void NoteEntryAction::renderKeyboardPreview(QPainter& painter, const MusicCursor& cursor) { Staff* staff = cursor.staff(); Part* part = staff->part(); Sheet* sheet = part->sheet(); Bar* bar = sheet->bar(cursor.bar()); QPointF p = bar->position() + QPointF(0, staff->top()); Voice* voice = cursor.staff()->part()->voice(cursor.voice()); VoiceBar* vb = voice->bar(bar); if (cursor.element() >= vb->elementCount()) { // cursor is past last element in bar, position of cursor is // halfway between last element and end of bar if (vb->elementCount() == 0) { // unless entire voicebar is still empty p.rx() += 15.0; } else { VoiceElement* ve = vb->element(vb->elementCount()-1); p.rx() += (ve->x() + bar->size()) / 2; } } else { // cursor is on an element, get the position of that element p.rx() += vb->element(cursor.element())->x(); } p.ry() += (cursor.staff()->lineCount() - 1)* cursor.staff()->lineSpacing(); p.ry() -= cursor.staff()->lineSpacing() * cursor.line() / 2; m_tool->shape()->renderer()->renderNote(painter, m_duration < QuarterNote ? QuarterNote : m_duration, p, 0, Qt::magenta); }
bool VoiceManager::stopVoice(NoteUniqueId ID) { assert(_initialised); // find the note in the active note map ActiveVoiceList::iterator iter = activeVoices.find(ID); // note not active?! if(iter == activeVoices.end()) return false; // release the note Voice* v = iter->second.voice(); v->release(); // add to inactive voices vector inactiveVoices.push_back(v); // remove from active voices map activeVoices.erase(iter); assert(_sanityCheck()); // reset note counter on silence if(activeVoices.empty() && inactiveVoices.empty()) { _counter = 0; } return true; }
// kill all voices and move to free stack void VoiceManager::_freeAllVoices() { if(!_initialised) return; Voice* v; // active voices ActiveVoiceList::iterator iter1; for(iter1 = activeVoices.begin(); iter1 != activeVoices.end(); ++iter1) { v = iter1->second.voice(); v->kill(); freeVoices.push(v); } activeVoices.clear(); // inactive voices InactiveVoiceList::iterator iter2; for(iter2 = inactiveVoices.begin(); iter2 != inactiveVoices.end(); ++iter2) { v = *iter2; v->kill(); freeVoices.push(v); } inactiveVoices.clear(); // reset the note age counter _counter = 0; }
void keyboardchar(int key) { // select a NIDAQ channel if the key is a number from 0 to 9: if (isdigit(key)) { if (keyselect) { keychan = key - '0'; keyselect = 0; cout << "\nKey Channel " << key - '0' << " selected" << endl; } if (velselect) { velchan = key - '0'; velselect = 0; cout << "\nVelocity Channel " << key - '0' << " selected" << endl; } return; } switch (key) { case 'd': // toggle display of sensor data on screen display = !display; break; case 'k': // toggle key number channel select option keyselect = !keyselect; break; case 'v': // toggle velocity channel select option velselect = !velselect; break; case 'z': // reset the key sensor range keymax = -10.0; keymin = 10.0; break; case 'x': // reset the velocity sensor range velmax = -10.0; velmin = 10.0; break; case 'a': // reverse the key axis of the sensor data keydir = -keydir; break; case 's': // reverse the veolcity sensor direction veldir = -veldir; break; case '-': // decrement instrument inst--; if (inst < 0) inst = 127; voice.pc(inst); cout << "\ninst = " << inst << endl; break; case '=': // increment instrument inst++; if (inst > 127) inst = 0; voice.pc(inst); cout << "\ninst = " << inst << endl; break; case ' ': // sustain pedal on/off sustain = !sustain; voice.sustain(sustain); cout << "\nsustain = " << sustain << endl; break; } }
void mainloopalgorithms(void) { if (seqstate && nextnotetime <= t_time) { nextnotetime += duration; if (curbeat >= meter*2 || curbeat == 0) { curbeat = 0; emphasis = midiscale(baton.d2p, 0, 20); meter = nextmeter; } else { if (curbeat % 2 == 0) { emphasis = 7; } else { emphasis = 0; } } curbeat++; if (baton.z2p < z2level) { emphasis = 0; } key = nextHenon(alpha, beta, x, xx) + transpose; if (key >= minnote && key <= maxnote) { cout << "\tPlaying note: " << key << "\tvel=" << loudness + emphasis << "\tdur=" << duration << "\tbeat=" << curbeat/2.0+0.5 << " " << "\tmeter=" << meter << endl; voice.play(key, loudness + emphasis); } else { voice.off(); } } }
void VoiceHandler::process() { global_router_.process(); int polyphony = static_cast<int>(input(kPolyphony)->at(0)); setPolyphony(utils::iclamp(polyphony, 1, polyphony)); for (int i = 0; i < numOutputs(); ++i) { int buffer_size = voice_outputs_[i]->owner->getBufferSize(); memset(output(i)->buffer, 0, buffer_size * sizeof(mopo_float)); } std::list<Voice*>::iterator iter = active_voices_.begin(); while (iter != active_voices_.end()) { Voice* voice = *iter; prepareVoiceTriggers(voice); processVoice(voice); // Remove voice if the right processor has a full silent buffer. if (voice_killer_ && voice->state().event != kVoiceOn && utils::isSilent(voice_killer_->buffer, buffer_size_)) { free_voices_.push_back(voice); iter = active_voices_.erase(iter); } else iter++; } }
void Prog::initial_config() { Voice *voice = new_voice(); if (!voice) { abort_example("Could not create initial voice.\n"); } voice->set_pos(300, 50); Mixer *mixer = new_mixer(); mixer->set_pos(300, 150); voice->attach(mixer); SampleInstance *splinst = new_sample_instance(); splinst->set_pos(220, 300); mixer->attach(splinst); splinst->toggle_playing(); SampleInstance *splinst2 = new_sample_instance(); splinst2->set_pos(120, 240); mixer->attach(splinst2); splinst2->toggle_playing(); Mixer *mixer2 = new_mixer(); mixer2->set_pos(500, 250); mixer->attach(mixer2); Audiostream *stream; if ((stream = new_audiostream())) { stream->set_pos(450, 350); mixer2->attach(stream); } }
void AudioThread::ReleaseVoice(uint8_t MIDIKey, uint8_t Velocity) { Voice* pVoice = ActiveVoices[MIDIKey]; if (pVoice) { pVoice->Kill(); //TODO: for now we're rude and just kill the poor, poor voice immediately :), later we add a Release() method to the Voice class and call it here to let the voice go through it's release phase ActiveVoices[MIDIKey] = NULL; } else std::cerr << "Couldn't find active voice for note off command!" << std::endl << std::flush; }
void Zerberus::allNotesOff(int channel) { busy = true; for (Voice* v = activeVoices; v; v = v->next()) { if (channel == -1 || (v->channel()->idx() == channel)) v->stop(); } busy = false; }
void VoiceHandler::sustainOff() { sustain_ = false; std::list<Voice*>::iterator iter = sustained_voices_.begin(); for (; iter != sustained_voices_.end(); ++iter) { Voice* voice = *iter; voice->deactivate(); } sustained_voices_.clear(); }
static void setOscillatorPitchMod(Voice& voice, int oscillatorNumber, double amount) { switch (oscillatorNumber) { case 1: voice.setOscillatorOnePitchAmount(amount); break; case 2: voice.setOscillatorTwoPitchAmount(amount); break; } }
void VoiceManager::onNoteOn(int noteNumber, int velocity) { Voice* voice = findFreeVoice(); if (!voice) { return; } voice->reset(); voice->setNoteNumber(noteNumber); voice->mVelocity = velocity; voice->isActive = true; voice->mVolumeEnvelope.enterStage(EnvelopeGenerator::ENVELOPE_STAGE_ATTACK); voice->mFilterEnvelope.enterStage(EnvelopeGenerator::ENVELOPE_STAGE_ATTACK); }
Voice *Prog::new_voice() { Voice *voice = new Voice(); if (voice->valid()) { elements.push_back(voice); } else { delete voice; voice = NULL; } return voice; }
void playNote(int note) { Voice* best = &voices[0]; double busy = best->getBusiness(); for (Voice& v : voices) { double b = v.getBusiness(); if (b < busy) { busy = b; best = &v; } } best->play(note); }
void VoiceHandler::noteOn(mopo_float note, mopo_float velocity, int sample, int channel) { MOPO_ASSERT(sample >= 0 && sample < buffer_size_); MOPO_ASSERT(channel >= 0 && channel < NUM_MIDI_CHANNELS); Voice* voice = grabVoice(); pressed_notes_.push_front(note); if (last_played_note_ < 0) last_played_note_ = note; voice->activate(note, velocity, last_played_note_, pressed_notes_.size(), sample, channel); active_voices_.push_back(voice); last_played_note_ = note; }
void mi::MidiNote(int const channel, int const value, int const velocity) { Voice * v; if(velocity > 0) { v = voice_manager->GetVoice(); v->SetMidiNote(value); voice_manager->TriggerNewVoice(helper::midinote_to_buzz(value), filter_freq, v); } if(velocity == 0) { voice_manager->InitiateReleaseForMidiNote(value); } }
void Zerberus::process(unsigned frames, float* p, float*, float*) { if (busy) return; while (!midiEvents.empty()) process(midiEvents.pop()); Voice* v = activeVoices; Voice* pv = 0; int n = 0; int nn = 0; while (v) { ++nn; v->process(frames, p); if (v->isOff()) { if (pv) pv->setNext(v->next()); else activeVoices = v->next(); ++n; freeVoices.push(v); } else pv = v; v = v->next(); } }
void NoteEntryAction::mousePress(Staff* staff, int bar, const QPointF& pos) { Clef* clef = staff->lastClefChange(bar); Voice* voice = staff->part()->voice(m_tool->voice()); VoiceBar* vb = voice->bar(bar); // find element before which to insert the chord int before = 0; for (int i = 0; i < vb->elementCount(); i++) { VoiceElement* e = vb->element(i); if (e->x() >= pos.x()) break; before++; } int line = staff->line(pos.y()); int pitch = 0, accidentals = 0; if (clef && !m_isRest) { pitch = clef->lineToPitch(line); // get correct accidentals for note KeySignature* ks = staff->lastKeySignatureChange(bar); if (ks) accidentals = ks->accidentals(pitch); for (int i = 0; i < before; i++) { Chord* c = dynamic_cast<Chord*>(vb->element(i)); if (!c) continue; for (int n = 0; n < c->noteCount(); n++) { if (c->note(n)->pitch() == pitch) { accidentals = c->note(n)->accidentals(); } } } } Chord* join = NULL; if (before > 0) join = dynamic_cast<Chord*>(vb->element(before-1)); if (join && join->x() + join->width() >= pos.x()) { if (clef && !m_isRest) { m_tool->addCommand(new AddNoteCommand(m_tool->shape(), join, staff, m_duration, pitch, accidentals)); } else { m_tool->addCommand(new MakeRestCommand(m_tool->shape(), join)); } } else { if (clef && !m_isRest) { m_tool->addCommand(new CreateChordCommand(m_tool->shape(), vb, staff, m_duration, before, pitch, accidentals)); } else { m_tool->addCommand(new CreateChordCommand(m_tool->shape(), vb, staff, m_duration, before)); } } }
void VoiceHandler::noteOn(mopo_float note, mopo_float velocity) { Voice* voice = 0; pressed_notes_.push_back(note); if (free_voices_.size() && active_voices_.size() < polyphony_) { voice = free_voices_.front(); free_voices_.pop_front(); } else { voice = active_voices_.front(); active_voices_.pop_front(); } voice->activate(note, velocity); active_voices_.push_back(voice); }
// // StopByOwner // // Stop all voices with the given owner id // void StopByOwner(U32 id) { if (Initialized()) { for (U32 i = 0; i < totalVoices; i++) { // Get the voice at this index Voice *voice = voices[i]; if (voice->owner == id) { voice->Stop(); } } } }
void VoiceHandler::setPolyphony(size_t polyphony) { while (all_voices_.size() < polyphony) { Voice* new_voice = createVoice(); all_voices_.push_back(new_voice); active_voices_.push_back(new_voice); } int num_voices_to_kill = active_voices_.size() - polyphony; for (int i = 0; i < num_voices_to_kill; ++i) { Voice* sacrifice = getVoiceToKill(); if (sacrifice) sacrifice->kill(); } polyphony_ = polyphony; }
int ts3plugin_onTextMessageEvent(uint64 serverConnectionHandlerID, anyID targetMode, anyID toID, anyID fromID, const char* fromName, const char* fromUniqueIdentifier, const char* message, int ffIgnored) { std::string text(message); std::regex expression("\\[URL\\].*\\[/URL\\]"); text = std::regex_replace(text, expression, "Link"); voice.Speak(text.c_str()); printf("PLUGIN: onTextMessageEvent %llu %d %d %s %s %d\n", (long long unsigned int)serverConnectionHandlerID, targetMode, fromID, fromName, message, ffIgnored); /* Friend/Foe manager has ignored the message, so ignore here as well. */ if(ffIgnored) { return 0; /* Client will ignore the message anyways, so return value here doesn't matter */ } #if 0 { /* Example code: Autoreply to sender */ /* Disabled because quite annoying, but should give you some ideas what is possible here */ /* Careful, when two clients use this, they will get banned quickly... */ anyID myID; if(ts3Functions.getClientID(serverConnectionHandlerID, &myID) != ERROR_ok) { ts3Functions.logMessage("Error querying own client id", LogLevel_ERROR, "Plugin", serverConnectionHandlerID); return 0; } if(fromID != myID) { /* Don't reply when source is own client */ if(ts3Functions.requestSendPrivateTextMsg(serverConnectionHandlerID, "Text message back!", fromID, NULL) != ERROR_ok) { ts3Functions.logMessage("Error requesting send text message", LogLevel_ERROR, "Plugin", serverConnectionHandlerID); } } } #endif return 0; /* 0 = handle normally, 1 = client will ignore the text message */ }
void VoiceManager::initialise(SamplingRate rate) { // initialise all voices with the sampling rate _wipeLists(); for(unsigned int i = 0; i < kMaxPolyphony; ++i) { Voice* v = new Voice(core); v->initialise(rate); freeVoices.push(v); } inactiveVoices.reserve(kMaxPolyphony); assert(freeVoices.size() == kMaxPolyphony); _freeAllVoices(); _initialised = true; }
// // StopByRecord // // Stop all voices playing the given record // void StopByRecord(Record *r) { if (Initialized()) { for (U32 i = 0; i < totalVoices; i++) { // Get the voice at this index Voice *voice = voices[i]; if ((voice->Status() != SMP_DONE) && (voice->record == r)) { voice->Stop(); } } } }
void Envelope::keyOff(const Voice& vox) { double releaseTime = m_releaseTime; if (vox.m_state.m_useAdsrControllers) releaseTime = MIDItoTIME[clamp(0, int(vox.getCtrlValue(vox.m_state.m_midiRelease)), 103)] / 1000.0; m_phase = (releaseTime != 0.0) ? State::Release : State::Complete; m_curTime = 0.0; }
void initialization(void) { sensor.initialize(options.argv()); // start CVIRTE stuff for NIDAQ card sensor.setPollPeriod(1); // check for new data every 1 millisecond sensor.setFrameSize(1); // data transfer size from NIDAQ card sensor.setModeLatest(); // just look at most recent data in buffer sensor.setSrate(500); // set NIDAQ sampling rate to X Hz sensor.activateAllChannels(); // turn on all channels for sampling cout << "starting data aquisition ... " << flush; sensor.start(); // start aquiring data from NIDAQ card cout << "ready." << endl; voice.setPort(synth.getOutputPort()); // specify output port of voice voice.setChannel(0); // specify output chan of voice voice.pc(inst); displayTimer.setPeriod(200); // display position every X milliseconds }
// // FindVoicePlayingEffect // // Returns the first voice playing 'e', or NULL // static Voice * FindVoicePlayingEffect(Effect *e) { // Ensure index is valid if (e->GetVoiceIndex() < totalVoices) { // Get the voice at this index Voice *v = voices[e->GetVoiceIndex()]; // Still playing and pointing to the given effect if ((v->Status() != SMP_DONE) && v->effect.Alive() && (v->effect == e)) { return (v); } } return (NULL); }
// // StopByEffect // // Stop all voices played using the given effect // void StopByEffect(Effect *e) { if (Initialized()) { for (U32 i = 0; i < totalVoices; i++) { // Get the voice at this index Voice *voice = voices[i]; // Effect is still alive and matches the one supplied if (voice->effect.Alive() && voice->effect == e) { voice->Stop(); } } } }
void stick1pollresponse(void) { duration = midiscale(127-baton.y1p, 70, 300); loudness = midiscale(baton.x1p, 20, 100); if (baton.z1p < z1level) { seqstate = 0; // turn off seq if baton too high voice.off(); } }
Voice* VoiceManager::_voiceStealer(T& container) { #ifndef NDEBUG typename T::size_type s = container.size(); #endif // is this container empty? if(container.empty()) return 0; // find the lowest amplitude voice in the inactive voice vector typename T::iterator iter = container.begin(); // try the first element typename T::iterator lowestElem = iter; U lowestVal, thisVal; _getPredValue(iter, lowestVal); // try all others ++iter; while(iter != container.end()) { //thisAmp = _derefListIter(iter)->getCurrentAmp(); _getPredValue(iter, thisVal); // is this note quieter? if(thisVal < lowestVal) { lowestVal = thisVal; lowestElem = iter; } ++iter; } // kill the voice Voice* v = _derefListIter(lowestElem); v->kill(); // remove from container container.erase(lowestElem); #ifndef NDEBUG assert(container.size() == s-1); #endif return v; }