void MidiMixerWindow::slotFaderLevelChanged(float value) { const QObject *s = sender(); for (FaderVector::const_iterator it = m_faders.begin(); it != m_faders.end(); ++it) { if ((*it)->m_volumeFader == s) { Instrument *instr = m_studio-> getInstrumentById((*it)->m_id); if (instr) { instr->setControllerValue(MIDI_CONTROLLER_VOLUME, MidiByte(value)); if (instr->hasFixedChannel()) { // send out to external controllers as well if the // affected instrument is on a fixed channel. //!!! really want some notification of whether we have any! int tabIndex = m_tabWidget->currentIndex(); if (tabIndex < 0) tabIndex = 0; int i = 0; for (DeviceList::const_iterator dit = m_studio->begin(); dit != m_studio->end(); ++dit) { RG_DEBUG << "slotFaderLevelChanged: i = " << i << ", tabIndex " << tabIndex << endl; if (!dynamic_cast<MidiDevice*>(*dit)) continue; if (i != tabIndex) { ++i; continue; } RG_DEBUG << "slotFaderLevelChanged: device id = " << instr->getDevice()->getId() << ", visible device id " << (*dit)->getId() << endl; if (instr->getDevice()->getId() == (*dit)->getId()) { RG_DEBUG << "slotFaderLevelChanged: sending control device mapped event for channel " << instr->getNaturalChannel() << endl; MappedEvent mE((*it)->m_id, MappedEvent::MidiController, MIDI_CONTROLLER_VOLUME, MidiByte(value)); mE.setRecordedChannel(instr->getNaturalChannel()); mE.setRecordedDevice(Device::CONTROL_DEVICE); StudioControl::sendMappedEvent(mE); } break; } } } emit instrumentParametersChanged((*it)->m_id); return ; } } }
static MidiByte getByte(const Event &e, const PropertyName &name) { long value = -1; try { value = e.get<Int>(name); } catch (...) { } if (value < 0 || value > 255) throw MIDIValueOutOfRange(name.getName()); return MidiByte(value); }
const ControlParameter& ControlParameter:: getExpression(void) { static const ControlParameter expression( "Expression", Rosegarden::Controller::EventType, "<none>", 0, 127, 100, MidiByte(11), 2, -1); return expression; }
// These exists to support calling PitchBendSequenceDialog because // some calls to PitchBendSequenceDialog always pitchbend or // expression rather than getting a ControlParameter from a ruler or // device. This can't be just a static member of ControlParameter, in // order to prevent the "static initialization order fiasco". const ControlParameter& ControlParameter:: getPitchBend(void) { static const ControlParameter pitchBend( "PitchBend", Rosegarden::PitchBend::EventType, "<none>", 0, 16383, 8192, MidiByte(1), 4, -1); return pitchBend; }
void MidiMixerWindow::slotControllerChanged(float value) { const QObject *s = sender(); size_t i = 0, j = 0; for (i = 0; i < m_faders.size(); ++i) { for (j = 0; j < m_faders[i]->m_controllerRotaries.size(); ++j) { if (m_faders[i]->m_controllerRotaries[j].second == s) break; } // break out on match if (j != m_faders[i]->m_controllerRotaries.size()) break; } // Don't do anything if we've not matched and got solid values // for i and j // if (i == m_faders.size() || j == m_faders[i]->m_controllerRotaries.size()) return ; //RG_DEBUG << "MidiMixerWindow::slotControllerChanged - found a controller" //<< endl; Instrument *instr = m_studio->getInstrumentById( m_faders[i]->m_id); if (instr) { //RG_DEBUG << "MidiMixerWindow::slotControllerChanged - " //<< "got instrument to change" << endl; instr->setControllerValue(m_faders[i]-> m_controllerRotaries[j].first, MidiByte(value)); if (instr->hasFixedChannel()) { int tabIndex = m_tabWidget->currentIndex(); if (tabIndex < 0) tabIndex = 0; int k = 0; for (DeviceList::const_iterator dit = m_studio->begin(); dit != m_studio->end(); ++dit) { RG_DEBUG << "slotControllerChanged: k = " << k << ", tabIndex " << tabIndex << endl; if (!dynamic_cast<MidiDevice*>(*dit)) continue; if (k != tabIndex) { ++k; continue; } RG_DEBUG << "slotControllerChanged: device id = " << instr->getDevice()->getId() << ", visible device id " << (*dit)->getId() << endl; if (instr->getDevice()->getId() == (*dit)->getId()) { RG_DEBUG << "slotControllerChanged: sending control device mapped event for channel " << instr->getNaturalChannel() << endl; // send out to external controllers as well. //!!! really want some notification of whether we have any! MappedEvent mE(m_faders[i]->m_id, MappedEvent::MidiController, m_faders[i]->m_controllerRotaries[j].first, MidiByte(value)); mE.setRecordedChannel(instr->getNaturalChannel()); mE.setRecordedDevice(Device::CONTROL_DEVICE); StudioControl::sendMappedEvent(mE); } } } emit instrumentParametersChanged(m_faders[i]->m_id); } }
void ManageMetronomeDialog::slotApply() { Studio &studio = m_doc->getStudio(); 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 == m_metronomeDevice->currentIndex()) break; count++; } if (!dev || !isSuitable(dev)) { RG_WARNING << "Warning: ManageMetronomeDialog::slotApply: no " << m_metronomeDevice->currentIndex() << "th device"; return ; } DeviceId deviceId = dev->getId(); studio.setMetronomeDevice(deviceId); if (getMetronome(dev) == 0) { RG_WARNING << "Warning: ManageMetronomeDialog::slotApply: unable to extract metronome from device " << deviceId; return ; } MidiMetronome metronome(*getMetronome(dev)); // get instrument InstrumentList list = dev->getPresentationInstruments(); Instrument *inst = list[m_metronomeInstrument->currentIndex()]; if (inst) { metronome.setInstrument(inst->getId()); } metronome.setBarPitch(m_barPitch); metronome.setBeatPitch(m_beatPitch); metronome.setSubBeatPitch(m_subBeatPitch); metronome.setDepth( m_metronomeResolution->currentIndex()); metronome.setBarVelocity( MidiByte(m_metronomeBarVely->value())); metronome.setBeatVelocity( MidiByte(m_metronomeBeatVely->value())); metronome.setSubBeatVelocity( MidiByte(m_metronomeSubBeatVely->value())); setMetronome(dev, metronome); m_doc->getComposition().setPlayMetronome(m_playEnabled->isChecked()); m_doc->getComposition().setRecordMetronome(m_recordEnabled->isChecked()); m_doc->getSequenceManager()->metronomeChanged(inst->getId(), true); m_doc->slotDocumentModified(); setModified(false); }
void AudioPluginOSCGUIManager::dispatch() { if (!m_studio) return ; while (m_oscBuffer.getReadSpace() > 0) { OSCMessage *message = 0; m_oscBuffer.read(&message, 1); int instrument = message->getTarget(); int position = message->getTargetData(); PluginContainer *container = m_studio->getContainerById(instrument); if (!container) continue; AudioPluginInstance *pluginInstance = container->getPlugin(position); if (!pluginInstance) continue; AudioPluginOSCGUI *gui = 0; if (m_guis.find(instrument) == m_guis.end()) { RG_DEBUG << "AudioPluginOSCGUIManager: no GUI for instrument " << instrument << endl; } else if (m_guis[instrument].find(position) == m_guis[instrument].end()) { RG_DEBUG << "AudioPluginOSCGUIManager: no GUI for instrument " << instrument << ", position " << position << endl; } else { gui = m_guis[instrument][position]; } std::string method = message->getMethod(); char type; const lo_arg *arg; // These generally call back on the RosegardenMainWindow. We'd // like to emit signals, but making AudioPluginOSCGUIManager a // QObject is problematic if it's only conditionally compiled. if (method == "control") { if (message->getArgCount() != 2) { RG_DEBUG << "AudioPluginOSCGUIManager: wrong number of args (" << message->getArgCount() << ") for control method" << endl; goto done; } if (!(arg = message->getArg(0, type)) || type != 'i') { RG_DEBUG << "AudioPluginOSCGUIManager: failed to get port number" << endl; goto done; } int port = arg->i; if (!(arg = message->getArg(1, type)) || type != 'f') { RG_DEBUG << "AudioPluginOSCGUIManager: failed to get port value" << endl; goto done; } float value = arg->f; RG_DEBUG << "AudioPluginOSCGUIManager: setting port " << port << " to value " << value << endl; m_mainWindow->slotChangePluginPort(instrument, position, port, value); } else if (method == "program") { if (message->getArgCount() != 2) { RG_DEBUG << "AudioPluginOSCGUIManager: wrong number of args (" << message->getArgCount() << ") for program method" << endl; goto done; } if (!(arg = message->getArg(0, type)) || type != 'i') { RG_DEBUG << "AudioPluginOSCGUIManager: failed to get bank number" << endl; goto done; } int bank = arg->i; if (!(arg = message->getArg(1, type)) || type != 'i') { RG_DEBUG << "AudioPluginOSCGUIManager: failed to get program number" << endl; goto done; } int program = arg->i; QString programName = StudioControl::getPluginProgram (pluginInstance->getMappedId(), bank, program); m_mainWindow->slotChangePluginProgram(instrument, position, programName); } else if (method == "update") { if (message->getArgCount() != 1) { RG_DEBUG << "AudioPluginOSCGUIManager: wrong number of args (" << message->getArgCount() << ") for update method" << endl; goto done; } if (!(arg = message->getArg(0, type)) || type != 's') { RG_DEBUG << "AudioPluginOSCGUIManager: failed to get GUI URL" << endl; goto done; } QString url = &arg->s; if (!gui) { RG_DEBUG << "AudioPluginOSCGUIManager: no GUI for update method" << endl; goto done; } gui->setGUIUrl(url); for (AudioPluginInstance::ConfigMap::const_iterator i = pluginInstance->getConfiguration().begin(); i != pluginInstance->getConfiguration().end(); ++i) { QString key = strtoqstr(i->first); QString value = strtoqstr(i->second); #ifdef DSSI_PROJECT_DIRECTORY_KEY if (key == PluginIdentifier::RESERVED_PROJECT_DIRECTORY_KEY) { key = DSSI_PROJECT_DIRECTORY_KEY; } #endif RG_DEBUG << "update: configuration: " << key << " -> " << value << endl; gui->sendConfiguration(key, value); } unsigned long rv = StudioControl::getPluginProgram (pluginInstance->getMappedId(), strtoqstr(pluginInstance->getProgram())); int bank = rv >> 16; int program = rv - (bank << 16); gui->sendProgram(bank, program); int controlCount = 0; for (PortInstanceIterator i = pluginInstance->begin(); i != pluginInstance->end(); ++i) { gui->sendPortValue((*i)->number, (*i)->value); /* Avoid overloading the GUI if there are lots and lots of ports */ if (++controlCount % 50 == 0) usleep(300000); } gui->show(); } else if (method == "configure") { if (message->getArgCount() != 2) { RG_DEBUG << "AudioPluginOSCGUIManager: wrong number of args (" << message->getArgCount() << ") for configure method" << endl; goto done; } if (!(arg = message->getArg(0, type)) || type != 's') { RG_DEBUG << "AudioPluginOSCGUIManager: failed to get configure key" << endl; goto done; } QString key = &arg->s; if (!(arg = message->getArg(1, type)) || type != 's') { RG_DEBUG << "AudioPluginOSCGUIManager: failed to get configure value" << endl; goto done; } QString value = &arg->s; #ifdef DSSI_RESERVED_CONFIGURE_PREFIX if (key.startsWith(DSSI_RESERVED_CONFIGURE_PREFIX) || key == PluginIdentifier::RESERVED_PROJECT_DIRECTORY_KEY) { RG_DEBUG << "AudioPluginOSCGUIManager: illegal reserved configure call from gui: " << key << " -> " << value; goto done; } #endif RG_DEBUG << "AudioPluginOSCGUIManager: configure(" << key << "," << value << ")" << endl; m_mainWindow->slotChangePluginConfiguration(instrument, position, #ifdef DSSI_GLOBAL_CONFIGURE_PREFIX key.startsWith(DSSI_GLOBAL_CONFIGURE_PREFIX), #else false, #endif key, value); } else if (method == "midi") { if (message->getArgCount() != 1) { RG_DEBUG << "AudioPluginOSCGUIManager: wrong number of args (" << message->getArgCount() << ") for midi method" << endl; goto done; } if (!(arg = message->getArg(0, type)) || type != 'm') { RG_DEBUG << "AudioPluginOSCGUIManager: failed to get MIDI event" << endl; goto done; } RG_DEBUG << "AudioPluginOSCGUIManager: handling MIDI message"; // let's only handle note on and note off int eventCode = arg->m[1]; int eventType = eventCode & MIDI_MESSAGE_TYPE_MASK; if (eventType == MIDI_NOTE_ON || eventType == MIDI_NOTE_OFF) { MappedEvent ev(instrument, MappedEvent::MidiNote, MidiByte(arg->m[2]), MidiByte(arg->m[3]), RealTime::zeroTime, RealTime::zeroTime, RealTime::zeroTime); if (eventType == MIDI_NOTE_OFF) ev.setVelocity(0); StudioControl::sendMappedEvent(ev); } } else if (method == "exiting") { RG_DEBUG << "AudioPluginOSCGUIManager: GUI exiting"; stopGUI(instrument, position); m_mainWindow->slotPluginGUIExited(instrument, position); } else { RG_DEBUG << "AudioPluginOSCGUIManager: unknown method " << method; } done: delete message; }