1 /* Calf DSP Library Utility Application - calfjackhost
2 * API wrapper for JACK Audio Connection Kit
4 * Copyright (C) 2007 Krzysztof Foltman
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2, or (at your option)
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
21 #ifndef __CALF_JACKHOST_H
22 #define __CALF_JACKHOST_H
31 #include <jack/jack.h>
32 #include <jack/session.h>
35 #define NFRAMES_MAYBE(nframes) nframes
37 #define NFRAMES_MAYBE(nframes)
40 namespace calf_plugins
{
44 struct automation_iface
46 virtual uint32_t apply_and_adjust(uint32_t start
, uint32_t time
) = 0;
47 virtual ~automation_iface() {}
52 std::vector
<jack_host
*> plugins
;
53 calf_utils::ptmutex mutex
;
55 /// Common port for MIDI parameter automation
56 jack_port_t
*automation_port
;
59 jack_client_t
*client
;
60 int input_nr
, output_nr
, midi_nr
;
61 std::string name
, input_name
, output_name
, midi_name
;
65 void add(jack_host
*plugin
);
66 void del(jack_host
*plugin
);
67 void open(const char *client_name
, const char *jack_session_id
);
68 std::string
get_name();
71 void delete_plugins();
72 void create_automation_input();
73 void destroy_automation_input();
74 void connect(const std::string
&p1
, const std::string
&p2
);
76 void apply_plugin_order(const std::vector
<int> &indices
);
77 void calculate_plugin_order(std::vector
<int> &indices
);
78 const char **get_ports(const char *name_re
, const char *type_re
, unsigned long flags
);
80 static int do_jack_process(jack_nframes_t nframes
, void *p
);
81 static int do_jack_bufsize(jack_nframes_t numsamples
, void *p
);
83 void atomic_swap(T
&v1
, T
&v2
)
85 calf_utils::ptlock
lock(mutex
);
90 class jack_host
: public plugin_ctl_iface
{
95 std::string name
, nice_name
;
97 port() : handle(NULL
), data(NULL
) {}
101 float **ins
, **outs
, **params
;
102 std::vector
<port
> inputs
, outputs
;
105 audio_module_iface
*module
;
106 automation_map
*cc_mappings
;
107 std::vector
<int> write_serials
;
108 int last_modify_serial
;
109 uint32_t last_designator
;
112 typedef int (*process_func
)(jack_nframes_t nframes
, void *p
);
117 std::string instance_name
;
118 int in_count
, out_count
, param_count
;
119 const plugin_metadata_iface
*metadata
;
122 jack_host(jack_client
*_client
, audio_module_iface
*_module
, const std::string
&_name
, const std::string
&_instance_name
, calf_plugins::progress_report_iface
*_priface
);
129 /// Handle JACK MIDI port data
130 void handle_event(uint8_t *buffer
, uint32_t size
);
131 /// Process audio and update meters
132 void process_part(unsigned int time
, unsigned int len
);
133 /// Get meter value for the Nth port
134 virtual float get_level(unsigned int port
);
135 /// Process audio/MIDI buffers
136 int process(jack_nframes_t nframes
, automation_iface
&automation
);
137 /// Retrieve and cache output port buffers
139 /// Retrieve the full list of input ports, audio+MIDI (the pointers are temporary, may point to nowhere after any changes etc.)
140 void get_all_input_ports(std::vector
<port
*> &ports
);
141 /// Retrieve the full list of output ports (the pointers are temporary, may point to nowhere after any changes etc.)
142 void get_all_output_ports(std::vector
<port
*> &ports
);
143 void handle_automation_cc(uint32_t designator
, int value
);
147 port
*get_inputs() { return &inputs
[0]; }
148 port
*get_outputs() { return &outputs
[0]; }
149 float *get_params() { return param_values
; }
150 port
*get_midi_port() { return get_metadata_iface()->get_midi() ? &midi_port
: NULL
; }
152 // Implementations of methods in plugin_ctl_iface
153 bool activate_preset(int bank
, int program
) { return false; }
154 virtual float get_param_value(int param_no
) {
155 assert(param_no
>= 0 && param_no
< param_count
);
156 return param_values
[param_no
];
158 virtual void set_param_value(int param_no
, float value
) {
159 assert(param_no
>= 0 && param_no
< param_count
);
160 param_values
[param_no
] = value
;
163 virtual void execute(int cmd_no
) { module
->execute(cmd_no
); }
164 virtual char *configure(const char *key
, const char *value
);
165 virtual void send_configures(send_configure_iface
*sci
) { module
->send_configures(sci
); }
166 virtual void send_automation_configures(send_configure_iface
*);
167 virtual int send_status_updates(send_updates_iface
*sui
, int last_serial
) { return module
->send_status_updates(sui
, last_serial
); }
168 virtual const plugin_metadata_iface
*get_metadata_iface() const { return module
->get_metadata_iface(); }
169 virtual const line_graph_iface
*get_line_graph_iface() const { return module
->get_line_graph_iface(); }
170 virtual const phase_graph_iface
*get_phase_graph_iface() const { return module
->get_phase_graph_iface(); }
171 virtual int get_write_serial(int param_no
) { return write_serials
[param_no
]; }
172 virtual void add_automation(uint32_t source
, const automation_range
&dest
);
173 virtual void delete_automation(uint32_t source
, int param_no
);
174 virtual void get_automation(int param_no
, std::multimap
<uint32_t, automation_range
> &dests
);
175 virtual uint32_t get_last_automation_source();
176 void replace_automation_map(automation_map
*amap
);
179 extern jack_host
*create_jack_host(jack_client
*_client
, const char *name
, const std::string
&instance_name
, calf_plugins::progress_report_iface
*priface
);