//-------------------------------------------------------------- void SoundManager::playSound(string name, bool isLoop, float volume, int* speakers,int nbSpeakers) { SoundPlayer* pSoundPlayer = getSoundPlayer(name); if (pSoundPlayer) { if (speakers == 0) pSoundPlayer->play(); else pSoundPlayer->playTo(speakers,nbSpeakers); pSoundPlayer->setLoop(isLoop); pSoundPlayer->setVolume(volume); } }
//-------------------------------------------------------------- void SoundManager::setup(ofxXmlSettings& settings) { m_driver = settings.getValue("murmur:soundOutput:driver", 0); printf("- setting sound output driver [%d]\n", m_driver); ofFmodSelectDriver(m_driver); m_driver = ofFmodGetDriverSelected(); printf("- selected driver is [%d]\n", m_driver); int nbOutputs = settings.getValue("murmur:soundOutput:nbSpeakers", 2); printf("- setting sound output for %d speakers\n", nbOutputs); ofFmodSetNumOutputs( nbOutputs ); settings.pushTag("murmur"); settings.pushTag("soundOutput"); settings.pushTag("soundMain"); int nbSpeakers = settings.getNumTags("speaker"); mp_soundMainSpeakers = new int[nbSpeakers]; for (int i=0;i<nbSpeakers;i++) { mp_soundMainSpeakers[i] = settings.getValue("speaker",0,i); printf("- adding for sound main speaker [%d]\n", i); } m_nbSoundMainSpeakers = nbSpeakers; settings.popTag(); settings.popTag(); string soundMainFile = settings.getAttribute("murmur:soundOutput:soundMain","file", "main.wav"); printf("- sound main is [%s]\n", soundMainFile.c_str()); ofDirectory dirSounds("Sounds"); if (dirSounds.exists()) { dirSounds.listDir(); printf("DIR %s [%d file(s)]\n", dirSounds.path().c_str(),dirSounds.size()); vector<ofFile> files = dirSounds.getFiles(); vector<ofFile>::iterator it; for (it = files.begin(); it != files.end(); ++it) { if ((*it).getExtension() == "mp3" || (*it).getExtension() == "wav") { string filename = (*it).getFileName(); printf("- [%s]\n", filename.c_str()); SoundPlayer* pSoundPlayer = new SoundPlayer(filename); pSoundPlayer->loadSound( "Sounds/"+filename ); pSoundPlayer->setLoop(false); pSoundPlayer->setMultiPlay(true); m_listSoundPlayer.push_back( pSoundPlayer ); } } } mp_soundMain = getSoundPlayer(soundMainFile); }
//-------------------------------------------------------------- void SoundManager::setup(ofxXmlSettings& settings) { OFAPPLOG->begin("SoundManager::setup()"); m_driver = settings.getValue("murmur:soundOutput:driver", 0); OFAPPLOG->println(" - setting sound output driver ["+ofToString(m_driver)+"]"); ofFmodSelectDriver(m_driver); m_driver = ofFmodGetDriverSelected(); OFAPPLOG->println(" - selected driver is "+ofToString(m_driver)); int nbOutputs = settings.getValue("murmur:soundOutput:nbSpeakers", 2); OFAPPLOG->println(" - setting sound output for "+ofToString(nbOutputs)+" speaker(s)"); ofFmodSetNumOutputs( nbOutputs ); settings.pushTag("murmur"); settings.pushTag("soundOutput"); settings.pushTag("soundMain"); int nbSpeakers = settings.getNumTags("speaker"); mp_soundMainSpeakers = new int[nbSpeakers]; for (int i=0;i<nbSpeakers;i++) { mp_soundMainSpeakers[i] = settings.getValue("speaker",0,i); OFAPPLOG->println(" - adding for sound main speaker ["+ofToString(i)+"]"); } m_nbSoundMainSpeakers = nbSpeakers; settings.popTag(); settings.popTag(); string soundMainFile = settings.getAttribute("murmur:soundOutput:soundMain","file", "main.wav"); OFAPPLOG->println(" - sound main is '"+soundMainFile+"'"); ofDirectory dirSounds("Sounds"); if (dirSounds.exists()) { dirSounds.listDir(); OFAPPLOG->println(" - DIR is '"+dirSounds.path()+"' ["+ofToString(dirSounds.size())+" file(s)]"); vector<ofFile> files = dirSounds.getFiles(); vector<ofFile>::iterator it; string strFileNames = ""; string strFileNamesSep = ""; for (it = files.begin(); it != files.end(); ++it) { if ((*it).getExtension() == "mp3" || (*it).getExtension() == "wav") { string filename = (*it).getFileName(); strFileNames += strFileNamesSep + filename; SoundPlayer* pSoundPlayer = new SoundPlayer(filename); pSoundPlayer->loadSound( "Sounds/"+filename ); pSoundPlayer->setLoop(false); pSoundPlayer->setMultiPlay(true); m_listSoundPlayer.push_back( pSoundPlayer ); strFileNamesSep = ", "; } } OFAPPLOG->println(" - FILES are '"+strFileNames+"'"); } mp_soundMain = getSoundPlayer(soundMainFile); OFAPPLOG->end(); }
//-------------------------------------------------------------- void SoundManager::setVolume(string name, float volume) { SoundPlayer* pSoundPlayer = getSoundPlayer(name); if (pSoundPlayer) pSoundPlayer->setVolume(volume); }
//---------- void Assets::refreshView() { auto filterString = ofToLower(this->filter.get()); this->view->clear(); this->ownedElements.clear(); auto filterWidget = Widgets::EditableValue<string>::make(this->filter); auto filterWidgetWeak = weak_ptr<Element>(filterWidget); filterWidget->onValueChange += [this, filterWidgetWeak](const string &) { auto filterWidget = filterWidgetWeak.lock(); this->refreshView(); }; this->view->add(filterWidget); auto addReloadButton = [this](ElementPtr element, shared_ptr<ofxAssets::BaseAsset> asset) { auto button = Widgets::Button::make("Reload", [asset]() { asset->reload(); }); this->ownedElements.push_back(button); button->addListenersToParent(element); element->onBoundsChange += [button](BoundsChangeArguments & args) { auto bounds = args.localBounds; const int width = 80; bounds.width = width; bounds.x = args.localBounds.width - width; button->setBounds(bounds); }; }; auto & assetRegister = ofxAssets::Register::X(); this->view->add("Images"); { const auto & images = assetRegister.getImages(); const auto & names = images.getNames(); for(const auto & name : names) { if (!filterString.empty()) { if(ofToLower(name).find(filterString) == string::npos) { continue; } } auto asset = images[name]; auto & image = asset->get(); auto width = image.getWidth(); auto height = image.getHeight(); auto element = make_shared<Element>(); float longestAxis = max(width, height); auto scaleFactor = 48.0f / longestAxis; auto drawWidth = width * scaleFactor; auto drawHeight = height * scaleFactor; element->onDraw += [asset, name, width, height, drawWidth, drawHeight](DrawArguments & args) { stringstream text; text << name << endl; text << width << "x" << height; ofxCvGui::Utils::drawText(text.str(), 58, 0); asset->get().draw(5, 0, drawWidth, drawHeight); }; element->setHeight(58.0f); this->view->add(element); addReloadButton(element, asset); } } this->view->add("Shaders"); { const auto & shaders = assetRegister.getShaders(); const auto & names = shaders.getNames(); for(const auto & name : names) { if (!filterString.empty()) { if(ofToLower(name).find(filterString) == string::npos) { continue; } } auto asset = shaders[name]; auto & shader = asset->get(); bool loaded = shader.isLoaded(); auto element = make_shared<Element>(); element->onDraw += [name, loaded](DrawArguments & args) { stringstream text; text << name << endl; text << "Loaded : " << (loaded ? "true" : "false"); ofxCvGui::Utils::drawText(text.str(), 5, 0); }; element->setHeight(58.0f); this->view->add(element); addReloadButton(element, asset); } } this->view->add("Fonts"); { auto fonts = assetRegister.getFonts(); auto names = fonts.getNames(); for(const auto & name : names) { auto sizes = assetRegister.getFontSizes(name); for(const auto & size : sizes) { auto sizeString = ofToString(size); if (!filterString.empty()) { if(ofToLower(name).find(filterString) == string::npos && filterString != sizeString) { continue; } } auto asset = fonts[name]; auto element = make_shared<Element>(); element->onDraw += [name, size, asset](DrawArguments & args) { stringstream text; text << name << ", size " << size; ofxCvGui::Utils::drawText(text.str(), 5, 38); asset->get(size).drawString("AaBbCcDdEeFf0123456789", 5, 35); }; element->setScissor(true); element->setHeight(58.0f); this->view->add(element); addReloadButton(element, asset); } } } this->view->add("Sounds"); { auto sounds = assetRegister.getSounds(); auto names = sounds.getNames(); for(const auto & name : names) { if (!filterString.empty()) { if(ofToLower(name).find(filterString) == string::npos) { continue; } } auto asset = sounds[name]; auto & buffer = asset->getSoundBuffer(); auto duration = buffer.getDurationMS(); auto channels = buffer.getNumChannels(); auto element = make_shared<Element>(); element->onDraw += [name, duration, channels](DrawArguments & args) { stringstream text; text << name << endl; text << "Duration = " << duration << ". Channels = " << channels; ofxCvGui::Utils::drawText(text.str(), 0, 5); }; element->setHeight(58.0f); this->view->add(element); auto playButton = Widgets::Toggle::make("Play", [asset]() { return asset->getSoundPlayer().isPlaying(); }, [asset](bool play) { if(play) { asset->getSoundPlayer().play(); } }); this->ownedElements.push_back(playButton); playButton->addListenersToParent(element); element->onBoundsChange += [playButton](BoundsChangeArguments & args) { auto bounds = args.localBounds; bounds.width = 64; bounds.x = args.localBounds.width - (80 + 64); playButton->setBounds(bounds); }; addReloadButton(element, asset); } } this->viewDirty = false; }