/[svn]/linuxsampler/trunk/src/drivers/audio/AudioOutputDeviceJack.cpp
ViewVC logotype

Diff of /linuxsampler/trunk/src/drivers/audio/AudioOutputDeviceJack.cpp

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

revision 227 by schoenebeck, Thu Aug 26 22:05:44 2004 UTC revision 880 by schoenebeck, Tue Jun 27 22:57:37 2006 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, 2006 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 23  Line 24 
24  #include "AudioOutputDeviceJack.h"  #include "AudioOutputDeviceJack.h"
25  #include "AudioOutputDeviceFactory.h"  #include "AudioOutputDeviceFactory.h"
26    
27  #if HAVE_JACK  #include <errno.h>
   
 namespace LinuxSampler {  
28    
29      REGISTER_AUDIO_OUTPUT_DRIVER(AudioOutputDeviceJack);  #if HAVE_JACK
30    
31      /* Common parameters for now they'll have to be registered here. */  #ifndef HAVE_JACK_CLIENT_NAME_SIZE
32      REGISTER_AUDIO_OUTPUT_DRIVER_PARAMETER(AudioOutputDeviceJack, ParameterActive);  #define jack_client_name_size() 33
33      REGISTER_AUDIO_OUTPUT_DRIVER_PARAMETER(AudioOutputDeviceJack, ParameterChannels);  #endif
34    
35    namespace LinuxSampler {
36    
37        /// number of currently existing JACK audio output devices in LinuxSampler
38        static int existingJackDevices = 0;
39    
40  // *************** ParameterName ***************  // *************** AudioChannelJack::ParameterName ***************
41  // *  // *
42    
43      AudioOutputDeviceJack::AudioChannelJack::ParameterName::ParameterName(AudioChannelJack* pChannel) : AudioChannel::ParameterName(ToString(pChannel->ChannelNr)) {      AudioOutputDeviceJack::AudioChannelJack::ParameterName::ParameterName(AudioChannelJack* pChannel) : AudioChannel::ParameterName(ToString(pChannel->ChannelNr)) {
# Line 48  namespace LinuxSampler { Line 50  namespace LinuxSampler {
50    
51    
52    
53  // *************** ParameterJackBindings ***************  // *************** AudioChannelJack::ParameterJackBindings ***************
54  // *  // *
55    
56      AudioOutputDeviceJack::AudioChannelJack::ParameterJackBindings::ParameterJackBindings(AudioChannelJack* pChannel) : DeviceRuntimeParameterStrings(std::vector<String>()) {      AudioOutputDeviceJack::AudioChannelJack::ParameterJackBindings::ParameterJackBindings(AudioChannelJack* pChannel) : DeviceRuntimeParameterStrings(std::vector<String>()) {
# Line 73  namespace LinuxSampler { Line 75  namespace LinuxSampler {
75      }      }
76    
77      void AudioOutputDeviceJack::AudioChannelJack::ParameterJackBindings::OnSetValue(std::vector<String> vS) {      void AudioOutputDeviceJack::AudioChannelJack::ParameterJackBindings::OnSetValue(std::vector<String> vS) {
78          // TODO: we should remove all existing bindings before we connect new ones here          String src_name = ((DeviceCreationParameterString*)pChannel->pDevice->Parameters["NAME"])->ValueAsString() + ":" +
79          String src_name = "LinuxSampler:" + ((DeviceRuntimeParameterString*)pChannel->Parameters["NAME"])->ValueAsString();                            ((DeviceRuntimeParameterString*)pChannel->Parameters["NAME"])->ValueAsString();
80            // disconnect all current bindings first
81            for (int i = 0; i < Bindings.size(); i++) {
82                String dst_name = Bindings[i];
83                int res = jack_disconnect(pChannel->pDevice->hJackClient, src_name.c_str(), dst_name.c_str());
84            }
85            // connect new bindings
86          for (int i = 0; i < vS.size(); i++) {          for (int i = 0; i < vS.size(); i++) {
87              String dst_name = vS[i];              String dst_name = vS[i];
88              int res = jack_connect(pChannel->pDevice->hJackClient, src_name.c_str(), dst_name.c_str());              int res = jack_connect(pChannel->pDevice->hJackClient, src_name.c_str(), dst_name.c_str());
89              if (res == EEXIST) throw AudioOutputException("Jack: Connection to port '" + dst_name + "' already established");              if (res == EEXIST) throw AudioOutputException("Jack: Connection to port '" + dst_name + "' already established");
90              else if (res)      throw AudioOutputException("Jack: Cannot connect port '" + src_name + "' to port '" + dst_name + "'");              else if (res)      throw AudioOutputException("Jack: Cannot connect port '" + src_name + "' to port '" + dst_name + "'");
91          }          }
92            // remember bindings
93            Bindings = vS;
94      }      }
95    
96      String AudioOutputDeviceJack::AudioChannelJack::ParameterJackBindings::Name() {      String AudioOutputDeviceJack::AudioChannelJack::ParameterJackBindings::Name() {
# Line 112  namespace LinuxSampler { Line 122  namespace LinuxSampler {
122    
123    
124    
125    // *************** AudioOutputDeviceJack::ParameterName ***************
126    // *
127    
128        AudioOutputDeviceJack::ParameterName::ParameterName() : DeviceCreationParameterString() {
129            InitWithDefault(); // use default name
130        }
131    
132        AudioOutputDeviceJack::ParameterName::ParameterName(String s) throw (Exception) : DeviceCreationParameterString(s) {
133        }
134    
135        String AudioOutputDeviceJack::ParameterName::Description() {
136            return "Arbitrary JACK client name";
137        }
138    
139        bool AudioOutputDeviceJack::ParameterName::Fix() {
140            return true;
141        }
142    
143        bool AudioOutputDeviceJack::ParameterName::Mandatory() {
144            return false;
145        }
146    
147        std::map<String,DeviceCreationParameter*> AudioOutputDeviceJack::ParameterName::DependsAsParameters() {
148            return std::map<String,DeviceCreationParameter*>(); // no dependencies
149        }
150    
151        std::vector<String> AudioOutputDeviceJack::ParameterName::PossibilitiesAsString(std::map<String,String> Parameters) {
152            return std::vector<String>();
153        }
154    
155        optional<String> AudioOutputDeviceJack::ParameterName::DefaultAsString(std::map<String,String> Parameters) {
156            return (existingJackDevices) ? "LinuxSampler" + ToString(existingJackDevices) : "LinuxSampler";
157        }
158    
159        void AudioOutputDeviceJack::ParameterName::OnSetValue(String s) throw (Exception) {
160            // not possible, as parameter is fix
161        }
162    
163        String AudioOutputDeviceJack::ParameterName::Name() {
164            return "NAME";
165        }
166    
167    
168    
169  // *************** AudioOutputDeviceJack ***************  // *************** AudioOutputDeviceJack ***************
170  // *  // *
171    
# Line 123  namespace LinuxSampler { Line 177  namespace LinuxSampler {
177       * @see AcquireChannels()       * @see AcquireChannels()
178       */       */
179      AudioOutputDeviceJack::AudioOutputDeviceJack(std::map<String,DeviceCreationParameter*> Parameters) : AudioOutputDevice(Parameters) {      AudioOutputDeviceJack::AudioOutputDeviceJack(std::map<String,DeviceCreationParameter*> Parameters) : AudioOutputDevice(Parameters) {
180          if ((hJackClient = jack_client_new("LinuxSampler")) == 0)          if (((DeviceCreationParameterString*)Parameters["NAME"])->ValueAsString().size() >= jack_client_name_size())
181                throw Exception("JACK client name too long");
182    
183            if ((hJackClient = jack_client_new(((DeviceCreationParameterString*)Parameters["NAME"])->ValueAsString().c_str())) == 0)
184              throw AudioOutputException("Seems Jack server not running.");              throw AudioOutputException("Seems Jack server not running.");
185    
186            existingJackDevices++;
187    
188          jack_set_process_callback(hJackClient, __libjack_process_callback, this);          jack_set_process_callback(hJackClient, __libjack_process_callback, this);
189          jack_on_shutdown(hJackClient, __libjack_shutdown_callback, this);          jack_on_shutdown(hJackClient, __libjack_shutdown_callback, this);
190          if (jack_activate(hJackClient))          if (jack_activate(hJackClient))
# Line 143  namespace LinuxSampler { Line 202  namespace LinuxSampler {
202      AudioOutputDeviceJack::~AudioOutputDeviceJack() {      AudioOutputDeviceJack::~AudioOutputDeviceJack() {
203          // destroy jack client          // destroy jack client
204          jack_client_close(hJackClient);          jack_client_close(hJackClient);
205            existingJackDevices--;
206      }      }
207    
208      /**      /**
# Line 165  namespace LinuxSampler { Line 225  namespace LinuxSampler {
225      }      }
226    
227      bool AudioOutputDeviceJack::IsPlaying() {      bool AudioOutputDeviceJack::IsPlaying() {
228          csIsPlaying.GetUnsafe();          return csIsPlaying.GetUnsafe();
229      }      }
230    
231      void AudioOutputDeviceJack::Stop() {      void AudioOutputDeviceJack::Stop() {
# Line 197  namespace LinuxSampler { Line 257  namespace LinuxSampler {
257      }      }
258    
259      String AudioOutputDeviceJack::Version() {      String AudioOutputDeviceJack::Version() {
260         String s = "$Revision: 1.12 $";         String s = "$Revision: 1.20 $";
261         return s.substr(11, s.size() - 13); // cut dollar signs, spaces and CVS macro keyword         return s.substr(11, s.size() - 13); // cut dollar signs, spaces and CVS macro keyword
262      }      }
263    

Legend:
Removed from v.227  
changed lines
  Added in v.880

  ViewVC Help
Powered by ViewVC