00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019 #ifndef JACK_AUDIO_IO_H
00020 #define JACK_AUDIO_IO_H
00021
00022 extern "C" {
00023 #include <jack/jack.h>
00024 #include <jack/types.h>
00025 #include <jack/ringbuffer.h>
00026 }
00027 #include <string>
00028 #include <vector>
00029 #include <stdexcept>
00030 #include "jackringbuffer.hpp"
00031
00032 namespace JackCpp {
00033
00048 class AudioIO {
00049 public:
00051 enum jack_state_t {notActive,active,closed};
00053 typedef std::vector<jack_default_audio_sample_t *> audioBufVector;
00054 private:
00055
00056 enum cmd_t {add_in_port, add_out_port};
00057 RingBuffer<cmd_t> mCmdBuffer;
00058
00059 jack_client_t *mJackClient;
00060
00061 std::vector<jack_port_t *> mOutputPorts;
00062 std::vector<jack_port_t *> mInputPorts;
00063
00064
00065
00066
00067 unsigned int mNumOutputPorts;
00068 unsigned int mNumInputPorts;
00069
00070
00071 audioBufVector mJackInBuf;
00072 audioBufVector mJackOutBuf;
00073
00074 jack_state_t mJackState;
00075
00076
00077
00078 inline int jackToClassAudioCallback(jack_nframes_t nframes);
00079 std::vector<std::string> mPortNames;
00080 protected:
00088 virtual int audioCallback(jack_nframes_t nframes,
00089 audioBufVector inBufs,
00090 audioBufVector outBufs) = 0;
00095 jack_client_t * client();
00096 public:
00105 AudioIO(std::string name,
00106 unsigned int inPorts = 0,
00107 unsigned int outPorts = 2,
00108 #ifdef __APPLE__
00109 bool startServer = false)
00110 #else
00111 bool startServer = true)
00112 #endif
00113 throw(std::runtime_error);
00114
00116 virtual ~AudioIO();
00117
00129 static int jackProcessCallback(jack_nframes_t nframes, void *arg);
00130
00132 bool portExists(std::string name);
00133
00146 virtual void reserveOutPorts(unsigned int num)
00147 throw(std::runtime_error);
00160 virtual void reserveInPorts(unsigned int num)
00161 throw(std::runtime_error);
00162
00164 void start()
00165 throw(std::runtime_error);
00167 void stop()
00168 throw(std::runtime_error);
00170 void close()
00171 throw(std::runtime_error);
00172
00174 unsigned int inPorts();
00176 unsigned int outPorts();
00177
00183 virtual unsigned int addInPort(std::string name)
00184 throw(std::runtime_error);
00190 virtual unsigned int addOutPort(std::string name)
00191 throw(std::runtime_error);
00192
00198 void connectTo(unsigned int index, std::string sourcePortName)
00199 throw(std::range_error, std::runtime_error);
00205 void connectFrom(unsigned int index, std::string destPortName)
00206 throw(std::range_error, std::runtime_error);
00212 void connectToPhysical(unsigned int index, unsigned physical_index)
00213 throw(std::range_error, std::runtime_error);
00219 void connectFromPhysical(unsigned int index, unsigned physical_index)
00220 throw(std::range_error, std::runtime_error);
00222 void disconnectInPort(unsigned int index)
00223 throw(std::range_error, std::runtime_error);
00225 void disconnectOutPort(unsigned int index)
00226 throw(std::range_error, std::runtime_error);
00227
00229 unsigned int numConnectionsInPort(unsigned int index)
00230 throw(std::range_error);
00232 unsigned int numConnectionsOutPort(unsigned int index)
00233 throw(std::range_error);
00234
00239 unsigned int numPhysicalSourcePorts();
00244 unsigned int numPhysicalDestinationPorts();
00245
00247 std::string getInputPortName(unsigned int index)
00248 throw(std::range_error);
00250 std::string getOutputPortName(unsigned int index)
00251 throw(std::range_error);
00252
00257 virtual void jackShutdownCallback();
00265 float getCpuLoad();
00267 jack_nframes_t getSampleRate();
00269 jack_nframes_t getBufferSize();
00271 bool isRealTime(){return jack_is_realtime(mJackClient);}
00280 std::string getName(){return std::string(jack_get_client_name(mJackClient));}
00282 jack_state_t getState(){return mJackState;}
00283
00291 jack_nframes_t getFrameTime(){return jack_frame_time(mJackClient);}
00292
00298 jack_nframes_t getFramesSinceCycleStart(){return jack_frames_since_cycle_start(mJackClient);}
00299 };
00300
00301 }
00302
00303 #endif