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