bool ModulatorSamplerSoundPool::loadMonolithicData(const ValueTree &sampleMap, const Array<File>& monolithicFiles, OwnedArray<ModulatorSamplerSound> &sounds) { jassert(!mc->getMainSynthChain()->areVoicesActive()); clearUnreferencedMonoliths(); loadedMonoliths.add(new MonolithInfoToUse(monolithicFiles)); MonolithInfoToUse* hmaf = loadedMonoliths.getLast(); try { hmaf->fillMetadataInfo(sampleMap); } catch (StreamingSamplerSound::LoadingError l) { String x; x << "Error at loading sample " << l.fileName << ": " << l.errorDescription; mc->getDebugLogger().logMessage(x); #if USE_FRONTEND mc->sendOverlayMessage(DeactiveOverlay::State::CustomErrorMessage, x); #else debugError(mc->getMainSynthChain(), x); #endif } for (int i = 0; i < sampleMap.getNumChildren(); i++) { ValueTree sample = sampleMap.getChild(i); if (sample.getNumChildren() == 0) { String fileName = sample.getProperty("FileName").toString().fromFirstOccurrenceOf("{PROJECT_FOLDER}", false, false); StreamingSamplerSound* sound = new StreamingSamplerSound(hmaf, 0, i); pool.add(sound); sounds.add(new ModulatorSamplerSound(mc, sound, i)); } else { StreamingSamplerSoundArray multiMicArray; for (int j = 0; j < sample.getNumChildren(); j++) { StreamingSamplerSound* sound = new StreamingSamplerSound(hmaf, j, i); pool.add(sound); multiMicArray.add(sound); } sounds.add(new ModulatorSamplerSound(mc, multiMicArray, i)); } } sendChangeMessage(); return true; }
bool KnownPluginList::scanAndAddFile (const String& fileOrIdentifier, const bool dontRescanIfAlreadyInList, OwnedArray <PluginDescription>& typesFound, AudioPluginFormat& format) { const ScopedLock sl (scanLock); if (dontRescanIfAlreadyInList && getTypeForFile (fileOrIdentifier) != nullptr) { bool needsRescanning = false; for (int i = types.size(); --i >= 0;) { const PluginDescription* const d = types.getUnchecked(i); if (d->fileOrIdentifier == fileOrIdentifier && d->pluginFormatName == format.getName()) { if (format.pluginNeedsRescanning (*d)) needsRescanning = true; else typesFound.add (new PluginDescription (*d)); } } if (! needsRescanning) return false; } if (blacklist.contains (fileOrIdentifier)) return false; OwnedArray <PluginDescription> found; { const ScopedUnlock sl2 (scanLock); if (scanner != nullptr) { if (! scanner->findPluginTypesFor (format, found, fileOrIdentifier)) addToBlacklist (fileOrIdentifier); } else { format.findAllTypesForFile (found, fileOrIdentifier); } } for (int i = 0; i < found.size(); ++i) { PluginDescription* const desc = found.getUnchecked(i); jassert (desc != nullptr); addType (*desc); typesFound.add (new PluginDescription (*desc)); } return found.size() > 0; }
bool KnownPluginList::scanAndAddFile (const String& fileOrIdentifier, const bool dontRescanIfAlreadyInList, OwnedArray<PluginDescription>& typesFound, AudioPluginFormat& format) { const ScopedLock sl (scanLock); if (dontRescanIfAlreadyInList && getTypeForFile (fileOrIdentifier) != nullptr) { bool needsRescanning = false; ScopedLock lock (typesArrayLock); for (auto* d : types) { if (d->fileOrIdentifier == fileOrIdentifier && d->pluginFormatName == format.getName()) { if (format.pluginNeedsRescanning (*d)) needsRescanning = true; else typesFound.add (new PluginDescription (*d)); } } if (! needsRescanning) return false; } if (blacklist.contains (fileOrIdentifier)) return false; OwnedArray<PluginDescription> found; { const ScopedUnlock sl2 (scanLock); if (scanner != nullptr) { if (! scanner->findPluginTypesFor (format, found, fileOrIdentifier)) addToBlacklist (fileOrIdentifier); } else { format.findAllTypesForFile (found, fileOrIdentifier); } } for (auto* desc : found) { jassert (desc != nullptr); addType (*desc); typesFound.add (new PluginDescription (*desc)); } return ! found.isEmpty(); }
//============================================================================== void DefaultMenuBarItemHandler::setupDefaultItemsIfNecessary() { if (menuBarItems.size() <= 0) { menuBarItems.add (new FileMenuBarItem()); menuBarItems.add (new EditMenuBarItem()); menuBarItems.add (new ViewMenuBarItem()); menuBarItems.add (new BuildMenuBarItem()); menuBarItems.add (new ToolsMenuBarItem()); menuBarItems.add (new HelpMenuBarItem()); } }
bool SmugMug::getSubCategoryList(OwnedArray<SubCategory>& subCategories) { StringPairArray params; XmlElement* n = smugMugRequest(("smugmug.subcategories.getAll"), params); if (n) { XmlElement* c = n->getChildByName(("SubCategories")); if (c) { XmlElement* subCat = c->getChildByName(("SubCategory")); while (subCat) { SubCategory* subCategory = new SubCategory(); subCategory->id = subCat->getIntAttribute(("id")); subCategory->title = subCat->getStringAttribute(("Name")); XmlElement* cat = subCat->getChildByName(("Category")); if (cat) subCategory->parentId = cat->getIntAttribute(("id")); subCategories.add(subCategory); subCat = subCat->getNextElementWithTagName(("SubCategory")); } } delete n; return true; } return false; }
OwnedArray<WifiAccessPoint> WifiStatusNM::nearbyAccessPoints() { NMDeviceWifi *wdev; const GPtrArray *ap_list; OwnedArray<WifiAccessPoint> accessPoints; wdev = NM_DEVICE_WIFI(nmdevice); //nm_device_wifi_request_scan(wdev, NULL, NULL); ap_list = nm_device_wifi_get_access_points(wdev); if (ap_list != NULL) { std::map<String, WifiAccessPoint *> uniqueAPs; for (int i = 0; i < ap_list->len; i++) { NMAccessPoint *ap = (NMAccessPoint *) g_ptr_array_index(ap_list, i); auto created_ap = createNMWifiAccessPoint(ap); /*FIXME: dropping hidden (no ssid) networks until gui supports it*/ if (created_ap->ssid.length() == 0) continue; if (uniqueAPs.find(created_ap->hash) == uniqueAPs.end()) uniqueAPs[created_ap->hash] = created_ap; else if (uniqueAPs[created_ap->hash]->signalStrength < created_ap->signalStrength) uniqueAPs[created_ap->hash] = created_ap; } for (const auto entry : uniqueAPs) accessPoints.add(entry.second); } DBG(__func__ << ": found " << accessPoints.size() << " AccessPoints"); return accessPoints; }
void Font::findFonts (OwnedArray<Font>& destArray) throw() { const StringArray names (findAllTypefaceNames()); for (int i = 0; i < names.size(); ++i) destArray.add (new Font (names[i], defaultFontHeight, Font::plain)); }
static void createTokens (int startPosition, const String& lineText, CodeDocument::Iterator& source, CodeTokeniser* analyser, OwnedArray <SyntaxToken>& newTokens) { CodeDocument::Iterator lastIterator (source); const int lineLength = lineText.length(); for (;;) { int tokenType = analyser->readNextToken (source); int tokenStart = lastIterator.getPosition(); int tokenEnd = source.getPosition(); if (tokenEnd <= tokenStart) break; tokenEnd -= startPosition; if (tokenEnd > 0) { tokenStart -= startPosition; newTokens.add (new SyntaxToken (lineText.substring (jmax (0, tokenStart), tokenEnd), tokenType)); if (tokenEnd >= lineLength) break; } lastIterator = source; } source = lastIterator; }
void MonitorTests::multiThreadedCallBackTest() { beginTest("Concurrent CallBack Test"); Monitor monitor; monitor.startMonitoring(); OwnedArray<SocketListener> listeners; for (int i = 0; i < 50 ; i++) { SocketListener* listener = new SocketListener(); listener->initializeSockets((40780 + (5*i)), &monitor, String("quassel") + String(i*20)); listeners.add(listener); } for (int i = 0; i < 50 ; i++) { pool->addJob(listeners[i], false); } while(pool->getNumJobs() > 0 ) { Thread::sleep(20); } monitor.stop(); for (int i = 0; i < 50 ; i++) { expectEquals(listeners[i]->was_informed , true); } }
bool SmugMug::getCategoryList(OwnedArray<Category>& categories) { StringPairArray params; XmlElement* n = smugMugRequest(("smugmug.categories.get"), params); if (n) { XmlElement* c = n->getChildByName(("Categories")); if (c) { XmlElement* cat = c->getChildByName(("Category")); while (cat) { Category* category = new Category(); category->id = cat->getIntAttribute(("id")); category->title = cat->getStringAttribute(("Name")); categories.add(category); cat = cat->getNextElementWithTagName(("Category")); } } delete n; return true; } return false; }
static void createFileCreationOptionComboBox (Component& setupComp, OwnedArray<Component>& itemsCreated, const char** fileOptions) { ComboBox* c = new ComboBox(); itemsCreated.add (c); setupComp.addChildAndSetID (c, "filesToCreate"); c->addItemList (StringArray (fileOptions), 1); c->setSelectedId (1, false); Label* l = new Label (String::empty, "Files to Auto-Generate:"); l->attachToComponent (c, true); itemsCreated.add (l); c->setBounds ("parent.width / 2 + 160, 10, parent.width - 10, top + 22"); }
void ThreadPool::addToDeleteList (OwnedArray<ThreadPoolJob>& deletionList, ThreadPoolJob* const job) const { job->shouldStop = true; job->pool = nullptr; if (job->shouldBeDeleted) deletionList.add (job); }
void EnabledModuleList::createRequiredModules (OwnedArray<LibraryModule>& modules) { for (int i = 0; i < getNumModules(); ++i) { ModuleDescription info (getModuleInfo (getModuleID (i))); if (info.isValid()) modules.add (new LibraryModule (info)); } }
bool SmugMug::getImages(OwnedArray<ImageItem>& images, SmugID albumId) { StringPairArray params; params.set(("AlbumID"), String(albumId.id)); params.set(("AlbumKey"), albumId.key); params.set(("Heavy"), ("1")); XmlElement* n = smugMugRequest(("smugmug.images.get"), params); if (n) { XmlElement* a = n->getChildByName(("Album")); if (a) { XmlElement* i = a->getChildByName(("Images")); if (i) { XmlElement* img = i->getChildByName(("Image")); while (img) { ImageItem* itm = new ImageItem(); itm->id.id = img->getIntAttribute(("id")); itm->id.key = img->getStringAttribute(("Key")); itm->filename = img->getStringAttribute(("FileName")); itm->caption = img->getStringAttribute(("")); itm->keywords = img->getStringAttribute(("")); itm->position = img->getIntAttribute(("Position")); itm->date = img->getStringAttribute(("Date")); itm->format = img->getStringAttribute(("Format")); itm->serial = img->getIntAttribute(("Serial")); itm->watermark = img->getBoolAttribute(("Watermark")); itm->size = img->getIntAttribute(("Size")); itm->width = img->getIntAttribute(("Width")); itm->height = img->getIntAttribute(("Height")); itm->md5sum = img->getStringAttribute(("MD5Sum")); itm->lastUpdated = img->getStringAttribute(("LastUpdated")); itm->originalURL = img->getStringAttribute(("OriginalURL")); itm->largeURL = img->getStringAttribute(("LargeURL")); itm->mediumURL = img->getStringAttribute(("MediumURL")); itm->smallURL = img->getStringAttribute(("SmallURL")); itm->tinyURL = img->getStringAttribute(("TinyURL")); itm->thumbURL = img->getStringAttribute(("ThumbURL")); itm->albumURL = img->getStringAttribute(("AlbumURL")); images.add(itm); img = img->getNextElementWithTagName(("Image")); } } } delete n; return images.size() > 0; } return false; }
//============================================================================== void MidiMessageSequence::createControllerUpdatesForTime (const int channelNumber, const double time, OwnedArray<MidiMessage>& dest) { bool doneProg = false; bool donePitchWheel = false; Array<int> doneControllers; doneControllers.ensureStorageAllocated (32); for (int i = list.size(); --i >= 0;) { const MidiMessage& mm = list.getUnchecked(i)->message; if (mm.isForChannel (channelNumber) && mm.getTimeStamp() <= time) { if (mm.isProgramChange()) { if (! doneProg) { dest.add (new MidiMessage (mm, 0.0)); doneProg = true; } } else if (mm.isController()) { if (! doneControllers.contains (mm.getControllerNumber())) { dest.add (new MidiMessage (mm, 0.0)); doneControllers.add (mm.getControllerNumber()); } } else if (mm.isPitchWheel()) { if (! donePitchWheel) { dest.add (new MidiMessage (mm, 0.0)); donePitchWheel = true; } } } } }
void MixerAudioSource::removeAllInputs() { OwnedArray<AudioSource> toDelete; { const ScopedLock sl (lock); for (int i = inputs.size(); --i >= 0;) if (inputsToDelete[i]) toDelete.add (inputs.getUnchecked(i)); } }
static void findImages (const Project::Item& item, OwnedArray<Project::Item>& found) { if (item.isImageFile()) { found.add (new Project::Item (item)); } else if (item.isGroup()) { for (int i = 0; i < item.getNumChildren(); ++i) findImages (item.getChild (i), found); } }
bool SmugMug::getAlbumList(OwnedArray<Album>& albums) { StringPairArray params; XmlElement* n = smugMugRequest(("smugmug.albums.get"), params); if (n) { XmlElement* a = n->getChildByName(("Albums")); if (a) { XmlElement* alb = a->getChildByName(("Album")); while (alb) { Album* album = new Album(); album->id.id = alb->getIntAttribute(("id")); album->id.key = alb->getStringAttribute(("Key")); album->title = alb->getStringAttribute(("Title")); XmlElement* cat = alb->getChildByName(("Category")); if (cat) { album->category = cat->getStringAttribute(("Name")); album->categoryId = cat->getIntAttribute(("id")); } else { album->category = String::empty; album->categoryId = -1; } XmlElement* subcat = alb->getChildByName(("SubCategory")); if (subcat) { album->subCategory = subcat->getStringAttribute(("Name")); album->subCategoryId = subcat->getIntAttribute(("id")); } else { album->subCategory = String::empty; album->subCategoryId = -1; } albums.add(album); alb = alb->getNextElementWithTagName(("Album")); } } delete n; return true; } return false; }
bool BufferingAudioReader::readNextBufferChunk() { const int64 pos = nextReadPosition; const int64 startPos = ((pos - 1024) / samplesPerBlock) * samplesPerBlock; const int64 endPos = startPos + numBlocks * samplesPerBlock; OwnedArray<BufferedBlock> newBlocks; for (int i = blocks.size(); --i >= 0;) if (blocks.getUnchecked(i)->range.intersects (Range<int64> (startPos, endPos))) newBlocks.add (blocks.getUnchecked(i)); if (newBlocks.size() == numBlocks) { newBlocks.clear (false); return false; } for (int64 p = startPos; p < endPos; p += samplesPerBlock) { if (getBlockContaining (p) == nullptr) { newBlocks.add (new BufferedBlock (*source, p, samplesPerBlock)); break; // just do one block } } { const ScopedLock sl (lock); newBlocks.swapWith (blocks); } for (int i = blocks.size(); --i >= 0;) newBlocks.removeObject (blocks.getUnchecked(i), false); return true; }
void ComponentBuilder::updateChildComponents (Component& parent, const ValueTree& children) { using namespace ComponentBuilderHelpers; const int numExistingChildComps = parent.getNumChildComponents(); Array <Component*> componentsInOrder; componentsInOrder.ensureStorageAllocated (numExistingChildComps); { OwnedArray<Component> existingComponents; existingComponents.ensureStorageAllocated (numExistingChildComps); int i; for (i = 0; i < numExistingChildComps; ++i) existingComponents.add (parent.getChildComponent (i)); const int newNumChildren = children.getNumChildren(); for (i = 0; i < newNumChildren; ++i) { const ValueTree childState (children.getChild (i)); ComponentBuilder::TypeHandler* const type = getHandlerForState (childState); jassert (type != nullptr); if (type != nullptr) { Component* c = findComponentWithID (existingComponents, getStateId (childState)); if (c == nullptr) c = createNewComponent (*type, childState, &parent); componentsInOrder.add (c); } } // (remaining unused items in existingComponents get deleted here as it goes out of scope) } // Make sure the z-order is correct.. if (componentsInOrder.size() > 0) { componentsInOrder.getLast()->toFront (false); for (int i = componentsInOrder.size() - 1; --i >= 0;) componentsInOrder.getUnchecked(i)->toBehind (componentsInOrder.getUnchecked (i + 1)); } }
void ProjectTreeViewBase::getAllSelectedNodesInTree (Component* componentInTree, OwnedArray <Project::Item>& selectedNodes) { TreeView* tree = dynamic_cast <TreeView*> (componentInTree); if (tree == nullptr) tree = componentInTree->findParentComponentOfClass<TreeView>(); if (tree != nullptr) { const int numSelected = tree->getNumSelectedItems(); for (int i = 0; i < numSelected; ++i) if (const ProjectTreeViewBase* const p = dynamic_cast <ProjectTreeViewBase*> (tree->getSelectedItem (i))) selectedNodes.add (new Project::Item (p->item)); } }
int main (int argc, char *argv[]) { Logger::setCurrentLogger(&DEBUG_LOGGER); #if 1 // Always load one instance to the pool to keep the plugin in cache // Consider testing PLUGIN_POOL_SIZE { DBG << "Loading plugin..." << endl; int poolSize = PLUGIN_POOL_SIZE; if (poolSize < 1) poolSize = 1; for (int numPlugs = 0; numPlugs < poolSize; ++numPlugs) { pluginPool.add(new ThreadSafePlugin(createSynthInstance())); } } #endif // Test: fire a request manually /* { DBG << "Firing test request" << endl; MemoryBlock testBlock; MemoryOutputStream ostream(testBlock, false); handlePluginRequest(PluginRequestParameters(), ostream); File testFile(resolveRelativePath("tmp/output2.wav")); testFile.replaceWithData(testBlock.getData(), testBlock.getSize()); DBG << "Done firing test request" << endl; } */ struct mg_context *ctx; const char *options[] = { "document_root", "public", "listening_ports", "8080", NULL }; struct mg_callbacks callbacks; memset(&callbacks, 0, sizeof(callbacks)); callbacks.begin_request = beginRequestHandler; ctx = mg_start(&callbacks, NULL, options); DBG << "Server started! Press ENTER to exit." << endl; getchar(); // Wait until user hits "enter" DBG << "Shutting down server threads" << endl; mg_stop(ctx); DBG << "Exiting" << endl; return 0; }
bool SmugMug::getNumberOfViews(int month, int year, OwnedArray<Views>& albums, OwnedArray<Views>& images) { StringPairArray params; params.set(("Month"), String(month)); params.set(("Year"), String(year)); XmlElement* n = smugMugRequest(("smugmug.users.getTransferStats"), params); if (n) { XmlElement* albs = n->getChildByName(("Albums")); if (albs) { XmlElement* alb = albs->getChildByName(("Album")); while (alb) { Views* v = new Views(); v->id = alb->getIntAttribute(("id")); v->views = alb->getIntAttribute(("Tiny")) + alb->getIntAttribute(("Small")) + alb->getIntAttribute(("Medium")) + alb->getIntAttribute(("Large")) + roundDoubleToInt(alb->getDoubleAttribute(("Original"))); albums.add(v); XmlElement* img = n->getChildByName(("Image")); while (img) { Views* v = new Views(); v->id = img->getIntAttribute(("id")); v->views = img->getIntAttribute(("Tiny")) + img->getIntAttribute(("Small")) + img->getIntAttribute(("Medium")) + img->getIntAttribute(("Large")) + roundDoubleToInt(img->getDoubleAttribute(("Original"))); img = img->getNextElementWithTagName(("Image")); } alb = alb->getNextElementWithTagName(("Album")); } } delete n; return true; } return false; }
bool ColumnFileBrowserContents::addColumn (const File& rootDirectory) { if (rootDirectory.isDirectory() && rootDirectory.exists()) { const int startingWidth = columns.getLast()->getWidth(); columns.add (new BrowserColumn (filesToDisplay)); addAndMakeVisible (columns.getLast()); columns.getLast()->setLookAndFeel (inactiveLookAndFeel); columns.getLast()->setRoot (rootDirectory); columns.getLast()->setSize (startingWidth, 50); columns.getLast()->addListener (this); columns.getLast()->addChangeListener (this); columns.getLast()->addComponentListener (this); resized(); return true; } return false; }
bool SmugMug::deleteDuplicates(SmugID albumId) { OwnedArray<ImageItem> images; if (getImages(images, albumId)) { OwnedArray<SmugID> duplicateIds; StringArray fileNames; for (int i = 0; i < images.size(); i++) { if (fileNames.contains(images[i]->filename)) duplicateIds.add(new SmugID(images[i]->id)); else fileNames.add(images[i]->filename); } for (int i = 0; i < duplicateIds.size(); i++) deleteImage(*duplicateIds[i]); return true; } return false; }
void LibraryModule::getConfigFlags (Project& project, OwnedArray<Project::ConfigFlag>& flags) const { const File header (getModuleHeaderFile (moduleInfo.getFolder())); jassert (header.exists()); StringArray lines; header.readLines (lines); for (int i = 0; i < lines.size(); ++i) { String line (lines[i].trim()); if (line.startsWith ("/**") && line.containsIgnoreCase ("Config:")) { ScopedPointer <Project::ConfigFlag> config (new Project::ConfigFlag()); config->sourceModuleID = getID(); config->symbol = line.fromFirstOccurrenceOf (":", false, false).trim(); if (config->symbol.length() > 2) { ++i; while (! (lines[i].contains ("*/") || lines[i].contains ("@see"))) { if (lines[i].trim().isNotEmpty()) config->description = config->description.trim() + " " + lines[i].trim(); ++i; } config->description = config->description.upToFirstOccurrenceOf ("*/", false, false); config->value.referTo (project.getConfigFlag (config->symbol)); flags.add (config.release()); } } } }
void scanFont (const File& file) { int faceIndex = 0; int numFaces = 0; std::clog << "got font: " << file.getFullPathName() << std::endl; do { FTFaceWrapper face (library, file, faceIndex); if (face.face != 0) { if (faceIndex == 0) numFaces = face.face->num_faces; if ((face.face->face_flags & FT_FACE_FLAG_SCALABLE) != 0) faces.add (new KnownTypeface (file, faceIndex, face)); } ++faceIndex; } while (faceIndex < numFaces); }
void Project::getJuceConfigFlags (OwnedArray <JuceConfigFlag>& flags) { ValueTree configNode (getJuceConfigNode()); File juceConfigH (getLocalJuceFolder().getChildFile ("juce_Config.h")); StringArray lines; lines.addLines (juceConfigH.loadFileAsString()); for (int i = 0; i < lines.size(); ++i) { String line (lines[i].trim()); if (line.startsWith ("/** ") && line.containsChar (':')) { ScopedPointer <JuceConfigFlag> config (new JuceConfigFlag()); config->symbol = line.substring (4).upToFirstOccurrenceOf (":", false, false).trim(); if (config->symbol.length() > 4) { config->description = line.fromFirstOccurrenceOf (":", false, false).trimStart(); ++i; while (! (lines[i].contains ("*/") || lines[i].contains ("@see"))) { if (lines[i].trim().isNotEmpty()) config->description = config->description.trim() + " " + lines[i].trim(); ++i; } config->description = config->description.upToFirstOccurrenceOf ("*/", false, false); config->value.referTo (getJuceConfigFlag (config->symbol)); flags.add (config.release()); } } } }
void Project::createRequiredModules (const ModuleList& availableModules, OwnedArray<LibraryModule>& modules) const { for (int i = 0; i < availableModules.modules.size(); ++i) if (isModuleEnabled (availableModules.modules.getUnchecked(i)->uid)) modules.add (availableModules.modules.getUnchecked(i)->create()); }
const String SAMCompiler::compile(ValueTree mdlRoot_) { String dspContent; //========================================================================== // DSP file header //========================================================================== dspContent << "// This DSP file has been generated by the Synth-A-Modeler compiler.\n"; dspContent << "import(\"physicalmodeling.lib\");\n\n"; //========================================================================== ValueTree faustTree = mdlRoot_.getChildWithName(Objects::variables); ValueTree massTree = mdlRoot_.getChildWithName(Objects::masses); ValueTree linkTree = mdlRoot_.getChildWithName(Objects::links); ValueTree wgTree = mdlRoot_.getChildWithName(Objects::waveguides); ValueTree jTree = mdlRoot_.getChildWithName(Objects::junctions); ValueTree tTree = mdlRoot_.getChildWithName(Objects::terminations); ValueTree aoTree = mdlRoot_.getChildWithName(Objects::audioobjects); int numMasslike = 0; int numPorts = 0; int numWaveguides = 0; int numJunctions = 0; String wgTermString; String junctString; StringArray wgOutputs; StringArray wgInputs; StringArray massWithJunct; StringArray linkWithJunct; StringArray massWithJunctLine; StringArray portWithJunctLine; StringArray massWithJunctOutputs; StringArray junctInputs; StringArray junctOutputs; //========================================================================== //========================================================================== // Write all waveguides and terminations //========================================================================== OwnedArray<WgWithSuffixes> wgWithSuffixes; for (int i = 0; i < wgTree.getNumChildren(); ++i) { ++numWaveguides; ValueTree wg = wgTree.getChild(i); WgWithSuffixes* wws = new WgWithSuffixes(); wws->wgId = wg[Ids::identifier].toString(); ValueTree left = jTree.getChildWithProperty(Ids::identifier, wg[Ids::startVertex]); ValueTree right; if (left.isValid()) { right = tTree.getChildWithProperty(Ids::identifier, wg[Ids::endVertex]); } else { left = tTree.getChildWithProperty(Ids::identifier, wg[Ids::startVertex]); right = jTree.getChildWithProperty(Ids::identifier, wg[Ids::endVertex]); } ValueTree term; ValueTree junct; StringArray wgSuffixes; if (left.getType() == Ids::termination) { wgSuffixes.add(wgR); wgSuffixes.add(wgL); wgSuffixes.add(wgRp); wgSuffixes.add(wgLp); term = left; junct = right; wws->termRight = false; } else if (left.getType() == Ids::junction) { wgSuffixes.add(wgL); wgSuffixes.add(wgR); wgSuffixes.add(wgLp); wgSuffixes.add(wgRp); term = right; junct = left; wws->termRight = true; } wws->wgSuffixes = wgSuffixes; wgInputs.add(wg[Ids::identifier].toString() + wgLp); wgInputs.add(wg[Ids::identifier].toString() + wgRp); wgOutputs.add(wg[Ids::identifier].toString() + wgL); wgOutputs.add(wg[Ids::identifier].toString() + wgR); ValueTree paWg = wg.getChildWithName(Ids::parameters); StringArray paWgStrings; for (int j = 0; j < paWg.getNumChildren(); ++j) { paWgStrings.add(paWg.getChild(j)[Ids::value].toString()); } wws->wgParams = paWgStrings; wgWithSuffixes.add(wws); ValueTree paTerm = term.getChildWithName(Ids::parameters); StringArray paTermStrings; for (int j = 0; j < paTerm.getNumChildren(); ++j) { paTermStrings.add(paTerm.getChild(j)[Ids::value].toString()); } //====================================================================== wgTermString << "\t"; wgTermString << wg[Ids::identifier].toString(); wgTermString << wgSuffixes[0] << " = " << term[Ids::identifier].toString(); wgTermString << " : "; wgTermString << paWgStrings[1]; wgTermString << ";\n\t"; wgTermString << term[Ids::identifier].toString(); wgTermString << " = "; wgTermString << wg[Ids::identifier].toString() << wgSuffixes[3]; wgTermString << " : "; wgTermString << paTermStrings[0] << ";\n\n"; //====================================================================== } //========================================================================== // Write all junctions //========================================================================== for (int i = 0; i < jTree.getNumChildren(); ++i) { ++numJunctions; ValueTree junct = jTree.getChild(i); junctOutputs.add(junct[Ids::identifier].toString()); junctInputs.add(junct[Ids::identifier].toString()+"p"); ValueTree wgs = getWgForJunct(wgTree, junct); StringArray junctWgOuts; StringArray junctWgParams; junctString << "\t"; for (int k = 0; k < wgs.getNumChildren(); ++k) { ValueTree wg = wgs.getChild(k); int wgSuffixesIdx = containsWgRef(wgWithSuffixes, wg[Ids::identifier].toString()); if (wgSuffixesIdx == -1) continue; const StringArray& wgSuffixes = wgWithSuffixes[wgSuffixesIdx]->wgSuffixes; junctString << wg[Ids::identifier].toString() << wgSuffixes[1]; junctString << " = "; junctString << junct[Ids::identifier].toString() << jTO; junctString << wg[Ids::identifier].toString(); junctString << " : "; junctString << wgWithSuffixes[wgSuffixesIdx]->wgParams[1]; junctString << ";\n\t"; junctString << junct[Ids::identifier].toString() << jTO; junctString << wg[Ids::identifier].toString() << " = "; junctString << junct[Ids::identifier].toString() << jOutputs; junctString << ":(_,!)-"; junctString << wg[Ids::identifier].toString() << wgSuffixes[2]; junctString << ";\n\t"; String jwo; jwo << wg[Ids::identifier].toString() << wgSuffixes[2]; jwo << "*" << wgWithSuffixes[wgSuffixesIdx]->wgParams[0]; junctWgOuts.add(jwo); junctWgParams.add(wgWithSuffixes[wgSuffixesIdx]->wgParams[0]); } String junctLinkString; String junctMassString; // Check if junction has one link and mass connected ValueTree junctLink = getJunctionLink(linkTree, junct); if (junctLink.isValid()) { String jm; if (junctLink[Ids::startVertex] == junct[Ids::identifier]) jm << junctLink[Ids::endVertex].toString(); else jm << junctLink[Ids::startVertex].toString(); junctMassString << jm << "p"; massWithJunct.add(jm); massWithJunctOutputs.add(jm + "p"); linkWithJunct.add(junctLink[Ids::identifier].toString()); ValueTree junctLinkParams = junctLink.getChildWithName(Ids::parameters); StringArray junctLinkParamsStrings; for (int k = 0; k < junctLinkParams.getNumChildren(); ++k) { ValueTree param = junctLinkParams.getChild(k); junctLinkParamsStrings.add(param[Ids::value].toString()); } junctLinkString << "junction" << junctLink.getType().toString(); junctLinkString << "Underneath(0.0,"; junctLinkString << junctLinkParamsStrings.joinIntoString(","); junctLinkString << ")"; // Get mass-like object connected with junction > link ValueTree mwj = massTree.getChildWithProperty(Ids::identifier, jm); String mwjl = "\t"; mwjl << jm; mwjl << " = (0.0"; StringArray otherLinks; for (int k = 0; k < linkTree.getNumChildren(); ++k) { ValueTree li = linkTree.getChild(k); if(li[Ids::identifier].toString() == junctLink[Ids::identifier].toString()) continue; if(li[Ids::startVertex].toString() == jm) { otherLinks.add("-"+li[Ids::identifier].toString()); } else if (li[Ids::endVertex].toString() == jm) { otherLinks.add("+"+li[Ids::identifier].toString()); } } mwjl << otherLinks.joinIntoString(String::empty); mwjl << "+("; mwjl << junct[Ids::identifier].toString() << jOutputs << ":(!,_)))"; // mwjl << " : "; // ValueTree mwjp = mwj.getChildWithName(Ids::parameters); // StringArray mwjpStrings; // for (int p = 0; p < mwjp.getNumChildren(); ++p) // { // ValueTree param = mwjp.getChild(p); // mwjpStrings.add(param[Ids::value].toString()); // } // mwjl << mwj.getType().toString(); // mwjl << "(" << mwjpStrings.joinIntoString(",") << ")"; mwjl << ";"; massWithJunctLine.add(mwjl); } else { junctMassString << "0.0"; junctLinkString << "junctionlink(0.0, 0.0, 0.0, 0.0)"; } junctString << junct[Ids::identifier].toString() << jOutputs; junctString << " = ("; junctString << junctMassString << ", 0.0+"; junctString << junctWgOuts.joinIntoString("+"); junctString << ", 0.0+"; junctString << junctWgParams.joinIntoString("+"); junctString << ") : "; junctString << junctLinkString << ";\n\t"; junctString << junct[Ids::identifier].toString(); junctString << " = "; junctString << junct[Ids::identifier].toString() << jOutputs; junctString << ":(_,!);\n\n"; } //========================================================================== // Write all faustcode //========================================================================== for (int i = 0; i < faustTree.getNumChildren(); ++i) { ValueTree fa = faustTree.getChild(i); dspContent << fa[Ids::identifier].toString(); dspContent << "="; dspContent << fa[Ids::faustCode].toString(); dspContent << ";\n"; } dspContent << "\n"; //========================================================================== // Get all mass names //========================================================================== OwnedArray<MassLinkRef> massLinkRefs; for (int i = 0; i < massTree.getNumChildren(); ++i) { ValueTree ma = massTree.getChild(i); if (massWithJunct.contains(ma[Ids::identifier].toString())) continue; MassLinkRef* mlf = new MassLinkRef(); mlf->massId = ma[Ids::identifier].toString(); StringArray mlfa; mlf->linkRefs = mlfa; if (ma.getType() == Ids::port) mlf->isPort = true; else mlf->isPort = false; massLinkRefs.add(mlf); } //========================================================================== // Write all link-like objects //========================================================================== StringArray linkobjects; for (int i = 0; i < linkTree.getNumChildren(); ++i) { ValueTree li = linkTree.getChild(i); String linkId = li[Ids::identifier].toString(); if (linkWithJunct.contains(linkId)) continue; String startVertex = li[Ids::startVertex].toString(); String endVertex = li[Ids::endVertex].toString(); int sIdx = containsMassLinkRef(massLinkRefs, startVertex); if (sIdx >= 0) massLinkRefs[sIdx]->linkRefs.add("-" + linkId); int eIdx = containsMassLinkRef(massLinkRefs, endVertex); if (eIdx >= 0) massLinkRefs[eIdx]->linkRefs.add("+" + linkId); String tagName = li.getType().toString(); ValueTree params = li.getChildWithName(Ids::parameters); StringArray paramsStr; for (int k = 0; k < params.getNumChildren(); ++k) { ValueTree param = params.getChild(k); paramsStr.add(param[Ids::value].toString()); } //====================================================================== String linkLine; linkLine << "\t"; linkLine << linkId; linkLine << " = ("; linkLine << startVertex << "p - "; linkLine << endVertex << "p) : "; linkLine << tagName << "("; linkLine << paramsStr.joinIntoString(",") << ");"; linkobjects.add(linkLine); //====================================================================== } StringArray massobjects; //========================================================================== // write all mass-like object except those connected to junctions //========================================================================== for (int i = 0; i < massTree.getNumChildren(); ++i) { ValueTree ma = massTree.getChild(i); if (massWithJunct.contains(ma[Ids::identifier].toString())) { if(ma.getType().toString().compare("port") == 0) ++numPorts; continue; } ++numMasslike; String tagName = ma.getType().toString(); String massName = ma[Ids::identifier].toString(); String massLine; massLine << "\t"; massLine << massName << " = (0.0"; if (tagName.compare("port") == 0) ++numPorts; int mIdx = containsMassLinkRef(massLinkRefs, massName); if (mIdx >= 0) { if (massLinkRefs[mIdx]->linkRefs.size() > 0) { massLine << massLinkRefs[mIdx]->linkRefs.joinIntoString(String::empty); } } massLine << ")"; if (tagName.compare("port") != 0) { massLine << " : "; massLine << tagName << "("; ValueTree params = ma.getChildWithName(Ids::parameters); StringArray paramsStr; for (int k = 0; k < params.getNumChildren(); ++k) { ValueTree param = params.getChild(k); paramsStr.add(param[Ids::value].toString()); } massLine << paramsStr.joinIntoString(",") << ")"; } massLine << ";"; massobjects.add(massLine); } //========================================================================== // add remaining mass-like object which are connected to junctions //========================================================================== massobjects.addArray(massWithJunctLine); //========================================================================== // Write all audio objects //========================================================================== StringArray audioobjects; StringArray audioNames; for (int i = 0; i < aoTree.getNumChildren(); ++i) { ValueTree ao = aoTree.getChild(i); String audioLine; String audioName = ao[Ids::identifier].toString(); audioNames.add(audioName); audioLine << "\t"; audioLine << audioName << " = "; ValueTree sources = ao.getChildWithName(Ids::sources); String paramLine; StringArray paramsStr; if (sources.getNumChildren() > 0) { for (int k = 0; k < sources.getNumChildren(); ++k) { ValueTree src = sources.getChild(k); paramsStr.add(src[Ids::value].toString()); } paramLine << paramsStr.joinIntoString("+"); } String optional = ao[Ids::optional].toString(); if (optional != String::empty) { if(! paramLine.startsWith("(")) paramLine = "(" + paramLine; if(! paramLine.endsWith(")")) paramLine << ")"; paramLine << optional; } audioLine << paramLine; audioLine << ";"; audioobjects.add(audioLine); } //========================================================================== // Generate all inputs and outputs //========================================================================== StringArray inputs; StringArray inputsPorts; for (int i = 0; i < massLinkRefs.size(); ++i) { if (massLinkRefs[i]->isPort) inputsPorts.add(massLinkRefs[i]->massId); else inputs.add(massLinkRefs[i]->massId); } StringArray outputs = inputs; outputs.addArray(massWithJunct); StringArray outputsPorts = inputsPorts; StringArray inputsP; StringArray inputsPPorts; for (int i = 0; i < inputs.size(); ++i) { String inputP = inputs[i]; inputP << "p"; inputsP.add(inputP); } for (int i = 0; i < massWithJunctOutputs.size(); ++i) { ++numMasslike; String inputP = massWithJunctOutputs[i]; inputsP.add(inputP); } for (int i = 0; i < inputsPorts.size(); ++i) { String inputPPort = inputsPorts[i]; inputPPort << "p"; inputsPPorts.add(inputPPort); } //========================================================================== // bibBlock with all imputs and outputs //========================================================================== dspContent << "bigBlock(" << inputsP.joinIntoString(","); if (wgInputs.size() > 0) dspContent << "," << wgInputs.joinIntoString(","); if (junctInputs.size() > 0) dspContent << "," << junctInputs.joinIntoString(","); if (inputsPPorts.size() > 0) dspContent << "," << inputsPPorts.joinIntoString(","); dspContent << ") = ("; dspContent << outputs.joinIntoString(","); if (wgOutputs.size() > 0) dspContent << "," << wgOutputs.joinIntoString(","); if (junctOutputs.size() > 0) dspContent << "," << junctOutputs.joinIntoString(","); if (outputsPorts.size() > 0) dspContent << "," << outputsPorts.joinIntoString(","); if (audioNames.size() > 0) dspContent << "," << audioNames.joinIntoString(","); dspContent << ") with {\n"; //========================================================================== // code for model objects //========================================================================== dspContent << "\n\t//waveguide termination objects\n"; dspContent << wgTermString; dspContent << "\t//junctions\n"; dspContent << junctString; dspContent << "\t//mass-like objects\n"; dspContent << massobjects.joinIntoString("\n") << "\n"; dspContent << "\n\t//link-like objects\n"; dspContent << linkobjects.joinIntoString("\n") << "\n"; dspContent << "\n\t//audio objects\n"; dspContent << audioobjects.joinIntoString("\n") << "\n};\n\n"; //========================================================================== // Calculate and write feedback line //========================================================================== StringArray feedbackArray; StringArray outputArray; //TODO: needs to be fixed for latest Synth-A-Modeler changes/fiyes int numFeedback = numMasslike - numPorts + (2 * numWaveguides) + numJunctions; for (int i = 0; i < numFeedback; ++i) { feedbackArray.add("_"); outputArray.add("!"); } for (int i = 0; i < numPorts + audioNames.size(); ++i) { feedbackArray.add("!"); outputArray.add("_"); } dspContent << "process = (bigBlock)~("; dspContent << feedbackArray.joinIntoString(","); dspContent << "):("; dspContent << outputArray.joinIntoString(",") << ");"; //========================================================================== massLinkRefs.clear(); wgWithSuffixes.clear(); return dspContent; }