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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1651 - (show annotations) (download) (as text)
Sun Jan 27 15:07:11 2008 UTC (16 years, 2 months ago) by persson
File MIME type: text/x-c++hdr
File size: 7882 byte(s)
* added JACK MIDI driver

1 /***************************************************************************
2 * *
3 * LinuxSampler - modular, streaming capable sampler *
4 * *
5 * Copyright (C) 2003, 2004 by Benno Senoner and Christian Schoenebeck *
6 * Copyright (C) 2005 - 2008 Christian Schoenebeck *
7 * *
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 #include "../../common/global_private.h"
28
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 #include "../midi/MidiInputDeviceJack.h"
38
39 namespace LinuxSampler {
40
41 /** JACK audio output driver
42 *
43 * Implements audio output to the JACK Audio Connection Kit (JACK).
44 */
45 class AudioOutputDeviceJack : public AudioOutputDevice {
46 public:
47 AudioOutputDeviceJack(std::map<String,DeviceCreationParameter*> Parameters);
48 virtual ~AudioOutputDeviceJack();
49
50 /**
51 * Audio channel implementation for the JACK audio driver.
52 */
53 class AudioChannelJack : public AudioChannel {
54 public:
55 /** Audio Channel Parameter 'NAME'
56 *
57 * Used to assign an arbitrary name to an audio channel.
58 */
59 class ParameterName : public AudioChannel::ParameterName {
60 public:
61 ParameterName(AudioChannelJack* pChannel);
62 virtual void OnSetValue(String s);
63 protected:
64 AudioChannelJack* pChannel;
65 };
66
67 /** Audio Channel Parameter 'JACK_BINDINGS'
68 *
69 * Used to connect to other JACK clients.
70 */
71 class ParameterJackBindings : public DeviceRuntimeParameterStrings {
72 public:
73 ParameterJackBindings(AudioChannelJack* pChannel);
74 virtual String Description();
75 virtual bool Fix();
76 virtual std::vector<String> PossibilitiesAsString();
77 virtual void OnSetValue(std::vector<String> vS);
78 static String Name();
79 protected:
80 AudioChannelJack* pChannel;
81 std::vector<String> Bindings;
82 };
83 protected:
84 AudioChannelJack(uint ChannelNr, AudioOutputDeviceJack* pDevice) throw (AudioOutputException);
85 ~AudioChannelJack();
86 friend class AudioOutputDeviceJack;
87 private:
88 AudioOutputDeviceJack* pDevice;
89 jack_port_t* hJackPort;
90 uint ChannelNr;
91
92 float* CreateJackPort(uint ChannelNr, AudioOutputDeviceJack* pDevice) throw (AudioOutputException);
93 };
94
95 /** Audio Device Parameter 'NAME'
96 *
97 * Used to assign an arbitrary name to the JACK client of this
98 * audio device.
99 */
100 class ParameterName : public DeviceCreationParameterString {
101 public:
102 ParameterName();
103 ParameterName(String s) throw (Exception);
104 virtual String Description();
105 virtual bool Fix();
106 virtual bool Mandatory();
107 virtual std::map<String,DeviceCreationParameter*> DependsAsParameters();
108 virtual std::vector<String> PossibilitiesAsString(std::map<String,String> Parameters);
109 virtual optional<String> DefaultAsString(std::map<String,String> Parameters);
110 virtual void OnSetValue(String s) throw (Exception);
111 static String Name();
112 };
113
114 // derived abstract methods from class 'AudioOutputDevice'
115 virtual void Play();
116 virtual bool IsPlaying();
117 virtual void Stop();
118 virtual uint MaxSamplesPerCycle();
119 virtual uint SampleRate();
120 virtual AudioChannel* CreateChannel(uint ChannelNr);
121
122
123 static String Name();
124
125 virtual String Driver();
126
127 static String Description();
128 static String Version();
129
130 int Process(uint Samples); // FIXME: should be private
131 protected:
132 AudioOutputDeviceJack(String* AutoConnectPortIDs = NULL, uint AutoConnectPorts = 0);
133 private:
134 ConditionServer csIsPlaying;
135 uint uiMaxSamplesPerCycle;
136 jack_client_t* hJackClient;
137 };
138
139 // Callback functions for the libjack API
140 int linuxsampler_libjack_process_callback(jack_nframes_t nframes, void* arg);
141 void linuxsampler_libjack_shutdown_callback(void* arg);
142
143
144 /** JACK client
145 *
146 * Represents a jack client. This class is shared by
147 * AudioOutputDeviceJack and MidiInputDeviceJack. The jack server
148 * calls JackClient::Process, which in turn calls
149 * AudioOutputDeviceJack::Process and/or
150 * MidiInputDeviceJack::Process.
151 */
152 class JackClient {
153 public:
154 static JackClient* CreateAudio(String Name);
155 static JackClient* CreateMidi(String Name);
156 static void ReleaseAudio(String Name);
157 static void ReleaseMidi(String Name);
158 int Process(uint Samples);
159 void Stop();
160 void SetAudioOutputDevice(AudioOutputDeviceJack* device);
161 void SetMidiInputDevice(MidiInputDeviceJack* device);
162
163 jack_client_t* hJackClient;
164
165 private:
166 static std::map<String, JackClient*> Clients;
167 struct config_t {
168 AudioOutputDeviceJack* AudioDevice;
169 MidiInputDeviceJack* MidiDevice;
170 };
171 SynchronizedConfig<config_t> Config;
172 SynchronizedConfig<config_t>::Reader ConfigReader;
173 bool audio;
174 bool midi;
175
176 JackClient(String Name);
177 ~JackClient();
178 };
179 }
180
181 #endif // HAVE_JACK
182 #endif // __LS_AUDIOOUTPUTDEVICEJACK_H__

  ViewVC Help
Powered by ViewVC