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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 2412 - (hide annotations) (download) (as text)
Mon Feb 4 21:52:56 2013 UTC (11 years, 2 months ago) by schoenebeck
File MIME type: text/x-c++hdr
File size: 9239 byte(s)
* Bugfix: update effects on sample rate & period size changes.
* JACK: allow to register jackd shutdown listeners.

1 schoenebeck 200 /***************************************************************************
2     * *
3     * LinuxSampler - modular, streaming capable sampler *
4     * *
5     * Copyright (C) 2003, 2004 by Benno Senoner and Christian Schoenebeck *
6 schoenebeck 2410 * Copyright (C) 2005 - 2013 Christian Schoenebeck *
7 schoenebeck 200 * *
8     * 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 *
10     * the Free Software Foundation; either version 2 of the License, or *
11     * (at your option) any later version. *
12     * *
13     * This program is distributed in the hope that it will be useful, *
14     * but WITHOUT ANY WARRANTY; without even the implied warranty of *
15     * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
16     * GNU General Public License for more details. *
17     * *
18     * You should have received a copy of the GNU General Public License *
19     * along with this program; if not, write to the Free Software *
20     * Foundation, Inc., 59 Temple Place, Suite 330, Boston, *
21     * MA 02111-1307 USA *
22     ***************************************************************************/
23    
24     #ifndef __LS_AUDIOOUTPUTDEVICEJACK_H__
25     #define __LS_AUDIOOUTPUTDEVICEJACK_H__
26    
27 schoenebeck 1424 #include "../../common/global_private.h"
28 schoenebeck 200
29     #if HAVE_JACK
30    
31     #include <vector>
32     #include <sstream>
33     #include <jack/jack.h>
34    
35     #include "AudioOutputDevice.h"
36     #include "../../common/ConditionServer.h"
37 schoenebeck 1682
38     #if HAVE_JACK_MIDI
39 persson 1651 #include "../midi/MidiInputDeviceJack.h"
40 schoenebeck 1682 #endif
41 schoenebeck 200
42     namespace LinuxSampler {
43 schoenebeck 2412
44     class JackClient;
45     class JackListener;
46 schoenebeck 200
47     /** JACK audio output driver
48     *
49     * Implements audio output to the JACK Audio Connection Kit (JACK).
50     */
51     class AudioOutputDeviceJack : public AudioOutputDevice {
52     public:
53     AudioOutputDeviceJack(std::map<String,DeviceCreationParameter*> Parameters);
54 schoenebeck 374 virtual ~AudioOutputDeviceJack();
55 schoenebeck 200
56 schoenebeck 226 /**
57     * Audio channel implementation for the JACK audio driver.
58 schoenebeck 221 */
59 schoenebeck 226 class AudioChannelJack : public AudioChannel {
60 schoenebeck 200 public:
61 schoenebeck 226 /** Audio Channel Parameter 'NAME'
62     *
63     * Used to assign an arbitrary name to an audio channel.
64     */
65     class ParameterName : public AudioChannel::ParameterName {
66     public:
67     ParameterName(AudioChannelJack* pChannel);
68     virtual void OnSetValue(String s);
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();
81     virtual bool Fix();
82     virtual std::vector<String> PossibilitiesAsString();
83     virtual void OnSetValue(std::vector<String> vS);
84     static String Name();
85     protected:
86 schoenebeck 483 AudioChannelJack* pChannel;
87     std::vector<String> Bindings;
88 schoenebeck 226 };
89 schoenebeck 200 protected:
90 schoenebeck 226 AudioChannelJack(uint ChannelNr, AudioOutputDeviceJack* pDevice) throw (AudioOutputException);
91     ~AudioChannelJack();
92 schoenebeck 2410 void UpdateJackBuffer(uint size);
93 schoenebeck 226 friend class AudioOutputDeviceJack;
94     private:
95     AudioOutputDeviceJack* pDevice;
96     jack_port_t* hJackPort;
97     uint ChannelNr;
98    
99     float* CreateJackPort(uint ChannelNr, AudioOutputDeviceJack* pDevice) throw (AudioOutputException);
100 schoenebeck 200 };
101    
102 schoenebeck 374 /** 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 schoenebeck 880 ParameterName(String s) throw (Exception);
111 schoenebeck 374 virtual String Description();
112     virtual bool Fix();
113     virtual bool Mandatory();
114     virtual std::map<String,DeviceCreationParameter*> DependsAsParameters();
115     virtual std::vector<String> PossibilitiesAsString(std::map<String,String> Parameters);
116     virtual optional<String> DefaultAsString(std::map<String,String> Parameters);
117 schoenebeck 880 virtual void OnSetValue(String s) throw (Exception);
118 schoenebeck 374 static String Name();
119     };
120    
121 schoenebeck 200 // derived abstract methods from class 'AudioOutputDevice'
122     virtual void Play();
123     virtual bool IsPlaying();
124     virtual void Stop();
125     virtual uint MaxSamplesPerCycle();
126     virtual uint SampleRate();
127 schoenebeck 226 virtual AudioChannel* CreateChannel(uint ChannelNr);
128 schoenebeck 2410 virtual float latency();
129 schoenebeck 200
130 persson 1651 static String Name();
131 schoenebeck 200
132     virtual String Driver();
133    
134     static String Description();
135     static String Version();
136    
137     int Process(uint Samples); // FIXME: should be private
138 schoenebeck 2410 void UpdateJackBuffers(uint size);
139 schoenebeck 2412 void addListener(JackListener* listener);
140     jack_client_t* jackClientHandle();
141 schoenebeck 200 protected:
142     AudioOutputDeviceJack(String* AutoConnectPortIDs = NULL, uint AutoConnectPorts = 0);
143     private:
144 schoenebeck 226 ConditionServer csIsPlaying;
145     uint uiMaxSamplesPerCycle;
146     jack_client_t* hJackClient;
147 schoenebeck 2412 JackClient* pJackClient;
148 schoenebeck 200 };
149    
150     // Callback functions for the libjack API
151 persson 1651 int linuxsampler_libjack_process_callback(jack_nframes_t nframes, void* arg);
152    
153     /** JACK client
154     *
155     * Represents a jack client. This class is shared by
156     * AudioOutputDeviceJack and MidiInputDeviceJack. The jack server
157     * calls JackClient::Process, which in turn calls
158     * AudioOutputDeviceJack::Process and/or
159     * MidiInputDeviceJack::Process.
160     */
161     class JackClient {
162     public:
163     static JackClient* CreateAudio(String Name);
164     static JackClient* CreateMidi(String Name);
165     static void ReleaseAudio(String Name);
166     static void ReleaseMidi(String Name);
167     int Process(uint Samples);
168     void Stop();
169     void SetAudioOutputDevice(AudioOutputDeviceJack* device);
170 schoenebeck 1682 #if HAVE_JACK_MIDI
171 persson 1651 void SetMidiInputDevice(MidiInputDeviceJack* device);
172 schoenebeck 1682 #endif
173 schoenebeck 2412 void addListener(JackListener* listener);
174 persson 1651
175     jack_client_t* hJackClient;
176    
177     private:
178 schoenebeck 2412 std::vector<JackListener*> jackListeners;
179 persson 1651 static std::map<String, JackClient*> Clients;
180     struct config_t {
181     AudioOutputDeviceJack* AudioDevice;
182 schoenebeck 1682 #if HAVE_JACK_MIDI
183 persson 1651 MidiInputDeviceJack* MidiDevice;
184 schoenebeck 1682 #endif
185 persson 1651 };
186     SynchronizedConfig<config_t> Config;
187     SynchronizedConfig<config_t>::Reader ConfigReader;
188     bool audio;
189     bool midi;
190    
191     JackClient(String Name);
192     ~JackClient();
193 schoenebeck 2410
194     // Callback functions for the libjack API
195 schoenebeck 2412 static void libjackShutdownCallback(void* arg);
196 schoenebeck 2410 static int libjackSampleRateCallback(jack_nframes_t nframes, void *arg);
197     static int libjackBufferSizeCallback(jack_nframes_t nframes, void *arg);
198 persson 1651 };
199 schoenebeck 2412
200     /**
201     * Currently not derived / instantiated by the sampler itself, however this
202     * class can be subclassed and used i.e. by a GUI build on top of the sampler,
203     * to react on JACK events. Because registering JACK callback functions through
204     * the general JACK API is not possible after the JACK client has been activated,
205     * and the latter is already the case as soon as an AudioOutputDeviceJack object
206     * has been instantiated.
207     */
208     class JackListener {
209     public:
210     virtual void onJackShutdown() = 0;
211     };
212 schoenebeck 200 }
213    
214     #endif // HAVE_JACK
215     #endif // __LS_AUDIOOUTPUTDEVICEJACK_H__

  ViewVC Help
Powered by ViewVC