FluidPlayer::FluidPlayer() { //MIDI params midiOut.listPorts(); // via instance midiIn.listPorts(); // via instance midiOut.openPort("passthrough_in"); // by name midiIn.openPort("passthrough_out"); // by name //midiOut.openPort("Network Sonoromancer_host"); //midiIn.openPort("Network Sonoromancer_host"); midiIn.ignoreTypes(false, false, false); midiIn.addListener(this); baseNoteMessageLength = DEMISEMIQUAVER; upperTimesig = 4; lowerTimesig = 4; currentInstrumentIndex = 0; loadInstruments(); loadScales(); setRootNote(NOTE_C); setScale( getScaleByName("Minor")); setInstrument( instrumentList[0] ); }
// Instrument file loader. bool Channel::loadInstrument ( const QString& sInstrumentFile, int iInstrumentNr ) { MainForm *pMainForm = MainForm::getInstance(); if (pMainForm == NULL) return false; if (pMainForm->client() == NULL || m_iChannelID < 0) return false; if (!isInstrumentFile(sInstrumentFile)) return false; if (m_iInstrumentStatus == 100 && m_sInstrumentFile == sInstrumentFile && m_iInstrumentNr == iInstrumentNr) return true; if ( ::lscp_load_instrument_non_modal( pMainForm->client(), qsamplerUtilities::lscpEscapePath( sInstrumentFile).toUtf8().constData(), iInstrumentNr, m_iChannelID ) != LSCP_OK ) { appendMessagesClient("lscp_load_instrument"); return false; } appendMessages(QObject::tr("Instrument: \"%1\" (%2).") .arg(sInstrumentFile).arg(iInstrumentNr)); return setInstrument(sInstrumentFile, iInstrumentNr); }
bool Part::readProperties(XmlReader& e) { const QStringRef& tag(e.name()); if (tag == "Staff") { Staff* staff = new Staff(score()); staff->setPart(this); score()->staves().push_back(staff); _staves.push_back(staff); staff->read(e); } else if (tag == "Instrument") { Instrument* instr = new Instrument; instr->read(e, this); setInstrument(instr, -1); } else if (tag == "name") instrument()->setLongName(e.readElementText()); else if (tag == "shortName") instrument()->setShortName(e.readElementText()); else if (tag == "trackName") _partName = e.readElementText(); else if (tag == "show") _show = e.readInt(); else return false; return true; }
void Part::read(XmlReader& e) { while (e.readNextStartElement()) { const QStringRef& tag(e.name()); if (tag == "Staff") { Staff* staff = new Staff(_score); staff->setPart(this); _score->staves().push_back(staff); _staves.push_back(staff); staff->read(e); } else if (tag == "Instrument") { Instrument* instr = new Instrument; instr->read(e); setInstrument(instr, -1); } else if (tag == "name") instrument()->setLongName(e.readElementText()); else if (tag == "shortName") instrument()->setShortName(e.readElementText()); else if (tag == "trackName") _partName = e.readElementText(); else if (tag == "show") _show = e.readInt(); else e.unknown(); } if (_partName.isEmpty()) _partName = instrument()->trackName(); }
/** * @param aPosition position in the sequencer where this event starts playing * @param aLength length (in sequencer steps) of this event * @param aInstrument the SynthInstrument whose properties will be used for synthesizing this event * can be NULL to keep the current SynthInstrument, if not null the current * SynthInstrument is replaced */ void BaseSynthEvent::invalidateProperties( int aPosition, float aLength, SynthInstrument* aInstrument ) { setInstrument( aInstrument ); position = aPosition; length = aLength; updateProperties(); // instant update as we're not rendering }
/** Create an EventWorkspace containing fake data * of single-crystal diffraction. * Instrument is MINITOPAZ * * @return EventWorkspace_sptr */ EventWorkspace_sptr createDiffractionEventWorkspace(int numEvents, int numPixels, int numBins) { double binDelta = 10.0; auto retVal = boost::make_shared<EventWorkspace>(); retVal->initialize(numPixels, 1, 1); // --------- Load the instrument ----------- const std::string filename = FileFinder::Instance().getFullPath( "IDFs_for_UNIT_TESTING/MINITOPAZ_Definition.xml"); InstrumentDefinitionParser parser(filename, "MINITOPAZ", Strings::loadFile(filename)); auto instrument = parser.parseXML(nullptr); retVal->populateInstrumentParameters(); retVal->setInstrument(instrument); DateAndTime run_start("2010-01-01T00:00:00"); for (int pix = 0; pix < numPixels; pix++) { for (int i = 0; i < numEvents; i++) { retVal->getSpectrum(pix) += Mantid::DataObjects::TofEvent( (i + 0.5) * binDelta, run_start + double(i)); } retVal->getSpectrum(pix).addDetectorID(pix); } // Create the x-axis for histogramming. HistogramData::BinEdges x1(numBins); auto &xRef = x1.mutableData(); for (int i = 0; i < numBins; ++i) { xRef[i] = i * binDelta; } // Set all the histograms at once. retVal->setAllX(x1); // Default unit: TOF. retVal->getAxis(0)->setUnit("TOF"); // Give it a crystal and goniometer WorkspaceCreationHelper::setGoniometer(retVal, 0., 0., 0.); WorkspaceCreationHelper::setOrientedLattice(retVal, 1., 1., 1.); // Some sanity checks if (retVal->getInstrument()->getName() != "MINITOPAZ") throw std::runtime_error("MDEventsTestHelper::" "createDiffractionEventWorkspace(): Wrong " "instrument loaded."); Mantid::detid2det_map dets; retVal->getInstrument()->getDetectors(dets); if (dets.size() != 100 * 100) throw std::runtime_error("MDEventsTestHelper::" "createDiffractionEventWorkspace(): Wrong " "instrument size."); return retVal; }
void FluidPlayer::nextInstrument() { int instrumentIndex = getInstrumentIndex(m_activeInstrument); if(instrumentIndex == -1) return; if( instrumentIndex+1 >= instrumentList.size()) instrumentIndex = 0; else instrumentIndex++; setInstrument(instrumentList[instrumentIndex]); }
void FluidPlayer::prevInstrument() { int instrumentIndex = getInstrumentIndex(m_activeInstrument); if(instrumentIndex == -1) return; if( instrumentIndex-1 < 0 ) instrumentIndex = instrumentList.size() - 1; else instrumentIndex--; setInstrument(instrumentList[instrumentIndex]); }
// Instrument file loader. bool qsamplerChannel::loadInstrument ( const QString& sInstrumentFile, int iInstrumentNr ) { if (client() == NULL || m_iChannelID < 0) return false; if (!isInstrumentFile(sInstrumentFile)) return false; if (m_iInstrumentStatus == 100 && m_sInstrumentFile == sInstrumentFile && m_iInstrumentNr == iInstrumentNr) return true; if (::lscp_load_instrument_non_modal(client(), sInstrumentFile.latin1(), iInstrumentNr, m_iChannelID) != LSCP_OK) { appendMessagesClient("lscp_load_instrument"); return false; } appendMessages(QObject::tr("Instrument: \"%1\" (%2).") .arg(sInstrumentFile).arg(iInstrumentNr)); return setInstrument(sInstrumentFile, iInstrumentNr); }
void MainWindow::initializeNewTab(const bool &isOpen, const QString &filePath) { ImageArea *imageArea; QString fileName(tr("Untitled Image")); if(isOpen && filePath.isEmpty()) { imageArea = new ImageArea(isOpen, "", this); fileName = imageArea->getFileName(); } else if(isOpen && !filePath.isEmpty()) { imageArea = new ImageArea(isOpen, filePath, this); fileName = imageArea->getFileName(); } else { imageArea = new ImageArea(false, "", this); } if (!imageArea->getFileName().isNull()) { QScrollArea *scrollArea = new QScrollArea(); scrollArea->setAttribute(Qt::WA_DeleteOnClose); scrollArea->setBackgroundRole(QPalette::Dark); scrollArea->setWidget(imageArea); mTabWidget->addTab(scrollArea, fileName); mTabWidget->setCurrentIndex(mTabWidget->count()-1); mUndoStackGroup->addStack(imageArea->getUndoStack()); connect(imageArea, SIGNAL(sendPrimaryColorView()), mToolbar, SLOT(setPrimaryColorView())); connect(imageArea, SIGNAL(sendSecondaryColorView()), mToolbar, SLOT(setSecondaryColorView())); connect(imageArea, SIGNAL(sendRestorePreviousInstrument()), this, SLOT(restorePreviousInstrument())); connect(imageArea, SIGNAL(sendSetInstrument(InstrumentsEnum)), this, SLOT(setInstrument(InstrumentsEnum))); connect(imageArea, SIGNAL(sendNewImageSize(QSize)), this, SLOT(setNewSizeToSizeLabel(QSize))); connect(imageArea, SIGNAL(sendCursorPos(QPoint)), this, SLOT(setNewPosToPosLabel(QPoint))); connect(imageArea, SIGNAL(sendColor(QColor)), this, SLOT(setCurrentPipetteColor(QColor))); connect(imageArea, SIGNAL(sendEnableCopyCutActions(bool)), this, SLOT(enableCopyCutActions(bool))); connect(imageArea, SIGNAL(sendEnableSelectionInstrument(bool)), this, SLOT(instumentsAct(bool))); setWindowTitle(QString("%1 - EasyPaint").arg(fileName)); }
void ADLPlayer::rewind() { // Reset song data _playPos = _songData; // Set melody/percussion mode setPercussionMode(_soundMode != 0); // Reset instruments for (Common::Array<Timbre>::iterator t = _timbres.begin(); t != _timbres.end(); ++t) memcpy(t->params, t->startParams, kOperatorsPerVoice * kParamCount * sizeof(uint16)); for (int i = 0; i < kMaxVoiceCount; i++) _currentInstruments[i] = 0; // Reset voices int numVoice = MIN<int>(_timbres.size(), _soundMode ? (int)kMaxVoiceCount : (int)kMelodyVoiceCount); for (int i = 0; i < numVoice; i++) { setInstrument(i, _currentInstruments[i]); setVoiceVolume(i, kMaxVolume); } _modifyInstrument = 0xFF; }
bool DmoPlayer::load(const std::string& filename) { FileStream f(filename); if(!f || f.extension() != ".dmo") return false; unsigned char chkhdr[16]; f.read(chkhdr, 16); DMOUnpacker unpacker; if(!unpacker.decrypt(chkhdr, 16)) { return false; } f.seek(0); std::vector<uint8_t> packed_module(f.size()); // load file f.read(packed_module.data(), f.size()); // decrypt unpacker.decrypt(packed_module.data(), packed_module.size()); const auto unpacked_length = 0x2000 * ARRAY_AS_WORD(packed_module.data(), 12); std::vector<uint8_t> module(unpacked_length); // unpack if(!unpacker.unpack(packed_module.data() + 12, module.data(), unpacked_length)) { return false; } // "TwinTeam" - signed ? if(memcmp(module.data(), "TwinTeam Module File" "\x0D\x0A", 22)) { return false; } // load header MemoryStream uf; uf.write(module.data(), module.size()); uf.seek(0); S3mHeader header; uf.seekrel(22); // ignore DMO header ID string uf.read(header.name, 28); uf.seekrel(2); // _unk_1 uf >> header.orderCount >> header.instrumentCount >> header.patternCount; uf.seekrel(2); // _unk_2 uf >> header.initialSpeed >> header.initialTempo; header.chanset.fill(0xff); for(int i = 0; i < 9; i++) header.chanset[i] = 0x10 + i; uf.seekrel(32); // ignore panning settings for all 32 channels // load orders for(int i = 0; i < header.orderCount; ++i) { uint8_t tmp; uf >> tmp; addOrder(tmp); std::cerr << "ORD=" << int(tmp) << "\n"; } addOrder(0xff); uf.seekrel(256 - header.orderCount); // load pattern lengths uint16_t my_patlen[100]; uf.read(my_patlen, 100); // load instruments for(int i = 0; i < header.instrumentCount; i++) { S3mInstrument instrument; uf.read(instrument.name, 28); uf >> instrument.volume; uf >> instrument.dsk; uf >> instrument.c2spd; uf >> instrument.type; uf >> instrument.d00; uf >> instrument.d01; uf >> instrument.d02; uf >> instrument.d03; uf >> instrument.d04; uf >> instrument.d05; uf >> instrument.d06; uf >> instrument.d07; uf >> instrument.d08; uf >> instrument.d09; uf >> instrument.d0a; /* * Originally, riven sets d0b = d0a and ignores 1 byte in the * stream, but i guess this was a typo, so i read it here. */ uf >> instrument.d0b; setInstrument(i, instrument); } // load patterns for(int pattern = 0; pattern < header.patternCount; pattern++) { const auto cur_pos = uf.pos(); for(int row = 0; row < 64; row++) { S3mCell* currentChannel = patternChannel(pattern, row); while(true) { uint8_t token; uf >> token; if(!token) break; const auto chan = token & 31; // note + instrument ? if(token & 32) { uint8_t bufbyte; uf >> bufbyte; currentChannel[chan].note = bufbyte & 15; currentChannel[chan].octave = bufbyte >> 4; uf >> currentChannel[chan].instrument; } // volume ? if(token & 64) uf >> currentChannel[chan].volume; // command ? if(token & 128) { uf >> currentChannel[chan].effect; uf >> currentChannel[chan].effectValue; } } }
OscillatorPanel::OscillatorPanel(wxWindow *parent, wxWindowID id) : wxPanel(parent, id, wxDefaultPosition, wxDefaultSize) { selectedVoice = 0; sliderChange = 0; callbacksAssigned = false; wxStaticBoxSizer *panelSizer = new wxStaticBoxSizer (new wxStaticBox (this, wxID_ANY, _T("Oscillator")), wxVERTICAL ); SetSizer( panelSizer ); SetAutoLayout( true ); wxStaticText *text; wxBoxSizer *vBox = new wxBoxSizer(wxVERTICAL); panelSizer->Add(vBox); voiceChoice = new wxChoice(this, VOICE_CHOICE, wxDefaultPosition, wxDefaultSize, NUM_VOICES + 1, voiceChoices); vBox->Add(voiceChoice, wxSizerFlags(0).Center().Expand()); voiceChoice->Select(0); oscillatorCanvas = new OscillatorCanvas(this, wxID_ANY, wxDefaultPosition, wxSize(200, 550)); vBox->Add(oscillatorCanvas); voiceBox = new wxBoxSizer(wxVERTICAL); vBox->Add(voiceBox, wxSizerFlags(0).Expand()); wxBoxSizer *hBox = new wxBoxSizer(wxHORIZONTAL); voiceBox->Add(hBox, wxSizerFlags(0).Expand()); text = new wxStaticText( this, wxID_ANY, _T("Frequency: "), wxDefaultPosition, wxDefaultSize); hBox->Add(text, wxSizerFlags(0).Center()); numerator = new wxSpinCtrl( this, NUMERATOR_SPINNER, wxEmptyString, wxDefaultPosition, wxSize(60, wxDefaultCoord) ); hBox->Add(numerator); text = new wxStaticText( this, wxID_ANY, _T("/"), wxDefaultPosition, wxDefaultSize); hBox->Add(text, wxSizerFlags(0).Center()); denominator = new wxSpinCtrl( this, DENOMINATOR_SPINNER, wxEmptyString, wxDefaultPosition, wxSize(60, wxDefaultCoord) ); hBox->Add(denominator); numerator->SetRange(1, MAX_HARMONICS); denominator->SetRange(1, MAX_HARMONICS); hBox = new wxBoxSizer(wxHORIZONTAL); voiceBox->Add(hBox, wxSizerFlags(0).Expand()); text = new wxStaticText( this, wxID_ANY, _T("Blur:"), wxDefaultPosition, wxDefaultSize); hBox->Add(text); blurSlider = new wxSlider( this, BLUR_SLIDER, 0, 0, 254, wxDefaultPosition, wxSize(125,wxDefaultCoord), wxSL_AUTOTICKS); hBox->Add(blurSlider, wxSizerFlags(1)); hBox = new wxBoxSizer(wxHORIZONTAL); voiceBox->Add(hBox, wxSizerFlags(0).Expand()); text = new wxStaticText( this, wxID_ANY, _T("Stretch:"), wxDefaultPosition, wxDefaultSize); hBox->Add(text); stretchSlider = new wxSlider( this, STRETCH_SLIDER, 0, 0, 254, wxDefaultPosition, wxSize(125,wxDefaultCoord), wxSL_AUTOTICKS); hBox->Add(stretchSlider, wxSizerFlags(1)); inst = 0; setInstrument(0); //PushEventHandler(new WheelCatcher(scrollMe)); panelSizer->Layout(); }
Part::Part(Score* s) { _score = s; _show = true; setInstrument(Instrument(), 0); // default instrument }
void Part::initFromInstrTemplate(const InstrumentTemplate* t) { _partName = t->trackName; setInstrument(Instrument::fromTemplate(t)); }
void ScriptSlots::refreshSlots() { clearSlots(); setInstrument(m_instrument); }
void Group8Strategy::processTrade(const Trade &t) { if (m_magic.contains(t.instrument())) { MagicData &data = m_magic[t.instrument()]; if (t.price() >= data.previousPrice) { if (data.isRising == false) { data.currentConsecutiveChanges = 0; } data.isRising = true; } else { if (data.isRising == true) { data.currentConsecutiveChanges = 0; } data.isRising = false; } data.previousPrice = t.price(); data.previousVolume = t.volume(); data.currentConsecutiveChanges++; if (5 <= data.currentConsecutiveChanges && t.time().secsTo(QTime(16,00)) >= 50) { data.currentConsecutiveChanges = 0; if (data.isRising) { auto r = Record::Ptr::create(); r->setBidId(6666); r->setAskId(0); r->setBidOrAsk(Record::BidAsk::Bid); r->setDate(t.date()); r->setTime(t.time()); r->setInstrument(t.instrument()); r->setType(Record::Type::ENTER); r->setVolume(data.previousVolume); r->setPrice(t.price()); r->setValue(r->price() * r->volume()); emit newRecordCreated(r); qDebug() << "created a bid"; //this is bad data.totalBought += data.previousVolume; } else { auto r = Record::Ptr::create(); r->setAskId(6666); r->setBidId(0); r->setBidOrAsk(Record::BidAsk::Ask); r->setDate(t.date()); r->setTime(t.time()); r->setInstrument(t.instrument()); r->setType(Record::Type::ENTER); r->setVolume(data.totalBought-data.totalSold); r->setPrice(t.price()); r->setValue(r->price() * r->volume()); emit newRecordCreated(r); qDebug() << "created a ask"; //this is bad. data.totalSold += data.totalBought-data.totalSold; } } //qDebug() << abs(QTime(15,40).secsTo(t.time())); //qDebug() <<(data.totalBought-data.totalSold); if( abs(QTime(16,00).secsTo(t.time())) < 50 && (data.totalBought-data.totalSold) > 0) { qDebug() << data.totalBought-data.totalSold; data.currentConsecutiveChanges = 0; auto r = Record::Ptr::create(); r->setAskId(6666); r->setBidId(0); r->setBidOrAsk(Record::BidAsk::Ask); r->setDate(t.date()); r->setTime(t.time()); r->setInstrument(t.instrument()); r->setType(Record::Type::ENTER); r->setVolume(data.totalBought-data.totalSold); r->setPrice(t.price()); r->setValue(r->price() * r->volume()); emit newRecordCreated(r); //this is bad. data.totalSold += data.totalBought-data.totalSold; } } }
void Part::initFromInstrTemplate(const InstrumentTemplate* t) { _partName = t->trackName; Instrument instr = Instrument::fromTemplate(t); setInstrument(instr, 0); }
uint32 ADLPlayer::pollMusic(bool first) { if (_timbres.empty() || !_songData || !_playPos || (_playPos >= (_songData + _songDataSize))) { end(); return 0; } // We'll ignore the first delay if (first) _playPos += (*_playPos & 0x80) ? 2 : 1; byte cmd = *_playPos++; // Song end marker if (cmd == 0xFF) { end(); return 0; } // Set the instrument that should be modified if (cmd == 0xFE) _modifyInstrument = *_playPos++; if (cmd >= 0xD0) { // Modify an instrument if (_modifyInstrument == 0xFF) warning("ADLPlayer: No instrument to modify"); else if (_modifyInstrument >= _timbres.size()) warning("ADLPlayer: Can't modify invalid instrument %d (%d)", _modifyInstrument, _timbres.size()); else _timbres[_modifyInstrument].params[_playPos[0]] = _playPos[1]; _playPos += 2; // If we currently have that instrument loaded, reload it for (int i = 0; i < kMaxVoiceCount; i++) if (_currentInstruments[i] == _modifyInstrument) setInstrument(i, _modifyInstrument); } else { // Voice command uint8 voice = cmd & 0x0F; uint8 note, volume; switch (cmd & 0xF0) { case 0x00: // Note on with volume note = *_playPos++; volume = *_playPos++; setVoiceVolume(voice, volume); noteOn(voice, note); break; case 0xA0: // Pitch bend bendVoicePitch(voice, ((uint16)*_playPos++) << 7); break; case 0xB0: // Set volume setVoiceVolume(voice, *_playPos++); break; case 0xC0: // Set instrument setInstrument(voice, *_playPos++); break; case 0x90: // Note on noteOn(voice, *_playPos++); break; case 0x80: // Note off noteOff(voice); break; default: warning("ADLPlayer: Unsupported command: 0x%02X. Stopping playback.", cmd); end(true); return 0; } } uint16 delay = *_playPos++; if (delay & 0x80) delay = ((delay & 3) << 8) | *_playPos++; return getSampleDelay(delay); }