fixes for OS X compile of last commit
[ardour2.git] / libs / ardour / ardour / audio_unit.h
blobc8e4b4d740afeb0a2a6e85928ff0fa2f5d61e5c1
1 /*
2 Copyright (C) 2006 Paul Davis
3 Written by Taybin Rutkin
5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; either version 2 of the License, or
8 (at your option) any later version.
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with this program; if not, write to the Free Software
17 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
21 #ifndef __ardour_audio_unit_h__
22 #define __ardour_audio_unit_h__
24 #include <stdint.h>
25 #include <boost/shared_ptr.hpp>
27 #include <list>
28 #include <set>
29 #include <string>
30 #include <vector>
31 #include <map>
33 #include <ardour/plugin.h>
35 #include <AudioUnit/AudioUnit.h>
36 #include <AudioUnit/AudioUnitProperties.h>
37 #include <appleutility/AUParamInfo.h>
39 #include <boost/shared_ptr.hpp>
41 class CAComponent;
42 class CAAudioUnit;
43 class CAComponentDescription;
44 struct AudioBufferList;
46 namespace ARDOUR {
48 class AudioEngine;
49 class Session;
51 struct AUParameterDescriptor : public Plugin::ParameterDescriptor {
52 // additional fields to make operations more efficient
53 AudioUnitParameterID id;
54 AudioUnitScope scope;
55 AudioUnitElement element;
56 float default_value;
57 bool automatable;
58 AudioUnitParameterUnit unit;
61 class AUPlugin : public ARDOUR::Plugin
63 public:
64 AUPlugin (AudioEngine& engine, Session& session, boost::shared_ptr<CAComponent> comp);
65 AUPlugin (const AUPlugin& other);
66 virtual ~AUPlugin ();
68 std::string unique_id () const;
69 const char * label () const;
70 const char * name () const { return _info->name.c_str(); }
71 const char * maker () const { return _info->creator.c_str(); }
72 uint32_t parameter_count () const;
73 float default_value (uint32_t port);
74 nframes_t latency () const;
75 void set_parameter (uint32_t which, float val);
76 float get_parameter (uint32_t which) const;
78 int get_parameter_descriptor (uint32_t which, ParameterDescriptor&) const;
79 uint32_t nth_parameter (uint32_t which, bool& ok) const;
80 void activate ();
81 void deactivate ();
82 void flush ();
83 int set_block_size (nframes_t nframes);
85 int connect_and_run (vector<Sample*>& bufs, uint32_t maxbuf, int32_t& in, int32_t& out, nframes_t nframes, nframes_t offset);
86 std::set<uint32_t> automatable() const;
87 string describe_parameter (uint32_t);
88 string state_node_name () const { return "audiounit"; }
89 void print_parameter (uint32_t, char*, uint32_t len) const;
91 bool parameter_is_audio (uint32_t) const;
92 bool parameter_is_control (uint32_t) const;
93 bool parameter_is_input (uint32_t) const;
94 bool parameter_is_output (uint32_t) const;
96 XMLNode& get_state();
97 int set_state(const XMLNode& node);
99 bool save_preset (string name);
100 bool load_preset (const string preset_label);
101 std::vector<std::string> get_presets ();
102 std::string current_preset() const;
104 bool has_editor () const;
106 int32_t can_do (int32_t in, int32_t& out);
107 uint32_t output_streams() const;
108 uint32_t input_streams() const;
109 int32_t configure_io (int32_t in, int32_t out);
110 bool requires_fixed_size_buffers() const;
112 void set_fixed_size_buffers (bool yn) {
113 _requires_fixed_size_buffers = yn;
116 boost::shared_ptr<CAAudioUnit> get_au () { return unit; }
117 boost::shared_ptr<CAComponent> get_comp () const { return comp; }
119 OSStatus render_callback(AudioUnitRenderActionFlags *ioActionFlags,
120 const AudioTimeStamp *inTimeStamp,
121 UInt32 inBusNumber,
122 UInt32 inNumberFrames,
123 AudioBufferList* ioData);
125 /* "host" callbacks */
127 OSStatus get_beat_and_tempo_callback (Float64* outCurrentBeat,
128 Float64* outCurrentTempo);
130 OSStatus get_musical_time_location_callback (UInt32* outDeltaSampleOffsetToNextBeat,
131 Float32* outTimeSig_Numerator,
132 UInt32* outTimeSig_Denominator,
133 Float64* outCurrentMeasureDownBeat);
135 OSStatus get_transport_state_callback (Boolean* outIsPlaying,
136 Boolean* outTransportStateChanged,
137 Float64* outCurrentSampleInTimeLine,
138 Boolean* outIsCycling,
139 Float64* outCycleStartBeat,
140 Float64* outCycleEndBeat);
142 static std::string maybe_fix_broken_au_id (const std::string&);
144 private:
145 boost::shared_ptr<CAComponent> comp;
146 boost::shared_ptr<CAAudioUnit> unit;
148 bool initialized;
149 int32_t input_channels;
150 int32_t output_channels;
151 std::vector<std::pair<int,int> > io_configs;
152 nframes_t _current_block_size;
153 bool _requires_fixed_size_buffers;
154 AudioBufferList* buffers;
156 /* despite all the cool work that apple did on their AU preset
157 system, they left factory presets and user presets as two
158 entirely different kinds of things, handled by two entirely
159 different parts of the API. Resolve this.
162 /* XXX these two maps should really be shared across all instances of this AUPlugin */
164 typedef std::map<std::string,std::string> UserPresetMap;
165 UserPresetMap user_preset_map;
166 typedef std::map<std::string,int> FactoryPresetMap;
167 FactoryPresetMap factory_preset_map;
169 UInt32 global_elements;
170 UInt32 output_elements;
171 UInt32 input_elements;
173 int set_output_format (AudioStreamBasicDescription&);
174 int set_input_format (AudioStreamBasicDescription&);
175 int set_stream_format (int scope, uint32_t cnt, AudioStreamBasicDescription&);
176 int _set_block_size (nframes_t nframes);
177 void discover_parameters ();
179 std::vector<std::pair<uint32_t, uint32_t> > parameter_map;
180 uint32_t current_maxbuf;
181 nframes_t current_offset;
182 nframes_t cb_offset;
183 vector<Sample*>* current_buffers;
184 nframes_t frames_processed;
186 std::vector<AUParameterDescriptor> descriptors;
187 void init ();
189 void discover_factory_presets ();
191 bool last_transport_rolling;
192 float last_transport_speed;
195 typedef boost::shared_ptr<AUPlugin> AUPluginPtr;
197 struct AUPluginCachedInfo {
198 std::vector<std::pair<int,int> > io_configs;
201 class AUPluginInfo : public PluginInfo {
202 public:
203 AUPluginInfo (boost::shared_ptr<CAComponentDescription>);
204 ~AUPluginInfo ();
206 PluginPtr load (Session& session);
208 AUPluginCachedInfo cache;
210 static PluginInfoList discover ();
211 static void get_names (CAComponentDescription&, std::string& name, Glib::ustring& maker);
212 static std::string stringify_descriptor (const CAComponentDescription&);
214 static int load_cached_info ();
216 private:
217 boost::shared_ptr<CAComponentDescription> descriptor;
218 UInt32 version;
220 static void discover_music (PluginInfoList&);
221 static void discover_fx (PluginInfoList&);
222 static void discover_generators (PluginInfoList&);
223 static void discover_by_description (PluginInfoList&, CAComponentDescription&);
224 static Glib::ustring au_cache_path ();
226 typedef std::map<std::string,AUPluginCachedInfo> CachedInfoMap;
227 static CachedInfoMap cached_info;
229 static bool cached_io_configuration (const std::string&, UInt32, CAComponent&, AUPluginCachedInfo&, const std::string& name);
230 static void add_cached_info (const std::string&, AUPluginCachedInfo&);
231 static void save_cached_info ();
234 typedef boost::shared_ptr<AUPluginInfo> AUPluginInfoPtr;
236 } // namespace ARDOUR
238 #endif // __ardour_audio_unit_h__