/[svn]/linuxsampler/trunk/src/Sampler.cpp
ViewVC logotype

Diff of /linuxsampler/trunk/src/Sampler.cpp

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

revision 158 by senkov, Mon Jun 28 04:30:11 2004 UTC revision 159 by capela, Tue Jun 29 21:11:50 2004 UTC
# Line 36  namespace LinuxSampler { Line 36  namespace LinuxSampler {
36      SamplerChannel::SamplerChannel(Sampler* pS) {      SamplerChannel::SamplerChannel(Sampler* pS) {
37          pSampler           = pS;          pSampler           = pS;
38          pEngine            = NULL;          pEngine            = NULL;
39          pMidiInputPort     = NULL;          pMidiInputDevice   = NULL;
40          pAudioOutputDevice = NULL;          pAudioOutputDevice = NULL;
41            midiPort           = 0;
42            midiChannel        = MidiInputDevice::MidiInputPort::midi_chan_all;
43          iIndex             = -1;          iIndex             = -1;
         midiChannel        = MidiInputDevice::MidiInputPort::midi_chan_all;  
44      }      }
45    
46      SamplerChannel::~SamplerChannel() {      SamplerChannel::~SamplerChannel() {
47          if (pEngine) {          if (pEngine) {
48                MidiInputDevice::MidiInputPort *pMidiInputPort = GetMidiInputDevicePort(this->midiPort);
49              if (pMidiInputPort) pMidiInputPort->Disconnect(pEngine);              if (pMidiInputPort) pMidiInputPort->Disconnect(pEngine);
50              if (pAudioOutputDevice) pAudioOutputDevice->Disconnect(pEngine);              if (pAudioOutputDevice) pAudioOutputDevice->Disconnect(pEngine);
51              delete pEngine;              delete pEngine;
# Line 63  namespace LinuxSampler { Line 65  namespace LinuxSampler {
65                  throw LinuxSamplerException("Unknown engine type");                  throw LinuxSamplerException("Unknown engine type");
66          }          }
67    
68            // dereference midi input port.
69            MidiInputDevice::MidiInputPort *pMidiInputPort = GetMidiInputDevicePort(this->midiPort);
70          // disconnect old engine          // disconnect old engine
71          if (pEngine) {          if (pEngine) {
72              if (pMidiInputPort) pMidiInputPort->Disconnect(pEngine);              if (pMidiInputPort) pMidiInputPort->Disconnect(pEngine);
# Line 72  namespace LinuxSampler { Line 76  namespace LinuxSampler {
76    
77          // connect new engine          // connect new engine
78          pEngine = pNewEngine;          pEngine = pNewEngine;
79          if (pMidiInputPort) pMidiInputPort->Connect(pNewEngine, (MidiInputDevice::MidiInputPort::midi_chan_t) Index());          if (pMidiInputPort) pMidiInputPort->Connect(pNewEngine, this->midiChannel);
80          if (pAudioOutputDevice) pAudioOutputDevice->Connect(pNewEngine);          if (pAudioOutputDevice) pAudioOutputDevice->Connect(pNewEngine);
81          dmsg(2,("OK\n"));          dmsg(2,("OK\n"));
82      }      }
# Line 80  namespace LinuxSampler { Line 84  namespace LinuxSampler {
84      void SamplerChannel::SetAudioOutputDevice(AudioOutputDevice* pDevice) {      void SamplerChannel::SetAudioOutputDevice(AudioOutputDevice* pDevice) {
85          // disconnect old device          // disconnect old device
86          if (pAudioOutputDevice && pEngine) pAudioOutputDevice->Disconnect(pEngine);          if (pAudioOutputDevice && pEngine) pAudioOutputDevice->Disconnect(pEngine);
   
87          // connect new device          // connect new device
88          pAudioOutputDevice = pDevice;          pAudioOutputDevice = pDevice;
89          if (pEngine) pAudioOutputDevice->Connect(pEngine);          if (pEngine) pAudioOutputDevice->Connect(pEngine);
90      }      }
91    
92      void SamplerChannel::SetMidiInputPort(MidiInputDevice* pDevice, int midiPort, MidiInputDevice::MidiInputPort::midi_chan_t MidiChannel) {      void SamplerChannel::SetMidiInputDevice(MidiInputDevice* pDevice) {
93          // disconnect old port         SetMidiInput(pDevice, this->midiPort, this->midiChannel);
94        }
95        
96        void SamplerChannel::SetMidiInputPort(int MidiPort) {
97           SetMidiInput(pMidiInputDevice, MidiPort, this->midiChannel);
98        }
99        
100        void SamplerChannel::SetMidiInputChannel(MidiInputDevice::MidiInputPort::midi_chan_t MidiChannel) {
101           SetMidiInput(pMidiInputDevice, this->midiPort, MidiChannel);
102        }
103        
104        void SamplerChannel::SetMidiInput(MidiInputDevice* pDevice, int MidiPort, MidiInputDevice::MidiInputPort::midi_chan_t MidiChannel) {
105            // dereference old midi input port.
106            MidiInputDevice::MidiInputPort *pMidiInputPort = GetMidiInputDevicePort(this->midiPort);
107            // disconnect old device port
108          if (pMidiInputPort && pEngine) pMidiInputPort->Disconnect(pEngine);          if (pMidiInputPort && pEngine) pMidiInputPort->Disconnect(pEngine);
109            // new device, port and channel
110          // connect new port          pMidiInputDevice = pDevice;
111          pMidiInputPort = pDevice->GetPort(midiPort);          this->midiPort = MidiPort;
112          if (!pMidiInputPort)          this->midiChannel = MidiChannel;
113                  throw LinuxSamplerException("MIDI port doesn't exist");          // connect new device port
114          if (pEngine) {          pMidiInputPort = GetMidiInputDevicePort(this->midiPort);
115                  pMidiInputPort->Connect(pEngine, MidiChannel);          if (pMidiInputPort && pEngine) pMidiInputPort->Connect(pEngine, MidiChannel);
116                  this->midiChannel = MidiChannel;          // Ooops.
117          }          if (pMidiInputPort == NULL)
118                throw LinuxSamplerException("There is no MIDI input port with index " + ToString(MidiPort) + ".");
119      }      }
120    
121      Engine* SamplerChannel::GetEngine() {      Engine* SamplerChannel::GetEngine() {
122          return pEngine;          return pEngine;
123      }      }
124    
125      MidiInputDevice::MidiInputPort* SamplerChannel::GetMidiInputPort() {      MidiInputDevice::MidiInputPort::midi_chan_t SamplerChannel::GetMidiInputChannel() {
126          return pMidiInputPort;          return this->midiChannel;
127        }
128    
129        int SamplerChannel::GetMidiInputPort() {
130            MidiInputDevice::MidiInputPort *pMidiInputPort = GetMidiInputDevicePort(this->midiPort);
131            return (pMidiInputPort ? (int) pMidiInputPort->GetPortNumber() : -1);
132      }      }
133    
134      AudioOutputDevice* SamplerChannel::GetAudioOutputDevice() {      AudioOutputDevice* SamplerChannel::GetAudioOutputDevice() {
# Line 113  namespace LinuxSampler { Line 136  namespace LinuxSampler {
136      }      }
137    
138      MidiInputDevice* SamplerChannel::GetMidiInputDevice() {      MidiInputDevice* SamplerChannel::GetMidiInputDevice() {
139          MidiInputDevice::MidiInputPort* port = GetMidiInputPort();          return pMidiInputDevice;
         if (!port)  
                 return NULL;  
         return port->GetDevice();  
140      }      }
141    
142      uint SamplerChannel::Index() {      uint SamplerChannel::Index() {
# Line 133  namespace LinuxSampler { Line 153  namespace LinuxSampler {
153          throw LinuxSamplerException("SamplerChannel index not found");          throw LinuxSamplerException("SamplerChannel index not found");
154      }      }
155    
156        MidiInputDevice::MidiInputPort* SamplerChannel::GetMidiInputDevicePort(int MidiPort) {
157            MidiInputDevice::MidiInputPort *pMidiInputPort = NULL;
158            if (pMidiInputDevice)
159                pMidiInputPort = pMidiInputDevice->GetPort(MidiPort);
160            return pMidiInputPort;
161        }
162    
163      // ******************************************************************      // ******************************************************************
164      // * Sampler      // * Sampler

Legend:
Removed from v.158  
changed lines
  Added in v.159

  ViewVC Help
Powered by ViewVC