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__
25 #include <boost/shared_ptr.hpp>
33 #include <AudioUnit/AudioUnit.h>
34 #include <appleutility/AUParamInfo.h>
36 #include <boost/shared_ptr.hpp>
38 #include "ardour/plugin.h"
39 #include "ardour/chan_mapping.h"
43 class CAComponentDescription;
44 struct AudioBufferList;
51 struct AUParameterDescriptor : public Plugin::ParameterDescriptor {
52 // additional fields to make operations more efficient
53 AudioUnitParameterID id;
55 AudioUnitElement element;
58 AudioUnitParameterUnit unit;
61 class AUPlugin : public ARDOUR::Plugin
64 AUPlugin (AudioEngine& engine, Session& session, boost::shared_ptr<CAComponent> comp);
65 AUPlugin (const AUPlugin& other);
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;
82 void set_block_size (nframes_t nframes);
84 int connect_and_run (std::vector<Sample*>& bufs, uint32_t maxbuf, int32_t& in, int32_t& out, nframes_t nframes, nframes_t offset);
85 std::set<uint32_t> automatable() const;
86 std::string describe_parameter (uint32_t);
87 std::string state_node_name () const { return "audiounit"; }
88 void print_parameter (uint32_t, char*, uint32_t len) const;
90 bool parameter_is_audio (uint32_t) const;
91 bool parameter_is_control (uint32_t) const;
92 bool parameter_is_input (uint32_t) const;
93 bool parameter_is_output (uint32_t) const;
96 int set_state(const XMLNode& node);
98 bool save_preset (std::string name);
99 bool load_preset (const std::string preset_label);
100 std::vector<std::string> get_presets ();
101 std::string current_preset() const;
103 bool has_editor () const;
105 int32_t can_do (int32_t in, int32_t& out);
106 ChanCount output_streams() const;
107 ChanCount input_streams() const;
108 int32_t configure_io (int32_t in, int32_t out);
110 boost::shared_ptr<CAAudioUnit> get_au () { return unit; }
111 boost::shared_ptr<CAComponent> get_comp () const { return comp; }
113 OSStatus render_callback(AudioUnitRenderActionFlags *ioActionFlags,
114 const AudioTimeStamp *inTimeStamp,
116 UInt32 inNumberFrames,
117 AudioBufferList* ioData);
119 boost::shared_ptr<CAComponent> comp;
120 boost::shared_ptr<CAAudioUnit> unit;
123 ChanCount input_channels;
124 ChanCount output_channels;
125 std::vector<std::pair<int,int> > io_configs;
126 AudioBufferList* buffers;
128 /* XXX this should really be shared across all AUPlugin instances */
130 typedef std::map<std::string,std::string> PresetMap;
131 PresetMap preset_map;
133 UInt32 global_elements;
134 UInt32 output_elements;
135 UInt32 input_elements;
137 int set_output_format (AudioStreamBasicDescription&);
138 int set_input_format (AudioStreamBasicDescription&);
139 int set_stream_format (int scope, uint32_t cnt, AudioStreamBasicDescription&);
140 int _set_block_size (nframes_t nframes);
141 void discover_parameters ();
143 std::vector<std::pair<uint32_t, uint32_t> > parameter_map;
144 uint32_t current_maxbuf;
145 nframes_t current_offset;
147 std::vector<Sample*>* current_buffers;
148 nframes_t frames_processed;
150 std::vector<AUParameterDescriptor> descriptors;
154 typedef boost::shared_ptr<AUPlugin> AUPluginPtr;
156 struct AUPluginCachedInfo {
157 std::vector<std::pair<int,int> > io_configs;
160 class AUPluginInfo : public PluginInfo {
162 AUPluginInfo (boost::shared_ptr<CAComponentDescription>);
165 PluginPtr load (Session& session);
167 AUPluginCachedInfo cache;
169 static PluginInfoList* discover ();
170 static void get_names (CAComponentDescription&, std::string& name, Glib::ustring& maker);
171 static std::string stringify_descriptor (const CAComponentDescription&);
173 static int load_cached_info ();
176 boost::shared_ptr<CAComponentDescription> descriptor;
179 static void discover_music (PluginInfoList&);
180 static void discover_fx (PluginInfoList&);
181 static void discover_generators (PluginInfoList&);
182 static void discover_by_description (PluginInfoList&, CAComponentDescription&);
183 static Glib::ustring au_cache_path ();
185 typedef std::map<std::string,AUPluginCachedInfo> CachedInfoMap;
186 static CachedInfoMap cached_info;
188 static bool cached_io_configuration (const std::string&, UInt32, CAComponent&, AUPluginCachedInfo&, const std::string& name);
189 static void add_cached_info (const std::string&, AUPluginCachedInfo&);
190 static void save_cached_info ();
193 typedef boost::shared_ptr<AUPluginInfo> AUPluginInfoPtr;
195 } // namespace ARDOUR
197 #endif // __ardour_audio_unit_h__