/[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 200 by schoenebeck, Tue Jul 13 22:04:16 2004 UTC revision 2444 by schoenebeck, Tue Apr 23 12:19:57 2013 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 - 2013 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  #ifndef __LS_AUDIOOUTPUTDEVICEJACK_H__  #ifndef __LS_AUDIOOUTPUTDEVICEJACK_H__
25  #define __LS_AUDIOOUTPUTDEVICEJACK_H__  #define __LS_AUDIOOUTPUTDEVICEJACK_H__
26    
27  #include "../../common/global.h"  #include "../../common/global_private.h"
28    
29  #if HAVE_JACK  #if HAVE_JACK
30    
# Line 34  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 43  namespace LinuxSampler { Line 51  namespace LinuxSampler {
51      class AudioOutputDeviceJack : public AudioOutputDevice {      class AudioOutputDeviceJack : public AudioOutputDevice {
52          public:          public:
53              AudioOutputDeviceJack(std::map<String,DeviceCreationParameter*> Parameters);              AudioOutputDeviceJack(std::map<String,DeviceCreationParameter*> Parameters);
54              ~AudioOutputDeviceJack();              virtual ~AudioOutputDeviceJack();
55    
56              // Audio channel parameter to connect to other Jack clients              /**
57              class ParameterJackBindings : public DeviceRuntimeParameterStrings {               * Audio channel implementation for the JACK audio driver.
58                 */
59                class AudioChannelJack : public AudioChannel {
60                  public:                  public:
61                      ParameterJackBindings(AudioChannel* pChannel, std::vector<String> InitialBindings) : DeviceRuntimeParameterStrings(InitialBindings) { this->pChannel = pChannel; }                      /** Audio Channel Parameter 'NAME'
62                      virtual String              Description()                      { return "Bindings to other JACK clients";                     }                       *
63                      virtual bool                Fix()                              { return false;                                                }                       * Used to assign an arbitrary name to an audio channel.
64                      virtual std::vector<String> PossibilitiesAsString()            { return std::vector<String>(); /* TODO: to be implemented */  }                       */
65                      virtual void                OnSetValue(std::vector<String> vS) { /* TODO: code to connect to other jack clients */            }                      class ParameterName : public AudioChannel::ParameterName {
66                            public:
67                                ParameterName(AudioChannelJack* pChannel);
68                                virtual void OnSetValue(String s) OVERRIDE;
69                            protected:
70                                AudioChannelJack* pChannel;
71                        };
72    
73                        /** Audio Channel Parameter 'JACK_BINDINGS'
74                         *
75                         * Used to connect to other JACK clients.
76                         */
77                        class ParameterJackBindings : public DeviceRuntimeParameterStrings {
78                            public:
79                                ParameterJackBindings(AudioChannelJack* pChannel);
80                                virtual String              Description() OVERRIDE;
81                                virtual bool                Fix() OVERRIDE;
82                                virtual std::vector<String> PossibilitiesAsString() OVERRIDE;
83                                virtual void                OnSetValue(std::vector<String> vS) OVERRIDE;
84                                static String Name();
85                            protected:
86                                AudioChannelJack*   pChannel;
87                                std::vector<String> Bindings;
88                        };
89                  protected:                  protected:
90                      AudioChannel* pChannel;                      AudioChannelJack(uint ChannelNr, AudioOutputDeviceJack* pDevice) throw (AudioOutputException);
91              };                      ~AudioChannelJack();
92                        void UpdateJackBuffer(uint size);
93                        friend class AudioOutputDeviceJack;
94                    private:
95                        AudioOutputDeviceJack* pDevice;
96                        jack_port_t*           hJackPort;
97                        uint                   ChannelNr;
98    
99              // derived abstract methods from class 'AudioOutputDevice'                      float* CreateJackPort(uint ChannelNr, AudioOutputDeviceJack* pDevice) throw (AudioOutputException);
100              virtual void Play();              };
             virtual bool IsPlaying();  
             virtual void Stop();  
             virtual void AcquireChannels(uint uiChannels);  
             virtual uint MaxSamplesPerCycle();  
             virtual uint SampleRate();  
101    
102              static String Name();              /** Audio Device Parameter 'NAME'
103                 *
104                 * Used to assign an arbitrary name to the JACK client of this
105                 * audio device.
106                 */
107                class ParameterName : public DeviceCreationParameterString {
108                    public:
109                        ParameterName();
110                        ParameterName(String s) throw (Exception);
111                        virtual String              Description() OVERRIDE;
112                        virtual bool                Fix() OVERRIDE;
113                        virtual bool                Mandatory() OVERRIDE;
114                        virtual std::map<String,DeviceCreationParameter*> DependsAsParameters() OVERRIDE;
115                        virtual std::vector<String> PossibilitiesAsString(std::map<String,String> Parameters) OVERRIDE;
116                        virtual optional<String>    DefaultAsString(std::map<String,String> Parameters) OVERRIDE;
117                        virtual void                OnSetValue(String s) throw (Exception) OVERRIDE;
118                        static String Name();
119                };
120    
121              virtual String Driver();              // derived abstract methods from class 'AudioOutputDevice'
122                virtual void Play() OVERRIDE;
123                virtual bool IsPlaying() OVERRIDE;
124                virtual void Stop() OVERRIDE;
125                virtual uint MaxSamplesPerCycle() OVERRIDE;
126                virtual uint SampleRate() OVERRIDE;
127                virtual AudioChannel* CreateChannel(uint ChannelNr) OVERRIDE;
128                virtual String Driver() OVERRIDE;
129                virtual float latency() OVERRIDE;
130                
131                static String Name();
132    
133              static String Description();              static String Description();
134              static String Version();              static String Version();
             static std::map<String,DeviceCreationParameter*> AvailableParameters();  
135    
136              int Process(uint Samples);  // FIXME: should be private              int Process(uint Samples);  // FIXME: should be private
137                void UpdateJackBuffers(uint size);
138                void addListener(JackListener* listener);
139                jack_client_t* jackClientHandle();
140          protected:          protected:
141              AudioOutputDeviceJack(String* AutoConnectPortIDs = NULL, uint AutoConnectPorts = 0);              AudioOutputDeviceJack(String* AutoConnectPortIDs = NULL, uint AutoConnectPorts = 0);
142          private:          private:
143              ConditionServer           csIsPlaying;              ConditionServer csIsPlaying;
144              uint                      uiMaxSamplesPerCycle;              uint            uiMaxSamplesPerCycle;
145              jack_client_t*            hJackClient;              jack_client_t*  hJackClient;
146              std::vector<jack_port_t*> hJackPorts;              JackClient* pJackClient;
147      };      };
148    
149      // Callback functions for the libjack API      // Callback functions for the libjack API
150      int  __libjack_process_callback(jack_nframes_t nframes, void* arg);      int  linuxsampler_libjack_process_callback(jack_nframes_t nframes, void* arg);
151      void __libjack_shutdown_callback(void* arg);  
152        /** JACK client
153         *
154         * Represents a jack client. This class is shared by
155         * AudioOutputDeviceJack and MidiInputDeviceJack. The jack server
156         * calls JackClient::Process, which in turn calls
157         * AudioOutputDeviceJack::Process and/or
158         * MidiInputDeviceJack::Process.
159         */
160        class JackClient {
161            public:
162                static JackClient* CreateAudio(String Name);
163                static JackClient* CreateMidi(String Name);
164                static void ReleaseAudio(String Name);
165                static void ReleaseMidi(String Name);
166                int Process(uint Samples);
167                void Stop();
168                void SetAudioOutputDevice(AudioOutputDeviceJack* device);
169                #if HAVE_JACK_MIDI
170                void SetMidiInputDevice(MidiInputDeviceJack* device);
171                #endif
172                void addListener(JackListener* listener);
173    
174                jack_client_t* hJackClient;
175    
176            private:
177                std::vector<JackListener*> jackListeners;
178                static std::map<String, JackClient*> Clients;
179                struct config_t {
180                    AudioOutputDeviceJack* AudioDevice;
181                    #if HAVE_JACK_MIDI
182                    MidiInputDeviceJack* MidiDevice;
183                    #endif
184                };
185                SynchronizedConfig<config_t> Config;
186                SynchronizedConfig<config_t>::Reader ConfigReader;
187                bool audio;
188                bool midi;
189    
190                JackClient(String Name);
191                ~JackClient();
192            
193                // Callback functions for the libjack API
194                static void libjackShutdownCallback(jack_status_t code, const char* reason, void *arg);
195                static int libjackSampleRateCallback(jack_nframes_t nframes, void *arg);
196                static int libjackBufferSizeCallback(jack_nframes_t nframes, void *arg);
197        };
198        
199        /**
200         * Currently not derived / instantiated by the sampler itself, however this
201         * class can be subclassed and used i.e. by a GUI build on top of the sampler,
202         * to react on JACK events. Because registering JACK callback functions through
203         * the general JACK API is not possible after the JACK client has been activated,
204         * and the latter is already the case as soon as an AudioOutputDeviceJack object
205         * has been instantiated.
206         */
207        class JackListener {
208        public:
209            virtual void onJackShutdown(jack_status_t code, const char* reason) = 0;
210        };
211  }  }
212    
213  #endif // HAVE_JACK  #endif // HAVE_JACK

Legend:
Removed from v.200  
changed lines
  Added in v.2444

  ViewVC Help
Powered by ViewVC