MidiDevice::MidiDevice(DeviceId id, InstrumentId ibase, const MidiDevice &dev) : Device(id, dev.getName(), Device::Midi), m_programList(dev.m_programList), m_bankList(dev.m_bankList), m_controlList(0), 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)) { createInstruments(ibase); // Populate device and Instrument with Controllers. ControlList::const_iterator cIt = dev.m_controlList.begin(); for(; cIt != dev.m_controlList.end(); ++cIt) { addControlParameter(*cIt, true); } // Create and assign a metronome if required // if (dev.getMetronome()) { m_metronome = new MidiMetronome(*dev.getMetronome()); } generatePresentationList(); }
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(); }
// 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; }
bool ManageMetronomeDialog::isSuitable(Device *dev, bool *hasConnectionReturn) { MidiDevice *md = dynamic_cast<MidiDevice *>(dev); if (md && md->getDirection() == MidiDevice::Play) { if (hasConnectionReturn) { QString conn = RosegardenSequencer::getInstance()->getConnection (md->getId()); if (conn == "") *hasConnectionReturn = false; else *hasConnectionReturn = true; } return true; } if (dynamic_cast<SoftSynthDevice *>(dev)) { if (hasConnectionReturn) *hasConnectionReturn = true; return true; } return false; }
CreateOrDeleteDeviceCommand::CreateOrDeleteDeviceCommand(Studio *studio, DeviceId id) : NamedCommand(getGlobalName(true)), m_studio(studio), m_deviceId(id), m_deviceCreated(true) { Device *device = m_studio->getDevice(m_deviceId); if (device) { m_name = device->getName(); m_type = device->getType(); m_direction = MidiDevice::Play; MidiDevice *md = dynamic_cast<MidiDevice *>(device); if (md) m_direction = md->getDirection(); m_connection = qstrtostr(RosegardenSequencer::getInstance() ->getConnection(md->getId())); } else { RG_DEBUG << "CreateOrDeleteDeviceCommand: No such device as " << m_deviceId << endl; } }
SplitByRecordingSrcDialog::SplitByRecordingSrcDialog(QWidget *parent, RosegardenDocument *doc) : QDialog(parent) { setModal(true); setWindowTitle(tr("Split by Recording Source")); QGridLayout *metagrid = new QGridLayout; setLayout(metagrid); QWidget *vBox = new QWidget(this); QVBoxLayout *vBoxLayout = new QVBoxLayout; metagrid->addWidget(vBox, 0, 0); QGroupBox *groupBox = new QGroupBox( tr("Recording Source"), vBox ); groupBox->setContentsMargins(10, 10, 10, 10); QGridLayout *layout = new QGridLayout(groupBox); layout->setSpacing(5); vBoxLayout->addWidget(groupBox); vBox->setLayout(vBoxLayout); layout->addWidget(new QLabel( tr("Channel:"), groupBox ), 0, 0); m_channel = new QComboBox( groupBox ); m_channel->setMaxVisibleItems( 17 ); layout->addWidget(m_channel, 0, 1); QSpacerItem *spacer = new QSpacerItem( 1, 1, QSizePolicy::Expanding, QSizePolicy::Minimum ); layout->addItem( spacer, 0, 2 ); m_channel->addItem(tr("any")); for (int i = 1; i < 17; ++i) { m_channel->addItem(QString::number(i)); } layout->addWidget(new QLabel( tr("Device:"), groupBox ), 1, 0); m_device = new QComboBox( groupBox ); layout->addWidget( m_device, 1, 1, 0+1, 2 - 1+1); m_deviceIds.clear(); m_deviceIds.push_back( -1); m_device->addItem(tr("any")); DeviceList *devices = doc->getStudio().getDevices(); DeviceListConstIterator it; for (it = devices->begin(); it != devices->end(); it++) { MidiDevice *dev = dynamic_cast<MidiDevice*>(*it); if (dev && dev->getDirection() == MidiDevice::Record) { QString label = QString::number(dev->getId()); label += ": "; label += strtoqstr(dev->getName()); QString connection = RosegardenSequencer::getInstance()->getConnection (dev->getId()); label += " - "; if (connection == "") label += tr("No connection"); else label += connection; m_device->addItem(label); m_deviceIds.push_back(dev->getId()); } } m_channel->setCurrentIndex(0); m_device->setCurrentIndex(0); groupBox->setLayout(layout); QDialogButtonBox *buttonBox = new QDialogButtonBox(QDialogButtonBox::Ok | QDialogButtonBox::Cancel ); metagrid->addWidget(buttonBox, 1, 0); metagrid->setRowStretch(0, 10); connect(buttonBox, SIGNAL(accepted()), this, SLOT(accept())); connect(buttonBox, SIGNAL(rejected()), this, SLOT(reject())); }
Instrument* Studio::assignMidiProgramToInstrument(MidiByte program, int msb, int lsb, bool percussion) { MidiDevice *midiDevice; std::vector<Device*>::iterator it; Rosegarden::InstrumentList::iterator iit; Rosegarden::InstrumentList instList; // Instruments that we may return // Rosegarden::Instrument *newInstrument = 0; Rosegarden::Instrument *firstInstrument = 0; bool needBank = (msb >= 0 || lsb >= 0); if (needBank) { if (msb < 0) msb = 0; if (lsb < 0) lsb = 0; } // Pass one - search through all MIDI instruments looking for // a match that we can re-use. i.e. if we have a matching // Program Change then we can use this Instrument. // for (it = m_devices.begin(); it != m_devices.end(); ++it) { midiDevice = dynamic_cast<MidiDevice*>(*it); if (midiDevice && midiDevice->getDirection() == MidiDevice::Play) { instList = (*it)->getPresentationInstruments(); for (iit = instList.begin(); iit != instList.end(); ++iit) { if (firstInstrument == 0) firstInstrument = *iit; // If we find an Instrument sending the right program already. // if ((*iit)->sendsProgramChange() && (*iit)->getProgramChange() == program && (!needBank || ((*iit)->sendsBankSelect() && (*iit)->getMSB() == msb && (*iit)->getLSB() == lsb && (*iit)->isPercussion() == percussion))) { return (*iit); } else { // Ignore the program change and use the percussion // flag. // if ((*iit)->isPercussion() && percussion) { return (*iit); } // Otherwise store the first Instrument for // possible use later. // if (newInstrument == 0 && (*iit)->sendsProgramChange() == false && (*iit)->sendsBankSelect() == false && (*iit)->isPercussion() == percussion) newInstrument = *iit; } } } } // Okay, if we've got this far and we have a new Instrument to use // then use it. // if (newInstrument != 0) { newInstrument->setSendProgramChange(true); newInstrument->setProgramChange(program); if (needBank) { newInstrument->setSendBankSelect(true); newInstrument->setPercussion(percussion); newInstrument->setMSB(msb); newInstrument->setLSB(lsb); } } else // Otherwise we just reuse the first Instrument we found newInstrument = firstInstrument; return newInstrument; }