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>
32 #include <ardour/plugin.h>
34 #include <AudioUnit/AudioUnit.h>
35 #include <appleutility/AUParamInfo.h>
37 #include <boost/shared_ptr.hpp>
41 class CAComponentDescription;
42 struct AudioBufferList;
49 struct AUParameterDescriptor : public Plugin::ParameterDescriptor {
50 // additional fields to make operations more efficient
51 AudioUnitParameterID id;
53 AudioUnitElement element;
56 AudioUnitParameterUnit unit;
59 class AUPlugin : public ARDOUR::Plugin
62 AUPlugin (AudioEngine& engine, Session& session, boost::shared_ptr<CAComponent> comp);
65 std::string unique_id () const;
66 const char * label () const;
67 const char * name () const { return _info->name.c_str(); }
68 const char * maker () const { return _info->creator.c_str(); }
69 uint32_t parameter_count () const;
70 float default_value (uint32_t port);
71 nframes_t latency () const;
72 void set_parameter (uint32_t which, float val);
73 float get_parameter (uint32_t which) const;
75 int get_parameter_descriptor (uint32_t which, ParameterDescriptor&) const;
76 uint32_t nth_parameter (uint32_t which, bool& ok) const;
79 void set_block_size (nframes_t nframes);
81 int connect_and_run (vector<Sample*>& bufs, uint32_t maxbuf, int32_t& in, int32_t& out, nframes_t nframes, nframes_t offset);
82 std::set<uint32_t> automatable() const;
83 string describe_parameter (uint32_t);
84 string state_node_name () const { return "audiounit"; }
85 void print_parameter (uint32_t, char*, uint32_t len) const;
87 bool parameter_is_audio (uint32_t) const;
88 bool parameter_is_control (uint32_t) const;
89 bool parameter_is_input (uint32_t) const;
90 bool parameter_is_output (uint32_t) const;
93 int set_state(const XMLNode& node);
95 bool save_preset (string name);
96 bool load_preset (const string preset_label);
97 std::vector<std::string> get_presets ();
99 bool has_editor () const;
101 bool fixed_io() const { return false; }
102 int32_t can_support_input_configuration (int32_t in);
103 int32_t compute_output_streams (int32_t nplugins);
104 uint32_t output_streams() const;
105 uint32_t input_streams() const;
107 boost::shared_ptr<CAAudioUnit> get_au () { return unit; }
108 boost::shared_ptr<CAComponent> get_comp () { return comp; }
110 OSStatus render_callback(AudioUnitRenderActionFlags *ioActionFlags,
111 const AudioTimeStamp *inTimeStamp,
113 UInt32 inNumberFrames,
114 AudioBufferList* ioData);
116 boost::shared_ptr<CAComponent> comp;
117 boost::shared_ptr<CAAudioUnit> unit;
119 AudioStreamBasicDescription streamFormat;
122 AudioBufferList* buffers;
124 UInt32 global_elements;
125 UInt32 output_elements;
126 UInt32 input_elements;
128 int set_output_format ();
129 int set_input_format ();
130 int set_stream_format (int scope, uint32_t cnt);
131 int _set_block_size (nframes_t nframes);
132 void discover_parameters ();
134 std::vector<std::pair<uint32_t, uint32_t> > parameter_map;
135 uint32_t current_maxbuf;
136 nframes_t current_offset;
138 vector<Sample*>* current_buffers;
139 nframes_t frames_processed;
141 std::vector<AUParameterDescriptor> descriptors;
144 typedef boost::shared_ptr<AUPlugin> AUPluginPtr;
146 class AUPluginInfo : public PluginInfo {
148 AUPluginInfo (boost::shared_ptr<CAComponentDescription>);
151 PluginPtr load (Session& session);
153 static PluginInfoList discover ();
154 static void get_names (CAComponentDescription&, std::string& name, Glib::ustring& maker);
155 static std::string stringify_descriptor (const CAComponentDescription&);
158 boost::shared_ptr<CAComponentDescription> descriptor;
160 static void discover_music (PluginInfoList&);
161 static void discover_fx (PluginInfoList&);
162 static void discover_by_description (PluginInfoList&, CAComponentDescription&);
165 typedef boost::shared_ptr<AUPluginInfo> AUPluginInfoPtr;
167 } // namespace ARDOUR
169 #endif // __ardour_audio_unit_h__