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

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

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

revision 1424 by schoenebeck, Sun Oct 14 22:00:17 2007 UTC revision 2513 by schoenebeck, Sun Jan 26 17:59:32 2014 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 - 2007 Christian Schoenebeck                       *   *   Copyright (C) 2005 - 2014 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 35  Line 35 
35  #include "AudioOutputDevice.h"  #include "AudioOutputDevice.h"
36  #include "../../common/ConditionServer.h"  #include "../../common/ConditionServer.h"
37    
38    #if HAVE_JACK_MIDI
39    #include "../midi/MidiInputDeviceJack.h"
40    #endif
41    
42  namespace LinuxSampler {  namespace LinuxSampler {
43        
44        class JackClient;
45        class JackListener;
46    
47      /** JACK audio output driver      /** JACK audio output driver
48       *       *
# Line 58  namespace LinuxSampler { Line 65  namespace LinuxSampler {
65                      class ParameterName : public AudioChannel::ParameterName {                      class ParameterName : public AudioChannel::ParameterName {
66                          public:                          public:
67                              ParameterName(AudioChannelJack* pChannel);                              ParameterName(AudioChannelJack* pChannel);
68                              virtual void OnSetValue(String s);                              virtual void OnSetValue(String s) OVERRIDE;
69                          protected:                          protected:
70                              AudioChannelJack* pChannel;                              AudioChannelJack* pChannel;
71                      };                      };
# Line 70  namespace LinuxSampler { Line 77  namespace LinuxSampler {
77                      class ParameterJackBindings : public DeviceRuntimeParameterStrings {                      class ParameterJackBindings : public DeviceRuntimeParameterStrings {
78                          public:                          public:
79                              ParameterJackBindings(AudioChannelJack* pChannel);                              ParameterJackBindings(AudioChannelJack* pChannel);
80                              virtual String              Description();                              virtual String              Description() OVERRIDE;
81                              virtual bool                Fix();                              virtual bool                Fix() OVERRIDE;
82                              virtual std::vector<String> PossibilitiesAsString();                              virtual std::vector<String> PossibilitiesAsString() OVERRIDE;
83                              virtual void                OnSetValue(std::vector<String> vS);                              virtual void                OnSetValue(std::vector<String> vS) OVERRIDE;
84                              static String Name();                              static String Name();
85                          protected:                          protected:
86                              AudioChannelJack*   pChannel;                              AudioChannelJack*   pChannel;
# Line 82  namespace LinuxSampler { Line 89  namespace LinuxSampler {
89                  protected:                  protected:
90                      AudioChannelJack(uint ChannelNr, AudioOutputDeviceJack* pDevice) throw (AudioOutputException);                      AudioChannelJack(uint ChannelNr, AudioOutputDeviceJack* pDevice) throw (AudioOutputException);
91                      ~AudioChannelJack();                      ~AudioChannelJack();
92                        void UpdateJackBuffer(uint size);
93                      friend class AudioOutputDeviceJack;                      friend class AudioOutputDeviceJack;
94                  private:                  private:
95                      AudioOutputDeviceJack* pDevice;                      AudioOutputDeviceJack* pDevice;
# Line 100  namespace LinuxSampler { Line 108  namespace LinuxSampler {
108                  public:                  public:
109                      ParameterName();                      ParameterName();
110                      ParameterName(String s) throw (Exception);                      ParameterName(String s) throw (Exception);
111                      virtual String              Description();                      virtual String              Description() OVERRIDE;
112                      virtual bool                Fix();                      virtual bool                Fix() OVERRIDE;
113                      virtual bool                Mandatory();                      virtual bool                Mandatory() OVERRIDE;
114                      virtual std::map<String,DeviceCreationParameter*> DependsAsParameters();                      virtual std::map<String,DeviceCreationParameter*> DependsAsParameters() OVERRIDE;
115                      virtual std::vector<String> PossibilitiesAsString(std::map<String,String> Parameters);                      virtual std::vector<String> PossibilitiesAsString(std::map<String,String> Parameters) OVERRIDE;
116                      virtual optional<String>    DefaultAsString(std::map<String,String> Parameters);                      virtual optional<String>    DefaultAsString(std::map<String,String> Parameters) OVERRIDE;
117                      virtual void                OnSetValue(String s) throw (Exception);                      virtual void                OnSetValue(String s) throw (Exception) OVERRIDE;
118                      static String Name();                      static String Name();
119              };              };
120    
121              // derived abstract methods from class 'AudioOutputDevice'              /** Audio Device Parameter 'SAMPLERATE'
122              virtual void Play();               *
123              virtual bool IsPlaying();               * Used to retrieve the sample rate of the JACK audio output
124              virtual void Stop();               * device. Even though the sample rate of the JACK server might
125              virtual uint MaxSamplesPerCycle();               * change during runtime, the JACK API currently however does not
126              virtual uint SampleRate();               * allow clients to change the sample rate. So this parameter is
127              virtual AudioChannel* CreateChannel(uint ChannelNr);               * read only.
128                 *
129                 * This base parameter class has just been overridden for this JACK
130              static String Name();               * driver to implement a valid default value for sample rate. The
131                 * default value will simply return the sample rate of the currently
132                 * running JACK server. It will return "nothing" if the JACK server
133                 * is not running at that point.
134                 */
135                class ParameterSampleRate : public AudioOutputDevice::ParameterSampleRate {
136                    public:
137                        ParameterSampleRate();
138                        ParameterSampleRate(String s);
139                        virtual optional<int> DefaultAsInt(std::map<String,String> Parameters) OVERRIDE;
140                        virtual void OnSetValue(int i) throw (Exception) OVERRIDE;
141                };
142    
143              virtual String Driver();              // derived abstract methods from class 'AudioOutputDevice'
144                virtual void Play() OVERRIDE;
145                virtual bool IsPlaying() OVERRIDE;
146                virtual void Stop() OVERRIDE;
147                virtual uint MaxSamplesPerCycle() OVERRIDE;
148                virtual uint SampleRate() OVERRIDE;
149                virtual AudioChannel* CreateChannel(uint ChannelNr) OVERRIDE;
150                virtual String Driver() OVERRIDE;
151                virtual float latency() OVERRIDE;
152                
153                static String Name();
154    
155              static String Description();              static String Description();
156              static String Version();              static String Version();
157    
158              int Process(uint Samples);  // FIXME: should be private              int Process(uint Samples);  // FIXME: should be private
159                void UpdateJackBuffers(uint size);
160                void addListener(JackListener* listener);
161                jack_client_t* jackClientHandle();
162          protected:          protected:
163              AudioOutputDeviceJack(String* AutoConnectPortIDs = NULL, uint AutoConnectPorts = 0);              AudioOutputDeviceJack(String* AutoConnectPortIDs = NULL, uint AutoConnectPorts = 0);
164          private:          private:
165              ConditionServer csIsPlaying;              ConditionServer csIsPlaying;
166              uint            uiMaxSamplesPerCycle;              uint            uiMaxSamplesPerCycle;
167              jack_client_t*  hJackClient;              jack_client_t*  hJackClient;
168                JackClient* pJackClient;
169      };      };
170    
171      // Callback functions for the libjack API      // Callback functions for the libjack API
172      int  __libjack_process_callback(jack_nframes_t nframes, void* arg);      int  linuxsampler_libjack_process_callback(jack_nframes_t nframes, void* arg);
173      void __libjack_shutdown_callback(void* arg);  
174        /** JACK client
175         *
176         * Represents a jack client. This class is shared by
177         * AudioOutputDeviceJack and MidiInputDeviceJack. The jack server
178         * calls JackClient::Process, which in turn calls
179         * AudioOutputDeviceJack::Process and/or
180         * MidiInputDeviceJack::Process.
181         */
182        class JackClient {
183            public:
184                static JackClient* CreateAudio(String Name);
185                static JackClient* CreateMidi(String Name);
186                static void ReleaseAudio(String Name);
187                static void ReleaseMidi(String Name);
188                int Process(uint Samples);
189                void Stop();
190                void SetAudioOutputDevice(AudioOutputDeviceJack* device);
191                #if HAVE_JACK_MIDI
192                void SetMidiInputDevice(MidiInputDeviceJack* device);
193                #endif
194                void addListener(JackListener* listener);
195    
196                jack_client_t* hJackClient;
197    
198            private:
199                std::vector<JackListener*> jackListeners;
200                static std::map<String, JackClient*> Clients;
201                struct config_t {
202                    AudioOutputDeviceJack* AudioDevice;
203                    #if HAVE_JACK_MIDI
204                    MidiInputDeviceJack* MidiDevice;
205                    #endif
206                };
207                SynchronizedConfig<config_t> Config;
208                SynchronizedConfig<config_t>::Reader ConfigReader;
209                bool audio;
210                bool midi;
211    
212                JackClient(String Name);
213                ~JackClient();
214            
215                // Callback functions for the libjack API
216    #if HAVE_JACK_ON_INFO_SHUTDOWN
217                static void libjackShutdownCallback(jack_status_t code, const char* reason, void *arg);
218    #else
219                static void libjackShutdownCallback(void *arg);
220    #endif
221                static int libjackSampleRateCallback(jack_nframes_t nframes, void *arg);
222                static int libjackBufferSizeCallback(jack_nframes_t nframes, void *arg);
223        };
224        
225        /**
226         * Currently not derived / instantiated by the sampler itself, however this
227         * class can be subclassed and used i.e. by a GUI build on top of the sampler,
228         * to react on JACK events. Because registering JACK callback functions through
229         * the general JACK API is not possible after the JACK client has been activated,
230         * and the latter is already the case as soon as an AudioOutputDeviceJack object
231         * has been instantiated.
232         */
233        class JackListener {
234        public:
235            virtual void onJackShutdown(jack_status_t code, const char* reason) = 0;
236        };
237  }  }
238    
239  #endif // HAVE_JACK  #endif // HAVE_JACK

Legend:
Removed from v.1424  
changed lines
  Added in v.2513

  ViewVC Help
Powered by ViewVC