AU support, plus changes in Plugin to make unique_id a string
[ardour.git] / libs / ardour / ardour / audio_unit.h
1 /*
2     Copyright (C) 2006 Paul Davis 
3     Written by Taybin Rutkin
4
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.
9
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.
14
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.
18
19 */
20
21 #ifndef __ardour_audio_unit_h__
22 #define __ardour_audio_unit_h__
23
24 #include <stdint.h>
25
26 #include <list>
27 #include <set>
28 #include <string>
29 #include <vector>
30
31 #include <ardour/plugin.h>
32
33 #include <AudioUnit/AudioUnit.h>
34
35 #include <boost/shared_ptr.hpp>
36
37 class CAComponent;
38 class CAAudioUnit;
39 class CAComponentDescription;
40 struct AudioBufferList;
41
42 namespace ARDOUR {
43
44 class AudioEngine;
45 class Session;
46
47 class AUPlugin : public ARDOUR::Plugin
48 {
49   public:
50         AUPlugin (AudioEngine& engine, Session& session, CAComponent* comp);
51         virtual ~AUPlugin ();
52         
53         std::string unique_id () const;
54         const char * label () const;
55         const char * name () const { return _info->name.c_str(); }
56         const char * maker () const { return _info->creator.c_str(); }
57         uint32_t parameter_count () const;
58         float default_value (uint32_t port);
59         nframes_t latency () const;
60         void set_parameter (uint32_t which, float val);
61         float get_parameter (uint32_t which) const;
62     
63         int get_parameter_descriptor (uint32_t which, ParameterDescriptor&) const;
64         uint32_t nth_parameter (uint32_t which, bool& ok) const;
65         void activate ();
66         void deactivate ();
67         void set_block_size (nframes_t nframes);
68     
69         int connect_and_run (vector<Sample*>& bufs, uint32_t maxbuf, int32_t& in, int32_t& out, nframes_t nframes, nframes_t offset);
70         std::set<uint32_t> automatable() const;
71         string describe_parameter (uint32_t);
72         string state_node_name () const { return "audiounit"; }
73         void print_parameter (uint32_t, char*, uint32_t len) const;
74     
75         bool parameter_is_audio (uint32_t) const;
76         bool parameter_is_control (uint32_t) const;
77         bool parameter_is_input (uint32_t) const;
78         bool parameter_is_output (uint32_t) const;
79     
80         XMLNode& get_state();
81         int set_state(const XMLNode& node);
82         
83         bool save_preset (string name);
84         bool load_preset (const string preset_label);
85         std::vector<std::string> get_presets ();
86     
87         bool has_editor () const;
88         
89         bool fixed_io() const { return false; }
90         int32_t can_support_input_configuration (int32_t in);
91         int32_t compute_output_streams (int32_t nplugins);
92         uint32_t output_streams() const;
93         uint32_t input_streams() const;
94
95         CAAudioUnit* get_au () { return unit; }
96         CAComponent* get_comp () { return comp; }
97     
98     OSStatus render_callback(AudioUnitRenderActionFlags *ioActionFlags,
99                              const AudioTimeStamp    *inTimeStamp,
100                              UInt32       inBusNumber,
101                              UInt32       inNumberFrames,
102                              AudioBufferList*       ioData);
103   private:
104         CAComponent* comp;
105         CAAudioUnit* unit;
106         
107         AudioStreamBasicDescription streamFormat;
108         bool initialized;
109         AudioBufferList* buffers;
110         
111         UInt32 global_elements;
112         UInt32 output_elements;
113         UInt32 input_elements;
114         
115         int set_output_format ();
116         int set_input_format ();
117         int set_stream_format (int scope, uint32_t cnt);
118         int _set_block_size (nframes_t nframes);
119
120         std::vector<std::pair<uint32_t, uint32_t> > parameter_map;
121         uint32_t current_maxbuf;
122         nframes_t current_offset;
123         nframes_t cb_offset;
124         vector<Sample*>* current_buffers;
125         nframes_t frames_processed;
126 };
127         
128 typedef boost::shared_ptr<AUPlugin> AUPluginPtr;
129
130 class AUPluginInfo : public PluginInfo {
131   public:       
132          AUPluginInfo (CAComponentDescription*);
133         ~AUPluginInfo ();
134
135         PluginPtr load (Session& session);
136
137         static PluginInfoList discover ();
138         static void get_names (CAComponentDescription&, std::string& name, Glib::ustring& maker);
139         static std::string stringify_descriptor (const CAComponentDescription&);
140
141   private:
142         CAComponentDescription* descriptor;
143         static void discover_music (PluginInfoList&);
144         static void discover_fx (PluginInfoList&);
145         static void discover_by_description (PluginInfoList&, CAComponentDescription&);
146 };
147
148 typedef boost::shared_ptr<AUPluginInfo> AUPluginInfoPtr;
149
150 } // namespace ARDOUR
151
152 #endif // __ardour_audio_unit_h__