/[svn]/linuxsampler/trunk/src/engines/gig/EngineChannel.cpp
ViewVC logotype

Diff of /linuxsampler/trunk/src/engines/gig/EngineChannel.cpp

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1653 by schoenebeck, Wed Jan 30 01:51:46 2008 UTC revision 1723 by schoenebeck, Sun Apr 20 08:53:39 2008 UTC
# Line 28  Line 28 
28  namespace LinuxSampler { namespace gig {  namespace LinuxSampler { namespace gig {
29    
30      EngineChannel::EngineChannel() :      EngineChannel::EngineChannel() :
31          InstrumentChangeCommandReader(InstrumentChangeCommand) {          InstrumentChangeCommandReader(InstrumentChangeCommand),
32            virtualMidiDevicesReader_AudioThread(virtualMidiDevices),
33            virtualMidiDevicesReader_MidiThread(virtualMidiDevices)
34        {
35          pMIDIKeyInfo = new midi_key_info_t[128];          pMIDIKeyInfo = new midi_key_info_t[128];
36          pEngine      = NULL;          pEngine      = NULL;
37          pInstrument  = NULL;          pInstrument  = NULL;
# Line 508  namespace LinuxSampler { namespace gig { Line 511  namespace LinuxSampler { namespace gig {
511              event.pEngineChannel      = this;              event.pEngineChannel      = this;
512              if (this->pEventQueue->write_space() > 0) this->pEventQueue->push(&event);              if (this->pEventQueue->write_space() > 0) this->pEventQueue->push(&event);
513              else dmsg(1,("EngineChannel: Input event queue full!"));              else dmsg(1,("EngineChannel: Input event queue full!"));
514              // inform instrument editor(s), if any ...              // inform connected virtual MIDI devices if any ...
515              pEngine->instruments.TrySendNoteOnToEditors(Key, Velocity, pInstrument);              // (e.g. virtual MIDI keyboard in instrument editor(s))
516                ArrayList<VirtualMidiDevice*>& devices =
517                    const_cast<ArrayList<VirtualMidiDevice*>&>(
518                        virtualMidiDevicesReader_MidiThread.Lock()
519                    );
520                for (int i = 0; i < devices.size(); i++) {
521                    devices[i]->SendNoteOnToDevice(Key, Velocity);
522                }
523                virtualMidiDevicesReader_MidiThread.Unlock();
524          }          }
525      }      }
526    
# Line 536  namespace LinuxSampler { namespace gig { Line 547  namespace LinuxSampler { namespace gig {
547              event.pEngineChannel      = this;              event.pEngineChannel      = this;
548              if (this->pEventQueue->write_space() > 0) this->pEventQueue->push(&event);              if (this->pEventQueue->write_space() > 0) this->pEventQueue->push(&event);
549              else dmsg(1,("EngineChannel: Input event queue full!"));              else dmsg(1,("EngineChannel: Input event queue full!"));
550              // inform instrument editor(s), if any ...              // inform connected virtual MIDI devices if any ...
551              pEngine->instruments.TrySendNoteOnToEditors(Key, Velocity, pInstrument);              // (e.g. virtual MIDI keyboard in instrument editor(s))
552                ArrayList<VirtualMidiDevice*>& devices =
553                    const_cast<ArrayList<VirtualMidiDevice*>&>(
554                        virtualMidiDevicesReader_MidiThread.Lock()
555                    );
556                for (int i = 0; i < devices.size(); i++) {
557                    devices[i]->SendNoteOnToDevice(Key, Velocity);
558                }
559                virtualMidiDevicesReader_MidiThread.Unlock();
560          }          }
561      }      }
562    
# Line 559  namespace LinuxSampler { namespace gig { Line 578  namespace LinuxSampler { namespace gig {
578              event.pEngineChannel      = this;              event.pEngineChannel      = this;
579              if (this->pEventQueue->write_space() > 0) this->pEventQueue->push(&event);              if (this->pEventQueue->write_space() > 0) this->pEventQueue->push(&event);
580              else dmsg(1,("EngineChannel: Input event queue full!"));              else dmsg(1,("EngineChannel: Input event queue full!"));
581              // inform instrument editor(s), if any ...              // inform connected virtual MIDI devices if any ...
582              pEngine->instruments.TrySendNoteOffToEditors(Key, Velocity, pInstrument);              // (e.g. virtual MIDI keyboard in instrument editor(s))
583                ArrayList<VirtualMidiDevice*>& devices =
584                    const_cast<ArrayList<VirtualMidiDevice*>&>(
585                        virtualMidiDevicesReader_MidiThread.Lock()
586                    );
587                for (int i = 0; i < devices.size(); i++) {
588                    devices[i]->SendNoteOffToDevice(Key, Velocity);
589                }
590                virtualMidiDevicesReader_MidiThread.Unlock();
591          }          }
592      }      }
593    
# Line 587  namespace LinuxSampler { namespace gig { Line 614  namespace LinuxSampler { namespace gig {
614              event.pEngineChannel      = this;              event.pEngineChannel      = this;
615              if (this->pEventQueue->write_space() > 0) this->pEventQueue->push(&event);              if (this->pEventQueue->write_space() > 0) this->pEventQueue->push(&event);
616              else dmsg(1,("EngineChannel: Input event queue full!"));              else dmsg(1,("EngineChannel: Input event queue full!"));
617              // inform instrument editor(s), if any ...              // inform connected virtual MIDI devices if any ...
618              pEngine->instruments.TrySendNoteOffToEditors(Key, Velocity, pInstrument);              // (e.g. virtual MIDI keyboard in instrument editor(s))
619                ArrayList<VirtualMidiDevice*>& devices =
620                    const_cast<ArrayList<VirtualMidiDevice*>&>(
621                        virtualMidiDevicesReader_MidiThread.Lock()
622                    );
623                for (int i = 0; i < devices.size(); i++) {
624                    devices[i]->SendNoteOffToDevice(Key, Velocity);
625                }
626                virtualMidiDevicesReader_MidiThread.Unlock();
627          }          }
628      }      }
629    
# Line 702  namespace LinuxSampler { namespace gig { Line 737  namespace LinuxSampler { namespace gig {
737          MidiVolume     = 1.0;          MidiVolume     = 1.0;
738          GlobalPanLeft  = 1.0f;          GlobalPanLeft  = 1.0f;
739          GlobalPanRight = 1.0f;          GlobalPanRight = 1.0f;
740            iLastPanRequest = 64;
741          GlobalTranspose = 0;          GlobalTranspose = 0;
742          // set all MIDI controller values to zero          // set all MIDI controller values to zero
743          memset(ControllerTable, 0x00, 129);          memset(ControllerTable, 0x00, 129);
# Line 728  namespace LinuxSampler { namespace gig { Line 764  namespace LinuxSampler { namespace gig {
764       *                  current audio cycle       *                  current audio cycle
765       */       */
766      void EngineChannel::ImportEvents(uint Samples) {      void EngineChannel::ImportEvents(uint Samples) {
767            // import events from pure software MIDI "devices"
768            // (e.g. virtual keyboard in instrument editor)
769            {
770                const int FragmentPos = 0; // randomly chosen, we don't care about jitter for virtual MIDI devices
771                Event event = pEngine->pEventGenerator->CreateEvent(FragmentPos);
772                VirtualMidiDevice::event_t devEvent; // the event format we get from the virtual MIDI device
773                // as we're going to (carefully) write some status to the
774                // synchronized struct, we cast away the const
775                ArrayList<VirtualMidiDevice*>& devices =
776                    const_cast<ArrayList<VirtualMidiDevice*>&>(virtualMidiDevicesReader_AudioThread.Lock());
777                // iterate through all virtual MIDI devices
778                for (int i = 0; i < devices.size(); i++) {
779                    VirtualMidiDevice* pDev = devices[i];
780                    // I think we can simply flush the whole FIFO(s), the user shouldn't be so fast ;-)
781                    while (pDev->GetMidiEventFromDevice(devEvent)) {
782                        event.Type =
783                            (devEvent.Type == VirtualMidiDevice::EVENT_TYPE_NOTEON) ?
784                                Event::type_note_on : Event::type_note_off;
785                        event.Param.Note.Key      = devEvent.Key;
786                        event.Param.Note.Velocity = devEvent.Velocity;
787                        event.pEngineChannel      = this;
788                        // copy event to internal event list
789                        if (pEvents->poolIsEmpty()) {
790                            dmsg(1,("Event pool emtpy!\n"));
791                            goto exitVirtualDevicesLoop;
792                        }
793                        *pEvents->allocAppend() = event;
794                    }
795                }
796            }
797            exitVirtualDevicesLoop:
798            virtualMidiDevicesReader_AudioThread.Unlock();
799    
800            // import events from the regular MIDI devices
801          RingBuffer<Event,false>::NonVolatileReader eventQueueReader = pEventQueue->get_non_volatile_reader();          RingBuffer<Event,false>::NonVolatileReader eventQueueReader = pEventQueue->get_non_volatile_reader();
802          Event* pEvent;          Event* pEvent;
803          while (true) {          while (true) {
# Line 773  namespace LinuxSampler { namespace gig { Line 843  namespace LinuxSampler { namespace gig {
843          if (pEngine) pEngine->Enable();          if (pEngine) pEngine->Enable();
844      }      }
845    
846        void EngineChannel::Connect(VirtualMidiDevice* pDevice) {
847            // double buffer ... double work ...
848            {
849                ArrayList<VirtualMidiDevice*>& devices = virtualMidiDevices.GetConfigForUpdate();
850                devices.add(pDevice);
851            }
852            {
853                ArrayList<VirtualMidiDevice*>& devices = virtualMidiDevices.SwitchConfig();
854                devices.add(pDevice);
855            }
856        }
857    
858        void EngineChannel::Disconnect(VirtualMidiDevice* pDevice) {
859            // double buffer ... double work ...
860            {
861                ArrayList<VirtualMidiDevice*>& devices = virtualMidiDevices.GetConfigForUpdate();
862                devices.remove(pDevice);
863            }
864            {
865                ArrayList<VirtualMidiDevice*>& devices = virtualMidiDevices.SwitchConfig();
866                devices.remove(pDevice);
867            }
868        }
869    
870      float EngineChannel::Volume() {      float EngineChannel::Volume() {
871          return GlobalVolume;          return GlobalVolume;
872      }      }
# Line 782  namespace LinuxSampler { namespace gig { Line 876  namespace LinuxSampler { namespace gig {
876          bStatusChanged = true; // status of engine channel has changed, so set notify flag          bStatusChanged = true; // status of engine channel has changed, so set notify flag
877      }      }
878    
879        float EngineChannel::Pan() {
880            return float(iLastPanRequest - 64) / 64.0f;
881        }
882    
883        void EngineChannel::Pan(float f) {
884            int iMidiPan = int(f * 64.0f) + 64;
885            if (iMidiPan > 127) iMidiPan = 127;
886            else if (iMidiPan < 0) iMidiPan = 0;
887            GlobalPanLeft  = Engine::PanCurve[128 - iMidiPan];
888            GlobalPanRight = Engine::PanCurve[iMidiPan];
889            iLastPanRequest = iMidiPan;
890        }
891    
892      uint EngineChannel::Channels() {      uint EngineChannel::Channels() {
893          return 2;          return 2;
894      }      }

Legend:
Removed from v.1653  
changed lines
  Added in v.1723

  ViewVC Help
Powered by ViewVC