Exemplo n.º 1
0
MappedInstrument::MappedInstrument(const Instrument &instr):
        m_type(instr.getType()),
        m_id(instr.getId()),
        m_name(instr.getName()),
        m_device((instr.getDevice())->getId()),
        m_audioChannels(instr.getAudioChannels())
{}
Exemplo n.º 2
0
void StateWriter::getState (MemoryBlock& destData)
{
    DBG("StateWriter::getState(): Saving state.")
    
    ValueTree settingsTree ("settings");
    
    ValueTree libTree ("library");
    libTree.setProperty ("threshold", library->getThreshold(), nullptr);
    libTree.setProperty ("release", library->getReleaseTicks(), nullptr);
    libTree.setProperty ("velocity", library->getVelocityScale(), nullptr);
    settingsTree.addChild (libTree, -1, nullptr);

    ValueTree patternsTree ("patterns");
    for (int i = 0; i < library->getNumPatterns(); i++) {
        Pattern* pattern = library->getPattern (i);
        ValueTree patternTree ("pattern");
        ValueTree instrumentsTree ("instruments");
        for (int j = 0; j < pattern->getNumInstruments(); j++) {
            Instrument* instrument = pattern->getInstrumentAt (j);
            ValueTree instrumentTree ("instrument");
            instrumentTree.setProperty ("index", instrument->getIndex(), nullptr);
            instrumentTree.setProperty ("name", instrument->getName(), nullptr);
            instrumentTree.setProperty ("noteNumber", instrument->getNoteNumber(), nullptr);            
            instrumentsTree.addChild (instrumentTree, -1, nullptr);
        }
        patternTree.addChild (instrumentsTree, -1, nullptr);
        patternsTree.addChild (patternTree, -1, nullptr);
    }
    settingsTree.addChild (patternsTree, -1, nullptr);
    
    ValueTree seqTree ("sequencer");
    seqTree.setProperty ("sequencerNum", sequencer->getSequencerNum(), nullptr);
    settingsTree.addChild (seqTree, -1, nullptr);
        
    MemoryOutputStream stream (destData, false);
    settingsTree.writeToStream (stream);
}
Exemplo n.º 3
0
bool Configuration::load(
	const char *filename, Drumkit *drumkit
, bool ignorePorts, int maxSamples, IFileLoadProgressListener * listener)
{
	if(!load(filename, listener))
		return false;

	drumkit->setName(kit.name);
	drumkit->setLevel(kit.level);
	drumkit->setSelectedSceneName(kit.selectedScene);
	
	// Filter out those instruments not in any of the included submixes
	if(!includedSubmixes.empty())
	{
		KitInfo::InstrumentInfoList list;
		
		for(KitInfo::InstrumentInfoList::iterator e = kit.instruments.begin(); e != kit.instruments.end(); ++e)
		{
			InstrumentInfo* info = *e;
			
			string mainName = string("[main]");
			
			bool include = false;
			
			for(SubmixNameList::iterator f = includedSubmixes.begin(); f != includedSubmixes.end(); ++f)
			{
				string name = *f;
				
				// If this instrument isn't in a submix, and "[main]" is one of the 
				// specified submix names, it needs to be included.
				if(info->submix.empty())
				{
					if(name == mainName)
						include = true;
				}
				else
				{
					// Is this instrument in one of the specified submixes?
					if(info->submix == name)
						include = true;
				}
			}
			
			if(include)
				list.push_back(info);
		}
		
		kit.instruments = list;
	}

	for(KitInfo::InstrumentInfoList::iterator e = kit.instruments.begin(); e != kit.instruments.end(); ++e)
	{
		InstrumentInfo *info = *e;
		
		Instrument* inst = info->toInstrument(maxSamples);
		if(inst)
			drumkit->add((unsigned)atoi(info->noteNumber.c_str()), inst);
			
		if(listener)
		{
			string msg = inst->getName();
			if(!listener->progressEvent(msg))
				return false;
		}
			
		if(ignorePorts)
			inst->removeFromSubmix();
			
		if(inst->isInSubmix())
		{
			string name = inst->getSubmixName();
			Submix* submix = drumkit->findSubmixByName(name);
			if(!submix) {
				submix = drumkit->addSubmix(name);
			}
			inst->setSubmix(submix);
			submix->setOrphaned(false);
		}
	}
	
	// Having added all of the instruments, now set up the victims
	for(KitInfo::InstrumentInfoList::iterator e = kit.instruments.begin(); e != kit.instruments.end(); ++e)
	{
		InstrumentInfo* info = *e;
		unsigned nn = (unsigned)atoi(info->noteNumber.c_str());
		Instrument* me = drumkit->findByNoteNumber(nn);
		
		if(!me)
		{
			cerr << "Oops! Just loaded an instrument which cannot be found by its configured note number!" << endl;
			return false;
		}
		
		if(!info->victims.empty())
		{
			for(InstrumentInfo::VictimList::iterator f = info->victims.begin(); f != info->victims.end(); ++f)
			{
				unsigned noteNumber = (unsigned)atoi((*(f)).c_str());
				if(noteNumber > 0)
				{
					// Find the victim instrument
					Instrument *vic = drumkit->findByNoteNumber(noteNumber); 
					if(vic)
					{
						me->addVictim(vic);
					}
				}
			}
		}
	}
	
	InstrumentList allInst = drumkit->allInstruments();
	
	// Load scenes
	for(KitInfo::SceneInfoList::iterator e = kit.scenes.begin(); e != kit.scenes.end(); ++e)
	{
		// Walk through the SceneSettingInfos and make sure there's an instrument matched up to each one.
		for(SceneInfo::SettingInfoList::iterator f = (*e)->settings.begin(); f != (*e)->settings.end(); ++f)
		{
			string name = (*f)->instrumentName;
			Instrument *inst = drumkit->findInstrumentByName(name.c_str());
			(*f)->inst = inst;
		}
		
		// Now, make sure there's a SceneSetting for each instrument in the kit.
		for(InstrumentList::iterator f = allInst.begin(); f != allInst.end(); ++f)
		{
			Instrument * inst = *f;
			
			// Does the SceneInfo have a SceneSettingInfo for the instrument?
			// If not, make sure it does.
			SceneSettingInfo * info = (*e)->findSettingInfoFor(inst);
			if(!info)
			{
				info = SceneSettingInfo::from(inst);
				(*e)->settings.push_back(info);	
			}
		}
		
		// convert to a real Scene for the kit
		drumkit->getScenes().push_back((*e)->toScene());
	}
	
/*	for(SceneList::iterator e = drumkit->getScenes().begin(); e != drumkit->getScenes().end(); ++e)
	{
		Scene *scene = *e;
		
		for(SceneSettingList::iterator f = scene->getSettings().begin(); f != scene->getSettings().end(); ++f)
		{
			SceneSetting * setting = *f;
			
			LOG_TRACE("\t" 
				<< setting->getInstrument()->getName() 
				<< " .level=" << setting->level 
				<< " .pan=" << setting->pan 
				<< " .pitch=" << setting->pitch 
			);
		}
	}*/
	
	return true;
}