InstrumentList Studio::getPresentationInstruments() const { InstrumentList list; // For each device... for (DeviceList::const_iterator it = m_devices.begin(); it != m_devices.end(); ++it) { const MidiDevice *midiDevice = dynamic_cast<MidiDevice *>(*it); if (midiDevice) { // skip read-only devices if (midiDevice->getDirection() == MidiDevice::Record) continue; } // get sub list InstrumentList subList = (*it)->getPresentationInstruments(); // concatenate list.insert(list.end(), subList.begin(), subList.end()); } return list; }
MidiDevice::MidiDevice(const MidiDevice &dev) : Device(dev.getId(), dev.getName(), dev.getType()), Controllable(), m_programList(dev.m_programList), m_bankList(dev.m_bankList), m_controlList(dev.m_controlList), m_keyMappingList(dev.m_keyMappingList), m_metronome(0), m_direction(dev.getDirection()), m_variationType(dev.getVariationType()), m_librarian(dev.getLibrarian()), m_allocator(new AllocateChannels(ChannelSetup::MIDI)) { // Create and assign a metronome if required // if (dev.getMetronome()) { m_metronome = new MidiMetronome(*dev.getMetronome()); } // Copy the instruments // InstrumentList insList = dev.getAllInstruments(); InstrumentList::iterator iIt = insList.begin(); for (; iIt != insList.end(); ++iIt) { Instrument *newInst = new Instrument(**iIt); newInst->setDevice(this); m_instruments.push_back(newInst); } // generate presentation instruments generatePresentationList(); }
void Part::insertTime(int tick, int len) { if (len == 0) return; // move all instruments if (len < 0) { // remove instruments between tickpos >= tick and tickpos < (tick+len) // ownership goes back to class InstrumentChange() auto si = _instruments.lower_bound(tick); auto ei = _instruments.lower_bound(tick-len); _instruments.erase(si, ei); } InstrumentList il; for (auto i = _instruments.lower_bound(tick); i != _instruments.end();) { Instrument* instrument = i->second; int tick = i->first; _instruments.erase(i++); _instruments[tick + len] = instrument; } _instruments.insert(il.begin(), il.end()); }
// From a user selection (from a "Presentation" list) return // the matching Instrument // Instrument* Studio::getInstrumentFromList(int index) { std::vector<Device*>::iterator it; InstrumentList list; InstrumentList::iterator iit; int count = 0; for (it = m_devices.begin(); it != m_devices.end(); ++it) { MidiDevice *midiDevice = dynamic_cast<MidiDevice*>(*it); if (midiDevice) { // skip read-only devices if (midiDevice->getDirection() == MidiDevice::Record) continue; } list = (*it)->getPresentationInstruments(); for (iit = list.begin(); iit != list.end(); ++iit) { if (count == index) return (*iit); count++; } } return 0; }
void MidiDevice::removeControlFromInstrument(const ControlParameter &con) { InstrumentList insList = getAllInstruments(); InstrumentList::iterator iIt = insList.begin(); for(; iIt != insList.end(); ++iIt) { (*iIt)->removeStaticController(con.getControllerValue()); } }
AudioDevice::AudioDevice(const AudioDevice &dev): Device(dev.getId(), dev.getName(), dev.getType()) { // Copy the instruments // InstrumentList insList = dev.getAllInstruments(); InstrumentList::iterator iIt = insList.begin(); for (; iIt != insList.end(); ++iIt) m_instruments.push_back(new Instrument(**iIt)); }
void cHandler::PostEvent( SaHpiEventTypeT type, const SaHpiEventUnionT& data, SaHpiSeverityT severity, const cResource * r, const InstrumentList& updates, const InstrumentList& removals ) const { if ( !IsVisible() ) { return; } struct oh_event * e = oh_new_event(); e->hid = m_id; e->event.Source = r ? r->GetResourceId() : SAHPI_UNSPECIFIED_RESOURCE_ID; e->event.EventType = type; oh_gettimeofday( &e->event.Timestamp ); e->event.Severity = severity; e->event.EventDataUnion = data; e->resource.ResourceId = SAHPI_UNSPECIFIED_RESOURCE_ID; e->resource.ResourceCapabilities = 0; if ( r ) { e->resource = r->GetRptEntry(); } InstrumentList::const_iterator i, end; for ( i = updates.begin(), end = updates.end(); i != end; ++i ) { const SaHpiRdrT& rdr = (*i)->GetRdr(); void * copy = g_memdup( &rdr, sizeof(rdr) ); e->rdrs = g_slist_append( e->rdrs, copy ); } for ( i = removals.begin(), end = removals.end(); i != end; ++i ) { const SaHpiRdrT& rdr = (*i)->GetRdr(); void * copy = g_memdup( &rdr, sizeof(rdr) ); e->rdrs_to_remove = g_slist_append( e->rdrs_to_remove, copy ); } oh_evt_queue_push( &m_eventq, e ); }
MidiDevice & MidiDevice::operator=(const MidiDevice &dev) { if (&dev == this) return *this; m_id = dev.getId(); m_name = dev.getName(); m_type = dev.getType(); m_librarian = dev.getLibrarian(); m_keyMappingList = dev.getKeyMappings(), m_programList = dev.getPrograms(); m_bankList = dev.getBanks(); m_controlList = dev.getControlParameters(); m_direction = dev.getDirection(); m_variationType = dev.getVariationType(); // clear down instruments list m_instruments.clear(); m_presentationInstrumentList.clear(); // Create and assign a metronome if required // if (dev.getMetronome()) { if (m_metronome) delete m_metronome; m_metronome = new MidiMetronome(*dev.getMetronome()); } else { delete m_metronome; m_metronome = 0; } if (m_allocator) { delete m_allocator; } m_allocator = new AllocateChannels(ChannelSetup::MIDI); // Copy the instruments // InstrumentList insList = dev.getAllInstruments(); InstrumentList::iterator iIt = insList.begin(); for (; iIt != insList.end(); ++iIt) { Instrument *newInst = new Instrument(**iIt); newInst->setDevice(this); m_instruments.push_back(newInst); } // generate presentation instruments generatePresentationList(); return (*this); }
bool Configuration::save(const char *filename, Drumkit *dk) { kit.name = dk->getName(); InstrumentList instruments = dk->allInstruments(); for(InstrumentList::iterator e = instruments.begin(); e != instruments.end(); ++e) kit.instruments.push_back(InstrumentInfo::from(*e)); for(SceneList::iterator e = dk->getScenes().begin(); e != dk->getScenes().end(); ++e) kit.scenes.push_back(SceneInfo::from(*e)); return save(filename); }
void MidiDevice::clearControlList() { // Clear down instrument controllers first. InstrumentList insList = getAllInstruments(); InstrumentList::iterator iIt = insList.begin(); for(; iIt != insList.end(); ++iIt) { (*iIt)->clearStaticControllers(); } m_controlList.clear(); }
Scene * Scene::updateFrom(Drumkit * kit) { InstrumentList inst = kit->allInstruments(); for(InstrumentList::iterator e = inst.begin(); e != inst.end(); ++e) { SceneSetting * setting = new SceneSetting(); setting->setInstrument(*e); setting->update(); this->add(setting); } return this; }
void MidiDevice::addControlToInstrument(const ControlParameter &con) { if (!isVisibleControlParameter(con)) { return; } // Run through all of this devices instruments and add default controls and // values to them. InstrumentList insList = getAllInstruments(); InstrumentList::iterator iIt = insList.begin(); for(; iIt != insList.end(); ++iIt) { MidiByte conNumber = con.getControllerValue(); MidiByte conValue = con.getDefault(); (*iIt)->setControllerValue(conNumber, conValue); } }
Instrument* Studio::getInstrumentById(InstrumentId id) { std::vector<Device*>::iterator it; InstrumentList list; InstrumentList::iterator iit; for (it = m_devices.begin(); it != m_devices.end(); ++it) { list = (*it)->getAllInstruments(); for (iit = list.begin(); iit != list.end(); ++iit) if ((*iit)->getId() == id) return (*iit); } return 0; }
// Special list merge method. void InstrumentList::merge ( const InstrumentList& instruments ) { // Maybe its better not merging to itself. if (this == &instruments) return; // Names data lists merge... mergeDataList(m_patches, instruments.patches()); mergeDataList(m_notes, instruments.notes()); mergeDataList(m_controllers, instruments.controllers()); mergeDataList(m_rpns, instruments.rpns()); mergeDataList(m_nrpns, instruments.nrpns()); // Instrument merge... InstrumentList::ConstIterator it; for (it = instruments.begin(); it != instruments.end(); ++it) { Instrument& instr = (*this)[it.key()]; instr = it.value(); } }
void MidiDevice::replaceControlParameters(const ControlList &con) { // Clear down instrument controllers in preparation for replace. InstrumentList insList = getAllInstruments(); InstrumentList::iterator iIt = insList.begin(); for(; iIt != insList.end(); ++iIt) { (*iIt)->clearStaticControllers(); } // Clear the Device control list m_controlList.clear(); // Now add the controllers to the device, ControlList::const_iterator cIt = con.begin(); for(; cIt != con.end(); ++cIt) { addControlParameter(*cIt, true); } }
// Conform instrument controllers to a new setup. void MidiDevice:: conformInstrumentControllers(void) { InstrumentList insList = getAllInstruments(); // Treat each instrument for(InstrumentList::iterator iIt = insList.begin(); iIt != insList.end(); ++iIt) { // Get this instrument's static controllers. As a seperate // copy, so it's not munged when we erase controllers. StaticControllers staticControllers = (*iIt)->getStaticControllers(); for (StaticControllerIterator it = staticControllers.begin(); it != staticControllers.end(); ++it) { MidiByte conNumber = it->first; const ControlParameter * con = findControlParameter(Rosegarden::Controller::EventType, conNumber); if (!con) { // It doesn't exist in device, so remove it from // instrument. (*iIt)->removeStaticController(conNumber); } else if ((*iIt)->getControllerValue(conNumber) == 0) { // Controller value probably has an old default value, // so set it to the new default. MidiByte value = con->getDefault(); (*iIt)->setControllerValue(conNumber, value); } } } }
void ModifyDeviceMappingCommand::execute() { Composition::trackcontainer &tracks = m_composition->getTracks(); Composition::trackcontainer::iterator it = tracks.begin(); Instrument *instr = 0; int index = 0; for (; it != tracks.end(); ++it) { instr = m_studio->getInstrumentById(it->second->getInstrument()); if (!instr || !instr->getDevice()) continue; if (instr->getDevice()->getId() == m_fromDevice) { // if source and target are MIDI if (m_studio->getDevice(m_fromDevice)->getType() == Device::Midi && m_studio->getDevice(m_toDevice)->getType() == Device::Midi) { // Try to match channels on the target device // MidiByte channel = instr->getNaturalChannel(); InstrumentList destList = m_studio-> getDevice(m_toDevice)->getPresentationInstruments(); InstrumentList::iterator dIt = destList.begin(); for (; dIt != destList.end(); ++dIt) { if ((*dIt)->getNaturalChannel() == channel) { break; } } // Failure to match anything and there's no Instruments // at all in the destination. Skip to next source Instrument. // if (dIt == destList.end() || destList.size() == 0) continue; RG_DEBUG << " Track " << it->first << ", setting Instrument to " << (*dIt)->getId() << endl; // store "to" and "from" values // m_mapping.push_back( std::pair < TrackId, InstrumentId > (it->first, instr->getId())); it->second->setInstrument((*dIt)->getId()); } else // audio is involved in the mapping - use indexes { // assign by index numbers InstrumentList destList = m_studio-> getDevice(m_toDevice)->getPresentationInstruments(); // skip if we can't match // if (index > (int)(destList.size() - 1)) continue; m_mapping.push_back( std::pair < TrackId, InstrumentId > (it->first, instr->getId())); it->second->setInstrument(destList[index]->getId()); } index++; } } }
// ??? 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) {
void MidiMixerWindow::setupTabs() { DeviceListConstIterator it; MidiDevice *dev = 0; InstrumentList instruments; InstrumentList::const_iterator iIt; int faderCount = 0, deviceCount = 1; if (m_tabFrame) delete m_tabFrame; // Setup m_tabFrame // QWidget *blackWidget = new QWidget(this); setCentralWidget(blackWidget); QVBoxLayout *centralLayout = new QVBoxLayout; blackWidget->setLayout(centralLayout); m_tabWidget = new QTabWidget; centralLayout->addWidget(m_tabWidget); connect(m_tabWidget, SIGNAL(currentChanged(QWidget *)), this, SLOT(slotCurrentTabChanged(QWidget *))); m_tabWidget->setTabPosition(QTabWidget::South); setWindowTitle(tr("MIDI Mixer")); setWindowIcon(IconLoader().loadPixmap("window-midimixer")); for (it = m_studio->begin(); it != m_studio->end(); ++it) { dev = dynamic_cast<MidiDevice*>(*it); if (dev) { // Get the control parameters that are on the IPB (and hence can // be shown here too). // ControlList controls = getIPBForMidiMixer(dev); instruments = dev->getPresentationInstruments(); // Don't add a frame for empty devices // if (!instruments.size()) continue; m_tabFrame = new QFrame(m_tabWidget); m_tabFrame->setContentsMargins(10, 10, 10, 10); // m_tabFrame->setContentsMargins(5, 5, 5, 5); ??? QGridLayout *mainLayout = new QGridLayout(m_tabFrame); // MIDI Mixer label QLabel *label = new QLabel("", m_tabFrame); mainLayout->addWidget(label, 0, 0, 0, 16, Qt::AlignCenter); // control labels for (size_t i = 0; i < controls.size(); ++i) { label = new QLabel(QObject::tr(controls[i].getName().c_str()), m_tabFrame); mainLayout->addWidget(label, i + 1, 0, Qt::AlignCenter); } // meter label // (obsolete abandoned code deleted here) // volume label label = new QLabel(tr("Volume"), m_tabFrame); mainLayout->addWidget(label, controls.size() + 2, 0, Qt::AlignCenter); // instrument label label = new QLabel(tr("Instrument"), m_tabFrame); label->setFixedWidth(80); //!!! this should come from metrics mainLayout->addWidget(label, controls.size() + 3, 0, Qt::AlignLeft); int posCount = 1; int firstInstrument = -1; for (iIt = instruments.begin(); iIt != instruments.end(); ++iIt) { // Add new fader struct // m_faders.push_back(new FaderStruct()); // Store the first ID // if (firstInstrument == -1) firstInstrument = (*iIt)->getId(); // Add the controls // for (size_t i = 0; i < controls.size(); ++i) { QColor knobColour = QColor(Qt::white); if (controls[i].getColourIndex() > 0) { Colour c = m_document->getComposition().getGeneralColourMap(). getColourByIndex(controls[i].getColourIndex()); knobColour = QColor(c.getRed(), c.getGreen(), c.getBlue()); } Rotary *controller = new Rotary(m_tabFrame, controls[i].getMin(), controls[i].getMax(), 1.0, 5.0, controls[i].getDefault(), 20, Rotary::NoTicks, false, controls[i].getDefault() == 64); //!!! hacky controller->setKnobColour(knobColour); connect(controller, SIGNAL(valueChanged(float)), this, SLOT(slotControllerChanged(float))); mainLayout->addWidget(controller, i + 1, posCount, Qt::AlignCenter); // Store the rotary // m_faders[faderCount]->m_controllerRotaries.push_back( std::pair<MidiByte, Rotary*> (controls[i].getControllerValue(), controller)); } // VU meter // MidiMixerVUMeter *meter = new MidiMixerVUMeter(m_tabFrame, VUMeter::FixedHeightVisiblePeakHold, 6, 30); mainLayout->addWidget(meter, controls.size() + 1, posCount, Qt::AlignCenter); m_faders[faderCount]->m_vuMeter = meter; // Volume fader // Fader *fader = new Fader(0, 127, 100, 20, 80, m_tabFrame); mainLayout->addWidget(fader, controls.size() + 2, posCount, Qt::AlignCenter); m_faders[faderCount]->m_volumeFader = fader; // Label // QLabel *idLabel = new QLabel(QString("%1"). arg((*iIt)->getId() - firstInstrument + 1), m_tabFrame); idLabel->setObjectName("idLabel"); mainLayout->addWidget(idLabel, controls.size() + 3, posCount, Qt::AlignCenter); // store id in struct m_faders[faderCount]->m_id = (*iIt)->getId(); // Connect them up // connect(fader, SIGNAL(faderChanged(float)), this, SLOT(slotFaderLevelChanged(float))); // Update all the faders and controllers // slotUpdateInstrument((*iIt)->getId()); // Increment counters // posCount++; faderCount++; } QString name = QString("%1 (%2)") .arg(QObject::tr(dev->getName().c_str())) .arg(deviceCount++); addTab(m_tabFrame, name); } } }
void MidiMixerWindow::sendControllerRefresh() { //!!! need to know if we have a current external controller device, // as this is expensive int tabIndex = m_tabWidget->currentIndex(); RG_DEBUG << "MidiMixerWindow::slotCurrentTabChanged: current is " << tabIndex << endl; if (tabIndex < 0) return ; int i = 0; for (DeviceList::const_iterator dit = m_studio->begin(); dit != m_studio->end(); ++dit) { MidiDevice *dev = dynamic_cast<MidiDevice*>(*dit); RG_DEBUG << "device is " << (*dit)->getId() << ", dev " << dev << endl; if (!dev) continue; if (i != tabIndex) { ++i; continue; } InstrumentList instruments = dev->getPresentationInstruments(); ControlList controls = getIPBForMidiMixer(dev); RG_DEBUG << "device has " << instruments.size() << " presentation instruments, " << dev->getAllInstruments().size() << " instruments " << endl; for (InstrumentList::const_iterator iIt = instruments.begin(); iIt != instruments.end(); ++iIt) { Instrument *instrument = *iIt; if (!instrument->hasFixedChannel()) { continue; } int channel = instrument->getNaturalChannel(); RG_DEBUG << "instrument is " << instrument->getId() << endl; for (ControlList::const_iterator cIt = controls.begin(); cIt != controls.end(); ++cIt) { int controller = (*cIt).getControllerValue(); int value; try { value = instrument->getControllerValue(controller); } catch (std::string s) { std::cerr << "Exception in MidiMixerWindow::currentChanged: " << s << " (controller " << controller << ", instrument " << instrument->getId() << ")" << std::endl; value = 0; } MappedEvent mE(instrument->getId(), MappedEvent::MidiController, controller, value); mE.setRecordedChannel(channel); mE.setRecordedDevice(Device::CONTROL_DEVICE); StudioControl::sendMappedEvent(mE); } MappedEvent mE(instrument->getId(), MappedEvent::MidiController, MIDI_CONTROLLER_VOLUME, instrument->getVolume()); mE.setRecordedChannel(channel); mE.setRecordedDevice(Device::CONTROL_DEVICE); RG_DEBUG << "sending controller mapped event for channel " << channel << ", volume " << instrument->getVolume() << endl; StudioControl::sendMappedEvent(mE); } break; } }
void MidiMixerWindow::slotControllerDeviceEventReceived(MappedEvent *e, const void *preferredCustomer) { if (preferredCustomer != this) return ; RG_DEBUG << "MidiMixerWindow::slotControllerDeviceEventReceived: this one's for me" << endl; raise(); // get channel number n from event // get nth instrument on current tab if (e->getType() != MappedEvent::MidiController) return ; unsigned int channel = e->getRecordedChannel(); MidiByte controller = e->getData1(); MidiByte value = e->getData2(); int tabIndex = m_tabWidget->currentIndex(); int i = 0; for (DeviceList::const_iterator it = m_studio->begin(); it != m_studio->end(); ++it) { MidiDevice *dev = dynamic_cast<MidiDevice*>(*it); if (!dev) continue; if (i != tabIndex) { ++i; continue; } InstrumentList instruments = dev->getPresentationInstruments(); for (InstrumentList::const_iterator iIt = instruments.begin(); iIt != instruments.end(); ++iIt) { Instrument *instrument = *iIt; if (instrument->getNaturalChannel() != channel) continue; ControlList cl = dev->getIPBControlParameters(); for (ControlList::const_iterator i = cl.begin(); i != cl.end(); ++i) { if ((*i).getControllerValue() == controller) { RG_DEBUG << "Setting controller " << controller << " for instrument " << instrument->getId() << " to " << value << endl; instrument->setControllerValue(controller, value); break; } } slotUpdateInstrument(instrument->getId()); emit instrumentParametersChanged(instrument->getId()); } break; } }
void MidiMixerWindow::slotUpdateInstrument(InstrumentId id) { //RG_DEBUG << "MidiMixerWindow::slotUpdateInstrument - id = " << id << endl; DeviceListConstIterator it; MidiDevice *dev = 0; InstrumentList instruments; InstrumentList::const_iterator iIt; int count = 0; blockSignals(true); for (it = m_studio->begin(); it != m_studio->end(); ++it) { dev = dynamic_cast<MidiDevice*>(*it); if (dev) { instruments = dev->getPresentationInstruments(); ControlList controls = getIPBForMidiMixer(dev); for (iIt = instruments.begin(); iIt != instruments.end(); ++iIt) { // Match and set // if ((*iIt)->getId() == id) { // Set Volume fader // m_faders[count]->m_volumeFader->blockSignals(true); MidiByte volumeValue; try { volumeValue = (*iIt)-> getControllerValue(MIDI_CONTROLLER_VOLUME); } catch (std::string s) { // This should never get called. volumeValue = (*iIt)->getVolume(); } m_faders[count]->m_volumeFader->setFader(float(volumeValue)); m_faders[count]->m_volumeFader->blockSignals(false); /* StaticControllers &staticControls = (*iIt)->getStaticControllers(); RG_DEBUG << "STATIC CONTROLS SIZE = " << staticControls.size() << endl; */ // Set all controllers for this Instrument // for (size_t i = 0; i < controls.size(); ++i) { float value = 0.0; m_faders[count]->m_controllerRotaries[i].second->blockSignals(true); // The ControllerValues might not yet be set on // the actual Instrument so don't always expect // to find one. There might be a hole here for // deleted Controllers to hang around on // Instruments.. // try { value = float((*iIt)->getControllerValue (controls[i].getControllerValue())); } catch (std::string s) { /* RG_DEBUG << "MidiMixerWindow::slotUpdateInstrument - " << "can't match controller " << int(controls[i]. getControllerValue()) << " - \"" << s << "\"" << endl; */ continue; } /* RG_DEBUG << "MidiMixerWindow::slotUpdateInstrument" << " - MATCHED " << int(controls[i].getControllerValue()) << endl; */ m_faders[count]->m_controllerRotaries[i]. second->setPosition(value); m_faders[count]->m_controllerRotaries[i].second->blockSignals(false); } } count++; } } } blockSignals(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 programName(QObject::tr((*iit)->getProgramName().c_str())); QString text; if ((*iit)->getType() == Instrument::SoftSynth) { iname.replace(QObject::tr("Synth plugin "), ""); programName = ""; AudioPluginInstance *plugin = (*iit)->getPlugin (Instrument::SYNTH_PLUGIN_POSITION); if (plugin) programName = strtoqstr(plugin->getDisplayName()); } else { iname = ipname; } if (programName != "") { text = tr("%1 (%2)").arg(iname).arg(programName); } 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 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; }