예제 #1
0
void Lv2Plugin::init ()
{
  m_activated = false;
  m_features = m_world.features.array();
  m_instance = slv2_plugin_instantiate(
      m_plugin, 
      m_sampleRate,
      m_features->get(Feature::PLUGIN_FEATURE) );
  
  Q_ASSERT(m_instance);

  m_name = slv2_plugin_get_name( m_plugin );
  Q_ASSERT(m_name);

  int count = slv2_plugin_get_num_ports(m_plugin);
  m_ports.resize( count );
  for (int i = 0; i < count; ++i) {
    m_ports[i] = new Lv2Port( m_world, this, i );
  }

  m_authorName     = slv2_plugin_get_author_name( m_plugin );
  m_authorEmail    = slv2_plugin_get_author_email( m_plugin );
  m_authorHomepage = slv2_plugin_get_author_homepage( m_plugin );

  m_features->initialize( *this );
}
예제 #2
0
bool LV2Effect::ProcessStereo(int count, WaveTrack *left, WaveTrack *right,
                              sampleCount lstart, 
                              sampleCount rstart,
                              sampleCount len)
{
   
   /* Allocate buffers */
   if (mBlockSize == 0) {
      mBlockSize = left->GetMaxBlockSize() * 2;

      fInBuffer = new float *[mAudioInputs.size()];
      unsigned long i;
      for (i = 0; i < mAudioInputs.size(); i++)
         fInBuffer[i] = new float[mBlockSize];
      fOutBuffer = new float *[mAudioOutputs.size()];
      for (i = 0; i < mAudioOutputs.size(); i++)
         fOutBuffer[i] = new float[mBlockSize];
   }

   /* Instantiate the plugin */
   SLV2Instance handle = slv2_plugin_instantiate(mData, left->GetRate(), 
                                                 gLV2Features);
   
   /* Write the Note On to the MIDI event buffer and connect it */
   LV2_Event_Buffer* midiBuffer;
   int noteOffTime;
   if (mMidiInput) {
      midiBuffer = lv2_event_buffer_new(40, 2);
      LV2_Event_Iterator iter;
      lv2_event_begin(&iter, midiBuffer);
      uint8_t noteOn[] = { 0x90, mNoteKey, mNoteVelocity };
      lv2_event_write(&iter, 0, 0, 1, 3, noteOn);
      noteOffTime = mNoteLength * left->GetRate();
      if (noteOffTime < len && noteOffTime < mBlockSize) {
         uint8_t noteOff[] = { 0x80, mNoteKey, 64 };
         lv2_event_write(&iter, noteOffTime, 0, 1, 3, noteOff);
      }
      slv2_instance_connect_port(handle, mMidiInput->mIndex, midiBuffer);
   }

   unsigned long p;
   for(p = 0; p < mAudioInputs.size(); p++) {
      slv2_instance_connect_port(handle, mAudioInputs[p].mIndex, fInBuffer[p]);
   }
   for(p = 0; p < mAudioOutputs.size(); p++) {
      slv2_instance_connect_port(handle, mAudioOutputs[p].mIndex, fOutBuffer[p]);
   }
   for (p = 0; p < mControlInputs.size(); p++) {
      slv2_instance_connect_port(handle, mControlInputs[p].mIndex, 
                                 &mControlInputs[p].mControlBuffer);
   }
   for (p = 0; p < mControlOutputs.size(); p++) {
      slv2_instance_connect_port(handle, mControlOutputs[p].mIndex, 
                                 &mControlOutputs[p].mControlBuffer);
   }
   
   slv2_instance_activate(handle);

   // Actually perform the effect here

   sampleCount originalLen = len;
   sampleCount ls = lstart;
   sampleCount rs = rstart;
   bool noteOver = false;
   while (len) {
      int block = mBlockSize;
      if (block > len)
         block = len;
      
      if (left &&  mAudioInputs.size() > 0) {
         left->Get((samplePtr)fInBuffer[0], floatSample, ls, block);
      }
      if (right && mAudioInputs.size() > 1) {
         right->Get((samplePtr)fInBuffer[1], floatSample, rs, block);
      }
      
      slv2_instance_run(handle, block);
      
      if (left && mAudioOutputs.size() > 0) {
         left->Set((samplePtr)fOutBuffer[0], floatSample, ls, block);
      }
      
      if (right && mAudioOutputs.size() > 1) {
         right->Set((samplePtr)fOutBuffer[1], floatSample, rs, block);
      }
      
      len -= block;
      noteOffTime -= block;
      ls += block;
      rs += block;
      
      // Clear the event buffer and add the note off event if needed
      if (mMidiInput) {
         lv2_event_buffer_reset(midiBuffer, 1, 
                                (uint8_t*)midiBuffer + 
                                sizeof(LV2_Event_Buffer));
         if (!noteOver && noteOffTime < len && noteOffTime < block) {
            LV2_Event_Iterator iter;
            lv2_event_begin(&iter, midiBuffer);
            uint8_t noteOff[] = { 0x80, mNoteKey, 64 };
            lv2_event_write(&iter, noteOffTime, 0, 1, 3, noteOff);
            noteOver = true;
         }
      }
      
      if (mAudioInputs.size() > 1) {
         if (TrackGroupProgress(count, (ls-lstart)/(double)originalLen))
            return false;
      }
      else {
         if (TrackProgress(count, (ls-lstart)/(double)originalLen))
            return false;
      }
      
   }
   
   slv2_instance_deactivate(handle);
   slv2_instance_free(handle);
   
   return true;
}