/[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 359 by senkov, Sun Feb 6 21:01:38 2005 UTC revision 556 by schoenebeck, Sat May 21 01:10:12 2005 UTC
# Line 3  Line 3 
3   *   LinuxSampler - modular, streaming capable sampler                     *   *   LinuxSampler - modular, streaming capable sampler                     *
4   *                                                                         *   *                                                                         *
5   *   Copyright (C) 2003, 2004 by Benno Senoner and Christian Schoenebeck   *   *   Copyright (C) 2003, 2004 by Benno Senoner and Christian Schoenebeck   *
6     *   Copyright (C) 2005 Christian Schoenebeck                              *
7   *                                                                         *   *                                                                         *
8   *   This program is free software; you can redistribute it and/or modify  *   *   This program is free software; you can redistribute it and/or modify  *
9   *   it under the terms of the GNU General Public License as published by  *   *   it under the terms of the GNU General Public License as published by  *
# Line 24  Line 25 
25    
26  #include "Sampler.h"  #include "Sampler.h"
27    
28    #include "engines/EngineChannelFactory.h"
29  #include "drivers/audio/AudioOutputDeviceFactory.h"  #include "drivers/audio/AudioOutputDeviceFactory.h"
30  #include "drivers/midi/MidiInputDeviceFactory.h"  #include "drivers/midi/MidiInputDeviceFactory.h"
 #include "engines/gig/Engine.h"  
31  #include "network/lscpserver.h"  #include "network/lscpserver.h"
32    
33  namespace LinuxSampler {  namespace LinuxSampler {
# Line 36  namespace LinuxSampler { Line 37  namespace LinuxSampler {
37    
38      SamplerChannel::SamplerChannel(Sampler* pS) {      SamplerChannel::SamplerChannel(Sampler* pS) {
39          pSampler           = pS;          pSampler           = pS;
40          pEngine            = NULL;          pEngineChannel     = NULL;
41          pMidiInputDevice   = NULL;          pMidiInputDevice   = NULL;
42          pAudioOutputDevice = NULL;          pAudioOutputDevice = NULL;
43          midiPort           = 0;          midiPort           = 0;
# Line 45  namespace LinuxSampler { Line 46  namespace LinuxSampler {
46      }      }
47    
48      SamplerChannel::~SamplerChannel() {      SamplerChannel::~SamplerChannel() {
49          if (pEngine) {          if (pEngineChannel) {
50              MidiInputPort* pMidiInputPort = GetMidiInputDevicePort(this->midiPort);              MidiInputPort* pMidiInputPort = GetMidiInputDevicePort(this->midiPort);
51              if (pMidiInputPort) pMidiInputPort->Disconnect(pEngine);              if (pMidiInputPort) pMidiInputPort->Disconnect(pEngineChannel);
52              if (pAudioOutputDevice) pAudioOutputDevice->Disconnect(pEngine);              if (pEngineChannel) {
53              delete pEngine;                  if (pAudioOutputDevice) pEngineChannel->DisconnectAudioOutputDevice();
54                    delete pEngineChannel;
55                }
56          }          }
57      }      }
58    
59      void SamplerChannel::LoadEngine(Engine::type_t EngineType) {      void SamplerChannel::SetEngineType(String EngineType) throw (LinuxSamplerException) {
60          dmsg(2,("SamplerChannel: Loading engine..."));          dmsg(2,("SamplerChannel: Assigning engine type..."));
61    
62          // create new engine          // create new engine channel
63          Engine* pNewEngine = NULL;          EngineChannel* pNewEngineChannel = EngineChannelFactory::Create(EngineType);
64          switch (EngineType) {          if (!pNewEngineChannel) throw LinuxSamplerException("Unknown engine type");
             case Engine::type_gig:  
                 pNewEngine = new gig::Engine;  
                 break;  
             default:  
                 throw LinuxSamplerException("Unknown engine type");  
         }  
65    
66          // dereference midi input port.          // dereference midi input port.
67          MidiInputPort* pMidiInputPort = GetMidiInputDevicePort(this->midiPort);          MidiInputPort* pMidiInputPort = GetMidiInputDevicePort(this->midiPort);
68          // disconnect old engine          // disconnect old engine
69          if (pEngine) {          if (pEngineChannel) {
70              if (pMidiInputPort) pMidiInputPort->Disconnect(pEngine);              if (pMidiInputPort) pMidiInputPort->Disconnect(pEngineChannel);
71              if (pAudioOutputDevice) pAudioOutputDevice->Disconnect(pEngine);              if (pAudioOutputDevice) pEngineChannel->DisconnectAudioOutputDevice();
72              delete pEngine;              delete pEngineChannel;
73          }          }
74    
75          // connect new engine          // connect new engine channel
76          pEngine = pNewEngine;          pEngineChannel = pNewEngineChannel;
77          if (pMidiInputPort) pMidiInputPort->Connect(pNewEngine, this->midiChannel);          if (pMidiInputPort) pMidiInputPort->Connect(pNewEngineChannel, this->midiChannel);
78          if (pAudioOutputDevice) pAudioOutputDevice->Connect(pNewEngine);          if (pAudioOutputDevice) {
79                pNewEngineChannel->Connect(pAudioOutputDevice);
80                pAudioOutputDevice->Connect(pNewEngineChannel->GetEngine());
81            }
82          dmsg(2,("OK\n"));          dmsg(2,("OK\n"));
83      }      }
84    
85      void SamplerChannel::SetAudioOutputDevice(AudioOutputDevice* pDevice) {      void SamplerChannel::SetAudioOutputDevice(AudioOutputDevice* pDevice) {
86          // disconnect old device          // disconnect old device
87          if (pAudioOutputDevice && pEngine) pAudioOutputDevice->Disconnect(pEngine);          if (pAudioOutputDevice && pEngineChannel) pEngineChannel->DisconnectAudioOutputDevice();
88          // connect new device          // connect new device
89          pAudioOutputDevice = pDevice;          pAudioOutputDevice = pDevice;
90          if (pEngine) pAudioOutputDevice->Connect(pEngine);          if (pEngineChannel) {
91                pEngineChannel->Connect(pAudioOutputDevice);
92                pAudioOutputDevice->Connect(pEngineChannel->GetEngine());
93            }
94      }      }
95    
96      void SamplerChannel::SetMidiInputDevice(MidiInputDevice* pDevice) {      void SamplerChannel::SetMidiInputDevice(MidiInputDevice* pDevice) {
# Line 106  namespace LinuxSampler { Line 109  namespace LinuxSampler {
109          // dereference old midi input port.          // dereference old midi input port.
110          MidiInputPort* pMidiInputPort = GetMidiInputDevicePort(this->midiPort);          MidiInputPort* pMidiInputPort = GetMidiInputDevicePort(this->midiPort);
111          // disconnect old device port          // disconnect old device port
112          if (pMidiInputPort && pEngine) pMidiInputPort->Disconnect(pEngine);          if (pMidiInputPort && pEngineChannel) pMidiInputPort->Disconnect(pEngineChannel);
113          // new device, port and channel          // new device, port and channel
114          pMidiInputDevice = pDevice;          pMidiInputDevice = pDevice;
115          this->midiPort = iMidiPort;          this->midiPort = iMidiPort;
116          this->midiChannel = MidiChannel;          this->midiChannel = MidiChannel;
117          // connect new device port          // connect new device port
118          pMidiInputPort = GetMidiInputDevicePort(this->midiPort);          pMidiInputPort = GetMidiInputDevicePort(this->midiPort);
119          if (pMidiInputPort && pEngine) pMidiInputPort->Connect(pEngine, MidiChannel);          if (pMidiInputPort && pEngineChannel) pMidiInputPort->Connect(pEngineChannel, MidiChannel);
120          // Ooops.          // Ooops.
121          if (pMidiInputPort == NULL)          if (pMidiInputPort == NULL)
122              throw LinuxSamplerException("There is no MIDI input port with index " + ToString(iMidiPort) + ".");              throw LinuxSamplerException("There is no MIDI input port with index " + ToString(iMidiPort) + ".");
123      }      }
124    
125      Engine* SamplerChannel::GetEngine() {      EngineChannel* SamplerChannel::GetEngineChannel() {
126          return pEngine;          return pEngineChannel;
127      }      }
128    
129      MidiInputPort::midi_chan_t SamplerChannel::GetMidiInputChannel() {      MidiInputPort::midi_chan_t SamplerChannel::GetMidiInputChannel() {
# Line 182  namespace LinuxSampler { Line 185  namespace LinuxSampler {
185          if (!mSamplerChannels.size()) {          if (!mSamplerChannels.size()) {
186              SamplerChannel* pChannel = new SamplerChannel(this);              SamplerChannel* pChannel = new SamplerChannel(this);
187              mSamplerChannels[0] = pChannel;              mSamplerChannels[0] = pChannel;
188              LSCPServer::SendLSCPNotify(LSCPEvent(LSCPEvent::event_channels, 1));              LSCPServer::SendLSCPNotify(LSCPEvent(LSCPEvent::event_channel_count, 1));
189              return pChannel;              return pChannel;
190          }          }
191    
# Line 197  namespace LinuxSampler { Line 200  namespace LinuxSampler {
200                  // we found an unused index, so insert the new channel there                  // we found an unused index, so insert the new channel there
201                  SamplerChannel* pChannel = new SamplerChannel(this);                  SamplerChannel* pChannel = new SamplerChannel(this);
202                  mSamplerChannels[i] = pChannel;                  mSamplerChannels[i] = pChannel;
203                  LSCPServer::SendLSCPNotify(LSCPEvent(LSCPEvent::event_channels, i));                  LSCPServer::SendLSCPNotify(LSCPEvent(LSCPEvent::event_channel_count, i));
204                  return pChannel;                  return pChannel;
205              }              }
206              throw LinuxSamplerException("Internal error: could not find unoccupied sampler channel index.");              throw LinuxSamplerException("Internal error: could not find unoccupied sampler channel index.");
# Line 206  namespace LinuxSampler { Line 209  namespace LinuxSampler {
209          // we have not reached the index limit so we just add the channel past the highest index          // we have not reached the index limit so we just add the channel past the highest index
210          SamplerChannel* pChannel = new SamplerChannel(this);          SamplerChannel* pChannel = new SamplerChannel(this);
211          mSamplerChannels[lastIndex + 1] = pChannel;          mSamplerChannels[lastIndex + 1] = pChannel;
212          LSCPServer::SendLSCPNotify(LSCPEvent(LSCPEvent::event_channels, lastIndex + 1));          LSCPServer::SendLSCPNotify(LSCPEvent(LSCPEvent::event_channel_count, lastIndex + 1));
213          return pChannel;          return pChannel;
214      }      }
215    
# Line 224  namespace LinuxSampler { Line 227  namespace LinuxSampler {
227              if (iterChan->second == pSamplerChannel) {              if (iterChan->second == pSamplerChannel) {
228                  mSamplerChannels.erase(iterChan);                  mSamplerChannels.erase(iterChan);
229                  delete pSamplerChannel;                  delete pSamplerChannel;
230                  LSCPServer::SendLSCPNotify(LSCPEvent(LSCPEvent::event_channels, mSamplerChannels.size()));                  LSCPServer::SendLSCPNotify(LSCPEvent(LSCPEvent::event_channel_count, mSamplerChannels.size()));
231                  return;                  return;
232              }              }
233          }          }
# Line 313  namespace LinuxSampler { Line 316  namespace LinuxSampler {
316    
317      MidiInputDevice* Sampler::CreateMidiInputDevice(String MidiDriver, std::map<String,String> Parameters) throw (LinuxSamplerException) {      MidiInputDevice* Sampler::CreateMidiInputDevice(String MidiDriver, std::map<String,String> Parameters) throw (LinuxSamplerException) {
318          // create new device          // create new device
319          MidiInputDevice* pDevice = MidiInputDeviceFactory::Create(MidiDriver, Parameters);          MidiInputDevice* pDevice = MidiInputDeviceFactory::Create(MidiDriver, Parameters, this);
320    
321          // add new device to the midi device list          // add new device to the midi device list
322          for (uint i = 0; ; i++) { // seek for a free place starting from the beginning          for (uint i = 0; ; i++) { // seek for a free place starting from the beginning

Legend:
Removed from v.359  
changed lines
  Added in v.556

  ViewVC Help
Powered by ViewVC