void AudioPluginOSCGUIManager::startGUI(InstrumentId instrument, int position) { RG_DEBUG << "AudioPluginOSCGUIManager::startGUI: " << instrument << "," << position << endl; checkOSCThread(); if (m_guis.find(instrument) != m_guis.end() && m_guis[instrument].find(position) != m_guis[instrument].end()) { RG_DEBUG << "stopping GUI first"; stopGUI(instrument, position); } // check the label PluginContainer *container = 0; container = m_studio->getContainerById(instrument); if (!container) { RG_DEBUG << "AudioPluginOSCGUIManager::startGUI: no such instrument or buss as " << instrument << endl; return; } AudioPluginInstance *pluginInstance = container->getPlugin(position); if (!pluginInstance) { RG_DEBUG << "AudioPluginOSCGUIManager::startGUI: no plugin at position " << position << " for instrument " << instrument << endl; return ; } try { AudioPluginOSCGUI *gui = new AudioPluginOSCGUI(pluginInstance, getOSCUrl(instrument, position, strtoqstr(pluginInstance->getIdentifier())), getFriendlyName(instrument, position, strtoqstr(pluginInstance->getIdentifier()))); m_guis[instrument][position] = gui; } catch (Exception e) { RG_DEBUG << "AudioPluginOSCGUIManager::startGUI: failed to start GUI: " << e.getMessage() << endl; } }
bool AudioPluginOSCGUIManager::hasGUI(InstrumentId instrument, int position) { PluginContainer *container = 0; container = m_studio->getContainerById(instrument); if (!container) return false; AudioPluginInstance *pluginInstance = container->getPlugin(position); if (!pluginInstance) return false; try { QString filePath = AudioPluginOSCGUI::getGUIFilePath (strtoqstr(pluginInstance->getIdentifier())); return ( !filePath.isEmpty() ); } catch (Exception e) { // that's OK return false; } }
void ManageMetronomeDialog::populate(int deviceIndex) { m_metronomeInstrument->clear(); DeviceList *devices = m_doc->getStudio().getDevices(); DeviceListConstIterator it; int count = 0; Device *dev = 0; for (it = devices->begin(); it != devices->end(); it++) { dev = *it; if (!isSuitable(dev)) continue; if (count == deviceIndex) break; count++; } // sanity if (count < 0 || dev == 0 || !isSuitable(dev)) { return ; } // populate instrument list InstrumentList list = dev->getPresentationInstruments(); InstrumentList::iterator iit; const MidiMetronome *metronome = getMetronome(dev); // if we've got no metronome against this device then create one if (metronome == 0) { InstrumentId id = SystemInstrumentBase; for (iit = list.begin(); iit != list.end(); ++iit) { if ((*iit)->isPercussion()) { id = (*iit)->getId(); break; } } setMetronome(dev, MidiMetronome(id)); metronome = getMetronome(dev); } // metronome should now be set but we still check it if (metronome) { int position = 0; int count = 0; for (iit = list.begin(); iit != list.end(); ++iit) { QString iname(QObject::tr((*iit)->getName().c_str())); QString ipname((*iit)->getLocalizedPresentationName()); QString pname(QObject::tr((*iit)->getProgramName().c_str())); QString text; if ((*iit)->getType() == Instrument::SoftSynth) { iname.replace(QObject::tr("Synth plugin "), ""); pname = ""; AudioPluginInstance *plugin = (*iit)->getPlugin (Instrument::SYNTH_PLUGIN_POSITION); if (plugin) { pname = strtoqstr(plugin->getProgram()); QString identifier = strtoqstr(plugin->getIdentifier()); if (identifier != "") { QString type, soName, label; PluginIdentifier::parseIdentifier (identifier, type, soName, label); if (pname == "") { pname = strtoqstr(plugin->getDistinctiveConfigurationText()); } if (pname != "") { pname = QString("%1: %2").arg(label).arg(pname); } else { pname = label; } } } } else { iname = ipname; } if (pname != "") { text = tr("%1 (%2)").arg(iname).arg(pname); } else { text = iname; } m_metronomeInstrument->addItem(text); if ((*iit)->getId() == metronome->getInstrument()) { position = count; } count++; } m_metronomeInstrument->setCurrentIndex(position); m_barPitch = metronome->getBarPitch(); m_beatPitch = metronome->getBeatPitch(); m_subBeatPitch = metronome->getSubBeatPitch(); slotPitchSelectorChanged(0); m_metronomeResolution->setCurrentIndex(metronome->getDepth()); m_metronomeBarVely->setValue(metronome->getBarVelocity()); m_metronomeBeatVely->setValue(metronome->getBeatVelocity()); m_metronomeSubBeatVely->setValue(metronome->getSubBeatVelocity()); m_playEnabled->setChecked(m_doc->getComposition().usePlayMetronome()); m_recordEnabled->setChecked(m_doc->getComposition().useRecordMetronome()); slotResolutionChanged(metronome->getDepth()); } }
bool AudioPluginOSCGUIManager::parseOSCPath(QString path, InstrumentId &instrument, int &position, QString &method) { RG_DEBUG << "AudioPluginOSCGUIManager::parseOSCPath(" << path << ")"; if (!m_studio) return false; QString pluginStr("/plugin/"); if (path.startsWith("//")) { path = path.right(path.length() - 1); } if (!path.startsWith(pluginStr)) { RG_DEBUG << "AudioPluginOSCGUIManager::parseOSCPath: malformed path " << path << endl; return false; } path = path.right(path.length() - pluginStr.length()); QString type = path.section('/', 0, 0); QString instrumentStr = path.section('/', 1, 1); QString positionStr = path.section('/', 2, 2); QString label = path.section('/', 3, -2); method = path.section('/', -1, -1); if (instrumentStr.isEmpty() || positionStr.isEmpty() ) { RG_DEBUG << "AudioPluginOSCGUIManager::parseOSCPath: no instrument or position in " << path; return false; } instrument = instrumentStr.toUInt(); if (positionStr == "synth") { position = Instrument::SYNTH_PLUGIN_POSITION; } else { position = positionStr.toInt(); } // check the label PluginContainer *container = m_studio->getContainerById(instrument); if (!container) { RG_DEBUG << "AudioPluginOSCGUIManager::parseOSCPath: no such instrument or buss as " << instrument << " in path " << path << endl; return false; } AudioPluginInstance *pluginInstance = container->getPlugin(position); if (!pluginInstance) { RG_DEBUG << "AudioPluginOSCGUIManager::parseOSCPath: no plugin at position " << position << " for instrument " << instrument << " in path " << path << endl; return false; } QString identifier = strtoqstr(pluginInstance->getIdentifier()); QString iType, iSoName, iLabel; PluginIdentifier::parseIdentifier(identifier, iType, iSoName, iLabel); if (iLabel != label) { RG_DEBUG << "AudioPluginOSCGUIManager::parseOSCPath: wrong label for plugin" << " at position " << position << " for instrument " << instrument << " in path " << path << " (actual label is " << iLabel << ")" << endl; return false; } RG_DEBUG << "AudioPluginOSCGUIManager::parseOSCPath: good path " << path << ", got mapped id " << pluginInstance->getMappedId() << endl; return true; }
// ??? Break this stuff off into an InstrumentPopup class. This class is too // big. void TrackButtons::populateInstrumentPopup(Instrument *thisTrackInstr, QMenu* instrumentPopup) { // pixmaps for icons to show connection states as variously colored boxes // ??? Factor out the icon-related stuff to make this routine clearer. // getIcon(Instrument *) would be ideal, but might not be easy. // getIcon(Device *) would also be needed. static QPixmap connectedPixmap, unconnectedPixmap, connectedUsedPixmap, unconnectedUsedPixmap, connectedSelectedPixmap, unconnectedSelectedPixmap; static bool havePixmaps = false; if (!havePixmaps) { IconLoader il; connectedPixmap = il.loadPixmap("connected"); connectedUsedPixmap = il.loadPixmap("connected-used"); connectedSelectedPixmap = il.loadPixmap("connected-selected"); unconnectedPixmap = il.loadPixmap("unconnected"); unconnectedUsedPixmap = il.loadPixmap("unconnected-used"); unconnectedSelectedPixmap = il.loadPixmap("unconnected-selected"); havePixmaps = true; } Composition &comp = m_doc->getComposition(); // clear the popup instrumentPopup->clear(); QMenu *currentSubMenu = 0; // position index int count = 0; int currentDevId = -1; // Get the list Studio &studio = m_doc->getStudio(); InstrumentList list = studio.getPresentationInstruments(); // For each instrument for (InstrumentList::iterator it = list.begin(); it != list.end(); ++it) { if (!(*it)) continue; // sanity check // get the Localized instrument name, with the string hackery performed // in Instrument QString iname((*it)->getLocalizedPresentationName()); // translate the program name // // Note we are converting the string from std to Q back to std then to // C. This is obviously ridiculous, but the fact that we have programName // here at all makes me think it exists as some kind of necessary hack // to coax tr() into behaving nicely. I decided to change it as little // as possible to get it to compile, and not refactor this down to the // simplest way to call tr() on a C string. QString programName(strtoqstr((*it)->getProgramName())); programName = QObject::tr(programName.toStdString().c_str()); Device *device = (*it)->getDevice(); DeviceId devId = device->getId(); bool connectedIcon = false; // Determine the proper program name and whether it is connected if ((*it)->getType() == Instrument::SoftSynth) { programName = ""; AudioPluginInstance *plugin = (*it)->getPlugin(Instrument::SYNTH_PLUGIN_POSITION); if (plugin) { // we don't translate any plugin program names or other texts programName = strtoqstr(plugin->getDisplayName()); connectedIcon = (plugin->getIdentifier() != ""); } } else if ((*it)->getType() == Instrument::Audio) { connectedIcon = true; } else { QString conn = RosegardenSequencer::getInstance()-> getConnection(devId); connectedIcon = (conn != ""); } // These two are for selecting the correct icon to display. bool instrUsedByMe = false; bool instrUsedByAnyone = false; if (thisTrackInstr && thisTrackInstr->getId() == (*it)->getId()) { instrUsedByMe = true; instrUsedByAnyone = true; } // If we have switched to a new device, we'll create a new submenu if (devId != (DeviceId)(currentDevId)) { currentDevId = int(devId); // For selecting the correct icon to display. bool deviceUsedByAnyone = false; if (instrUsedByMe) deviceUsedByAnyone = true; else { for (Composition::trackcontainer::iterator tit = comp.getTracks().begin(); tit != comp.getTracks().end(); ++tit) { if (tit->second->getInstrument() == (*it)->getId()) { instrUsedByAnyone = true; deviceUsedByAnyone = true; break; } Instrument *instr = studio.getInstrumentById(tit->second->getInstrument()); if (instr && (instr->getDevice()->getId() == devId)) { deviceUsedByAnyone = true; } } } QIcon icon (connectedIcon ? (deviceUsedByAnyone ? connectedUsedPixmap : connectedPixmap) : (deviceUsedByAnyone ? unconnectedUsedPixmap : unconnectedPixmap)); // Create a submenu for this device QMenu *subMenu = new QMenu(instrumentPopup); subMenu->setMouseTracking(true); subMenu->setIcon(icon); // Not needed so long as AA_DontShowIconsInMenus is false. //subMenu->menuAction()->setIconVisibleInMenu(true); // Menu title QString deviceName = QObject::tr(device->getName().c_str()); subMenu->setTitle(deviceName); // QObject name subMenu->setObjectName(deviceName); // Add the submenu to the popup menu instrumentPopup->addMenu(subMenu); // Connect the submenu to slotInstrumentSelected() connect(subMenu, SIGNAL(triggered(QAction*)), this, SLOT(slotInstrumentSelected(QAction*))); currentSubMenu = subMenu; } else if (!instrUsedByMe) {