Просмотр исходного кода

Sound will optionally generate float buffer, added POLYIGNORE to an usupported method in Sound, IDE tabs will now open files from their file browser

Ivan Safrin 12 лет назад
Родитель
Сommit
122c804485

+ 7 - 7
Core/Contents/Include/PolySound.h

@@ -57,11 +57,11 @@ namespace Polycode {
 		* Constructor.
 		* @param fileName Path to an OGG or WAV file to load.
 		*/ 
-		Sound(const String& fileName);
-		Sound(const char *data, int size, int channels = 1, ALsizei freq = 44100, int bps = 16);
+		Sound(const String& fileName, bool generateFloatBuffer = false);
+		Sound(int size, const char *data, int channels = 1, ALsizei freq = 44100, int bps = 16);
 		virtual ~Sound();
 		
-		void loadFile(String fileName);
+		void loadFile(String fileName, bool generateFloatBuffer);
 		
 		void reloadProperties();
 		
@@ -138,8 +138,8 @@ namespace Polycode {
 		Number getMaxDistance();
 		
 		ALuint loadBytes(const char *data, int size, int channels = 1, ALsizei freq = 44100, int bps = 16);
-		ALuint loadWAV(const String& fileName);
-		ALuint loadOGG(const String& fileName);
+		ALuint loadWAV(const String& fileName, bool generateFloatBuffer);
+		ALuint loadOGG(const String& fileName, bool generateFloatBuffer);
 		
 		ALuint GenSource(ALuint buffer);
 		ALuint GenSource();
@@ -150,7 +150,7 @@ namespace Polycode {
 		static unsigned long readByte32(const unsigned char buffer[4]);		
 		static unsigned short readByte16(const unsigned char buffer[2]);
 		
-//		std::vector<Number> *getFloatBuffer();
+		POLYIGNORE std::vector<float> *getFloatBuffer();
 
 	protected:
 	
@@ -169,6 +169,6 @@ namespace Polycode {
 		ALuint soundSource;
 		int sampleLength;
 		
-//		std::vector<Number> floatBuffer;
+		std::vector<float> floatBuffer;
 	};
 }

+ 18 - 17
Core/Contents/Source/PolySound.cpp

@@ -57,18 +57,18 @@ long custom_tellfunc(void *datasource) {
 	return OSBasics::tell(file);
 }
 
-Sound::Sound(const String& fileName) :  referenceDistance(1), maxDistance(MAX_FLOAT), pitch(1), volume(1), sampleLength(-1) {
+Sound::Sound(const String& fileName, bool generateFloatBuffer) :  referenceDistance(1), maxDistance(MAX_FLOAT), pitch(1), volume(1), sampleLength(-1) {
 	checkALError("Construct: Loose error before construction");
 	soundLoaded = false;	
 
-	loadFile(fileName);	
+	loadFile(fileName, generateFloatBuffer);	
 	
 	setIsPositional(false);
 	
 	checkALError("Construct from file: Finished");
 }
 
-Sound::Sound(const char *data, int size, int channels, int freq, int bps) : referenceDistance(1), maxDistance(MAX_FLOAT), pitch(1), volume(1), buffer(AL_NONE), soundSource(AL_NONE), sampleLength(-1) {
+Sound::Sound(int size, const char *data, int channels, int freq, int bps) : referenceDistance(1), maxDistance(MAX_FLOAT), pitch(1), volume(1), buffer(AL_NONE), soundSource(AL_NONE), sampleLength(-1) {
 	checkALError("Construct: Loose error before construction");
 	buffer = loadBytes(data, size, freq, channels, bps);
 	
@@ -82,7 +82,7 @@ Sound::Sound(const char *data, int size, int channels, int freq, int bps) : refe
 	checkALError("Construct from data: Finished");
 }
 
-void Sound::loadFile(String fileName) {
+void Sound::loadFile(String fileName, bool generateFloatBuffer) {
 
 	if(soundLoaded) {
 		alDeleteSources(1,&soundSource);	
@@ -106,9 +106,9 @@ void Sound::loadFile(String fileName) {
 	}
 	
 	if(extension == "wav" || extension == "WAV") {
-		buffer = loadWAV(actualFilename);			
+		buffer = loadWAV(actualFilename, generateFloatBuffer);			
 	} else if(extension == "ogg" || extension == "OGG") {
-		buffer = loadOGG(actualFilename);			
+		buffer = loadOGG(actualFilename, generateFloatBuffer);
 	}
 	
 	this->fileName = actualFilename;
@@ -390,7 +390,7 @@ ALuint Sound::loadBytes(const char *data, int size, int freq, int channels, int
 	return buffer;
 }
 
-ALuint Sound::loadOGG(const String& fileName) {
+ALuint Sound::loadOGG(const String& fileName, bool generateFloatBuffer) {
 //	floatBuffer.clear();
 	vector<char> data;
 	
@@ -443,22 +443,23 @@ ALuint Sound::loadOGG(const String& fileName) {
 	sampleLength = data.size() / sizeof(unsigned short);
 	
 	alBufferData(buffer, format, &data[0], static_cast<ALsizei>(data.size()), freq);
-/*	
-	int32_t *ptr32 = (int32_t*) &data[0];
-	for(int i=0; i < data.size()/2; i++ ) {
-		floatBuffer.push_back(((Number)ptr32[i])/((Number)INT32_MAX));
-	}	
-*/	
+	
+	if(generateFloatBuffer) {
+		int32_t *ptr32 = (int32_t*) &data[0];
+		for(int i=0; i < data.size()/2; i++ ) {
+			floatBuffer.push_back(((Number)ptr32[i])/((Number)INT32_MAX));
+		}	
+	}
 	return buffer;
 }
 
-/*
-std::vector<Number> *Sound::getFloatBuffer() {
+
+std::vector<float> *Sound::getFloatBuffer() {
 	return &floatBuffer;
 }
-*/
 
-ALuint Sound::loadWAV(const String& fileName) {
+
+ALuint Sound::loadWAV(const String& fileName, bool generateFloatBuffer) {
 	long bytes;
 	vector <char> data;
 	ALsizei freq;

+ 14 - 2
IDE/Contents/Source/PolycodeFrame.cpp

@@ -834,6 +834,9 @@ PolycodeProjectTab::PolycodeProjectTab(PolycodeProject *project, PolycodeEditorM
 
 void PolycodeProjectTab::setActive(bool val) {
 	active = val;
+	if(!active) {
+		projectBrowser->removeAllHandlers();
+	}
 }
 
 bool PolycodeProjectTab::isActive() {
@@ -967,7 +970,8 @@ void PolycodeProjectFrame::showTab(PolycodeProjectTab *tab) {
 	tab->getEditorHolder()->setActive(true);
 	tab->Resize(getWidth(), getHeight());
 	activeTab = tab;
-	restructTabs();		
+	restructTabs();
+	dispatchEvent(new UIEvent(), Event::CHANGE_EVENT);			
 }
 
 void PolycodeProjectFrame::restructTabs() {
@@ -1265,6 +1269,13 @@ void PolycodeFrame::showAssetBrowser(std::vector<String> extensions) {
 
 void PolycodeFrame::handleEvent(Event *event) {
 
+	if(event->getDispatcher() == activeProjectFrame) {
+		if(event->getEventCode() == Event::CHANGE_EVENT) {
+			printf("WOOP\n");
+			dispatchEvent(new Event(), Event::CHANGE_EVENT);
+		}
+	}
+
 	if(event->getDispatcher() == activeProjectFrame) {
 		if(event->getEventCode() == UIEvent::CLOSE_EVENT) {
 			dispatchEvent(new UIEvent(), UIEvent::CLOSE_EVENT);
@@ -1462,7 +1473,8 @@ void PolycodeFrame::switchToProjectFrame(PolycodeProjectFrame *projectFrame) {
 		activeProjectFrame->getActiveTab()->getEditorHolder()->setActive(true);
 	}
 	activeProjectFrame->addEventListener(this, UIEvent::CLOSE_EVENT);
-	Resize(getWidth(), getHeight());	
+	activeProjectFrame->addEventListener(this, Event::CHANGE_EVENT);	
+	Resize(getWidth(), getHeight());
 }
 
 PolycodeProjectFrame *PolycodeFrame::getProjectFrame(PolycodeProject *project) {

+ 14 - 2
IDE/Contents/Source/PolycodeIDEApp.cpp

@@ -116,6 +116,7 @@ PolycodeIDEApp::PolycodeIDEApp(PolycodeView *view) : EventDispatcher() {
 	frame->stopButton->addEventListener(this, UIEvent::CLICK_EVENT);
 	
 	frame->addEventListener(this, UIEvent::CLOSE_EVENT);
+	frame->addEventListener(this, Event::CHANGE_EVENT);	
 	screen->addChild(frame);
 	
 	projectManager = new PolycodeProjectManager();
@@ -613,8 +614,19 @@ void PolycodeIDEApp::handleEvent(Event *event) {
 		}
 	}
 
-	if(event->getDispatcher() == frame && event->getEventCode() == UIEvent::CLOSE_EVENT) {
-		closeFile();
+	if(event->getDispatcher() == frame) {
+		if(event->getEventCode() == Event::CHANGE_EVENT) {
+			printf("HOPHOP\n");
+			if(frame->getCurrentProjectBrowser()) {
+				frame->getCurrentProjectBrowser()->removeAllHandlersForListener(this);
+			}
+			frame->getCurrentProjectBrowser()->addEventListener(this, Event::CHANGE_EVENT);
+			frame->getCurrentProjectBrowser()->addEventListener(this, PolycodeProjectBrowserEvent::HANDLE_MENU_COMMAND);			
+		}
+			
+		if(event->getEventCode() == UIEvent::CLOSE_EVENT) {
+			closeFile();
+		}
 	}
 
 	if(event->getDispatcher() == frame->fileDialog) {

+ 1 - 1
IDE/Contents/Source/PolycodeProps.cpp

@@ -2419,7 +2419,7 @@ void SoundSheet::handleEvent(Event *event) {
 
 	if(event->getDispatcher() == soundProp  && event->getEventCode() == Event::CHANGE_EVENT) {
 		lastSoundPath = soundProp->get();
-		sound->getSound()->loadFile(lastSoundPath);
+		sound->getSound()->loadFile(lastSoundPath, false);
 	}