void ControlCanvas::update() { //int bin = 999999; for( ControlList::iterator i = _controls.begin(); i != _controls.end(); ++i ) { Control* control = i->get(); if ( control->isDirty() || _contextDirty ) { osg::Vec2f size; control->calcSize( _context, size ); osg::Vec2f surfaceSize( _context._vp->width(), _context._vp->height() ); control->calcPos( _context, osg::Vec2f(0,0), surfaceSize ); osg::Geode* geode = _geodeTable[control]; geode->removeDrawables( 0, geode->getNumDrawables() ); DrawableList drawables; control->draw( _context, drawables ); for( DrawableList::iterator j = drawables.begin(); j != drawables.end(); ++j ) { j->get()->setDataVariance( osg::Object::DYNAMIC ); // j->get()->getOrCreateStateSet()->setRenderBinDetails( bin++, "RenderBin" ); geode->addDrawable( j->get() ); } } } _contextDirty = false; }
ControlParameter * MidiDevice::getControlParameter(const std::string &type, Rosegarden::MidiByte controllerValue) { ControlList::iterator it = m_controlList.begin(); for (; it != m_controlList.end(); ++it) { if (it->getType() == type) { // Return matched on type for most events // if (type != Rosegarden::Controller::EventType) return &*it; // Also match controller value for Controller events // if (it->getControllerValue() == controllerValue) return &*it; } } return 0; }
std::string MidiDevice::toXmlString() { std::stringstream midiDevice; midiDevice << " <device id=\"" << m_id << "\" name=\"" << m_name << "\" direction=\"" << (m_direction == Play ? "play" : "record") << "\" variation=\"" << (m_variationType == VariationFromLSB ? "LSB" : m_variationType == VariationFromMSB ? "MSB" : "") << "\" connection=\"" << encode(m_connection) << "\" type=\"midi\">" << std::endl << std::endl; midiDevice << " <librarian name=\"" << encode(m_librarian.first) << "\" email=\"" << encode(m_librarian.second) << "\"/>" << std::endl; if (m_metronome) { // Write out the metronome - watch the MidiBytes // when using the stringstream // midiDevice << " <metronome " << "instrument=\"" << m_metronome->getInstrument() << "\" " << "barpitch=\"" << (int)m_metronome->getBarPitch() << "\" " << "beatpitch=\"" << (int)m_metronome->getBeatPitch() << "\" " << "subbeatpitch=\"" << (int)m_metronome->getSubBeatPitch() << "\" " << "depth=\"" << (int)m_metronome->getDepth() << "\" " << "barvelocity=\"" << (int)m_metronome->getBarVelocity() << "\" " << "beatvelocity=\"" << (int)m_metronome->getBeatVelocity() << "\" " << "subbeatvelocity=\"" << (int)m_metronome->getSubBeatVelocity() << "\"/>" << std::endl << std::endl; } // and now bank information // BankList::iterator it; InstrumentList::iterator iit; ProgramList::iterator pt; for (it = m_bankList.begin(); it != m_bankList.end(); ++it) { midiDevice << " <bank " << "name=\"" << encode(it->getName()) << "\" " << "percussion=\"" << (it->isPercussion() ? "true" : "false") << "\" " << "msb=\"" << (int)it->getMSB() << "\" " << "lsb=\"" << (int)it->getLSB() << "\">" << std::endl; // Not terribly efficient // for (pt = m_programList.begin(); pt != m_programList.end(); ++pt) { if (pt->getBank() == *it) { midiDevice << " <program " << "id=\"" << (int)pt->getProgram() << "\" " << "name=\"" << encode(pt->getName()) << "\" "; if (!pt->getKeyMapping().empty()) { midiDevice << "keymapping=\"" << encode(pt->getKeyMapping()) << "\" "; } midiDevice << "/>" << std::endl; } } midiDevice << " </bank>" << std::endl << std::endl; } // Now controllers (before Instruments, which can depend on // Controller colours) // midiDevice << " <controls>" << std::endl; ControlList::iterator cIt; for (cIt = m_controlList.begin(); cIt != m_controlList.end() ; ++cIt) midiDevice << cIt->toXmlString(); midiDevice << " </controls>" << std::endl << std::endl; // Add instruments // for (iit = m_instruments.begin(); iit != m_instruments.end(); ++iit) midiDevice << (*iit)->toXmlString(); KeyMappingList::iterator kit; for (kit = m_keyMappingList.begin(); kit != m_keyMappingList.end(); ++kit) { midiDevice << " <keymapping " << "name=\"" << encode(kit->getName()) << "\">\n"; for (MidiKeyMapping::KeyNameMap::const_iterator nmi = kit->getMap().begin(); nmi != kit->getMap().end(); ++nmi) { midiDevice << " <key number=\"" << (int)nmi->first << "\" name=\"" << encode(nmi->second) << "\"/>\n"; } midiDevice << " </keymapping>\n"; } midiDevice << " </device>" << std::endl; return midiDevice.str(); }
void MIDIInstrumentParameterPanel::setupControllers(MidiDevice *md) { RG_DEBUG << "setupControllers()"; if (!md) return; // To cut down on flicker, we avoid destroying and recreating // widgets as far as possible here. If a label already exists, // we just set its text; if a rotary exists, we only replace it // if we actually need a different one. Composition &comp = m_doc->getComposition(); ControlList list = md->getControlParameters(); // Sort by IPB position. std::sort(list.begin(), list.end(), ControlParameter::ControlPositionCmp()); int count = 0; RotaryInfoVector::iterator rotaryIter = m_rotaries.begin(); // For each controller for (ControlList::iterator it = list.begin(); it != list.end(); ++it) { if (it->getIPBPosition() == -1) continue; // Get the knob colour (even if it's default, because otherwise it turns // black instead of the default color from the map! it was here the // whole time, this simple!) // const Colour c = comp.getGeneralColourMap().getColourByIndex( it->getColourIndex()); const QColor knobColour = QColor(c.getRed(), c.getGreen(), c.getBlue()); Rotary *rotary = 0; // If the Rotary widgets have already been created, update them. if (rotaryIter != m_rotaries.end()) { // Update the controller number that is associated with the // existing rotary widget. rotaryIter->controller = it->getControllerValue(); // Update the properties of the existing rotary widget. rotary = rotaryIter->rotary; rotary->setMinimum(it->getMin()); rotary->setMaximum(it->getMax()); // If the default is 64, then this is most likely a "centered" // control which should show its distance from the 12 o'clock // position around the outside. rotary->setCentered((it->getDefault() == 64)); rotary->setKnobColour(knobColour); // Update the controller name. rotaryIter->label->setText(QObject::tr(it->getName().c_str())); // Next Rotary widget ++rotaryIter; } else { // Need to create the Rotary widget. // Create a horizontal box for the Rotary/Label pair. QWidget *hbox = new QWidget(m_rotaryFrame); QHBoxLayout *hboxLayout = new QHBoxLayout; hboxLayout->setSpacing(8); hboxLayout->setMargin(0); hbox->setLayout(hboxLayout); // Add a Rotary float pageStep = 5.0; if (it->getMax() - it->getMin() < 10) pageStep = 1.0; else if (it->getMax() - it->getMin() < 20) pageStep = 2.0; rotary = new Rotary(hbox, // parent it->getMin(), // minimum it->getMax(), // maximum 1.0, // step pageStep, // pageStep it->getDefault(), // initialPosition 20, // size Rotary::NoTicks, // ticks false, // snapToTicks (it->getDefault() == 64)); // centred, see setCentered() above rotary->setKnobColour(knobColour); hboxLayout->addWidget(rotary); // Add a label SqueezedLabel *label = new SqueezedLabel(QObject::tr(it->getName().c_str()), hbox); label->setFont(font()); hboxLayout->addWidget(label); RG_DEBUG << "setupControllers(): Adding new widget at " << (count / 2) << "," << (count % 2); // Add the compound (Rotary and Label) widget to the grid. m_rotaryGrid->addWidget(hbox, count / 2, (count % 2) * 2, Qt::AlignLeft); hbox->show(); // Add to the Rotary info list RotaryInfo ri; ri.rotary = rotary; ri.label = label; ri.controller = it->getControllerValue(); m_rotaries.push_back(ri); // Connect for changes to the Rotary by the user. connect(rotary, SIGNAL(valueChanged(float)), m_rotaryMapper, SLOT(map())); rotaryIter = m_rotaries.end(); } // Add signal mapping // m_rotaryMapper->setMapping(rotary, int(it->getControllerValue())); ++count; } // If there are more rotary widgets than this instrument needs, // delete them. if (rotaryIter != m_rotaries.end()) { for (RotaryInfoVector::iterator it = rotaryIter; it != m_rotaries.end(); ++it) { // ??? Instead of deleting and recreating, we could hide the // extras and bring them back when needed. delete it->rotary; delete it->label; } m_rotaries.resize(count); } }