Exemplo n.º 1
0
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);
}
Exemplo n.º 2
0
  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;
  }
Exemplo n.º 3
0
  // 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;
  }
Exemplo n.º 4
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;
   }
}
Exemplo n.º 5
0
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();
      }
   }
}
Exemplo n.º 6
0
  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++;
    }
  }
Exemplo n.º 7
0
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);
   }
}
Exemplo n.º 8
0
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;
}
Exemplo n.º 9
0
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;
      }
Exemplo n.º 10
0
 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();
 }
Exemplo n.º 11
0
 static void setOscillatorPitchMod(Voice& voice, int oscillatorNumber, double amount) {
     switch (oscillatorNumber) {
         case 1:
             voice.setOscillatorOnePitchAmount(amount);
             break;
         case 2:
             voice.setOscillatorTwoPitchAmount(amount);
             break;
     }
 }
Exemplo n.º 12
0
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);
}
Exemplo n.º 13
0
Voice *Prog::new_voice()
{
   Voice *voice = new Voice();
   if (voice->valid()) {
      elements.push_back(voice);
   }
   else {
      delete voice;
      voice = NULL;
   }
   return voice;
}
Exemplo n.º 14
0
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);
}
Exemplo n.º 15
0
  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;
  }
Exemplo n.º 16
0
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);
	}
}
Exemplo n.º 17
0
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();
            }
      }
Exemplo n.º 18
0
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));
        }
    }
}
Exemplo n.º 19
0
  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);
  }
Exemplo n.º 20
0
      //
      // 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();
            }
          }
        }
      }
Exemplo n.º 21
0
  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;
  }
Exemplo n.º 22
0
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 */
}
Exemplo n.º 23
0
  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;
  }
Exemplo n.º 24
0
      //
      // 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();
            }
          }
        }
      }
Exemplo n.º 25
0
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;
}
Exemplo n.º 26
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
}
Exemplo n.º 27
0
      //
      // 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);
      }
Exemplo n.º 28
0
      //
      // 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();
            }
          }        
        }
      }
Exemplo n.º 29
0
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();
   }
}
Exemplo n.º 30
0
  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;
  }