1 /* JACK Backend code for Carla */
4 #include "audio_plugin.h"
6 #include <QtCore/QProcess>
9 extern AudioPlugin
* AudioPlugins
[MAX_PLUGINS
];
11 extern volatile double ains_peak
[MAX_PLUGINS
*2];
12 extern volatile double aouts_peak
[MAX_PLUGINS
*2];
15 extern OscData global_osc_data
;
17 // --------------------------------------------------------------------------------------------------------
20 const char* bool2str(bool yesno
)
28 // --------------------------------------------------------------------------------------------------------
31 PluginOscThread::PluginOscThread(QObject
*parent
) :
34 qDebug("PluginOscThread::PluginOscThread(%p)", parent
);
35 m_process
= new QProcess(parent
);
38 PluginOscThread::~PluginOscThread()
40 // TODO - kill process
44 void PluginOscThread::set_plugin(AudioPlugin
* plugin
)
49 void PluginOscThread::run()
53 // --------------------------------------------------------------------------------------------------------
56 CarlaCheckThread::CarlaCheckThread(QObject
*parent
) :
59 qDebug("CarlaCheckThread::CarlaCheckThread(%p)", parent
);
62 void CarlaCheckThread::run()
64 qDebug("CarlaCheckThread::run()");
67 PluginPostEvent post_events
[MAX_POSTEVENTS
];
69 while (carla_is_engine_running())
71 for (unsigned short i
=0; i
<MAX_PLUGINS
; i
++)
73 AudioPlugin
* plugin
= AudioPlugins
[i
];
74 if (plugin
&& plugin
->id
>= 0)
76 // --------------------------------------------------------------------------------------------------------
77 // Process postponed events
79 // Make a safe copy of events, and clear them
80 plugin
->post_events_lock();
81 memcpy(&post_events
, &plugin
->post_events
.events
, sizeof(PluginPostEvent
)*MAX_POSTEVENTS
);
83 for (j
=0; j
< MAX_POSTEVENTS
; j
++)
84 plugin
->post_events
.events
[j
].valid
= false;
86 plugin
->post_events_unlock();
89 for (j
=0; j
< MAX_POSTEVENTS
; j
++)
91 if (post_events
[j
].valid
)
93 switch (post_events
[j
].type
)
96 callback_action(CALLBACK_DEBUG
, plugin
->id
, post_events
[j
].index
, 0, post_events
[j
].value
);
99 case PostEventParameter
:
100 osc_send_set_parameter_value(&global_osc_data
, plugin
->id
, post_events
[j
].index
, post_events
[j
].value
);
101 callback_action(CALLBACK_PARAMETER_CHANGED
, plugin
->id
, post_events
[j
].index
, 0, post_events
[j
].value
);
103 if (plugin
->hints
& PLUGIN_IS_BRIDGE
)
104 osc_send_control(&plugin
->osc
.data
, post_events
[j
].index
, post_events
[j
].value
);
107 case PostEventProgram
:
108 osc_send_set_program(&global_osc_data
, plugin
->id
, post_events
[j
].index
);
109 callback_action(CALLBACK_PROGRAM_CHANGED
, plugin
->id
, post_events
[j
].index
, 0, 0.0f
);
111 if (plugin
->hints
& PLUGIN_IS_BRIDGE
)
112 osc_send_program(&plugin
->osc
.data
, post_events
[j
].index
);
114 for (uint32_t k
=0; k
< plugin
->param
.count
; k
++)
115 osc_send_set_default_value(&global_osc_data
, plugin
->id
, k
, plugin
->param
.ranges
[k
].def
);
118 case PostEventMidiProgram
:
119 osc_send_set_midi_program(&global_osc_data
, plugin
->id
, post_events
[j
].index
);
120 callback_action(CALLBACK_MIDI_PROGRAM_CHANGED
, plugin
->id
, post_events
[j
].index
, 0, 0.0f
);
122 if (plugin
->type
== PLUGIN_DSSI
)
123 osc_send_program_as_midi(&plugin
->osc
.data
, plugin
->midiprog
.data
[post_events
[j
].index
].bank
, plugin
->midiprog
.data
[post_events
[j
].index
].program
);
125 if (plugin
->hints
& PLUGIN_IS_BRIDGE
)
126 osc_send_midi_program(&plugin
->osc
.data
, plugin
->midiprog
.data
[post_events
[j
].index
].bank
, plugin
->midiprog
.data
[post_events
[j
].index
].program
);
128 for (uint32_t k
=0; k
< plugin
->param
.count
; k
++)
129 osc_send_set_default_value(&global_osc_data
, plugin
->id
, k
, plugin
->param
.ranges
[k
].def
);
132 case PostEventNoteOn
:
133 osc_send_note_on(&global_osc_data
, plugin
->id
, post_events
[j
].index
, post_events
[j
].value
);
134 callback_action(CALLBACK_NOTE_ON
, plugin
->id
, post_events
[j
].index
, post_events
[j
].value
, 0.0f
);
136 if (plugin
->hints
& PLUGIN_IS_BRIDGE
)
137 osc_send_note_on(&plugin
->osc
.data
, plugin
->id
, post_events
[j
].index
, post_events
[j
].value
);
140 case PostEventNoteOff
:
141 osc_send_note_off(&global_osc_data
, plugin
->id
, post_events
[j
].index
, post_events
[j
].value
);
142 callback_action(CALLBACK_NOTE_OFF
, plugin
->id
, post_events
[j
].index
, post_events
[j
].value
, 0.0f
);
144 if (plugin
->hints
& PLUGIN_IS_BRIDGE
)
145 osc_send_note_off(&plugin
->osc
.data
, plugin
->id
, post_events
[j
].index
, post_events
[j
].value
);
154 // --------------------------------------------------------------------------------------------------------
156 if (plugin
->gui
.visible
&& plugin
->gui
.type
!= GUI_EXTERNAL_OSC
)
159 // --------------------------------------------------------------------------------------------------------
162 // Check if it needs update
163 bool update_ports_gui
= (plugin
->gui
.visible
&& plugin
->gui
.type
== GUI_EXTERNAL_OSC
&& plugin
->osc
.data
.target
);
165 if (!global_osc_data
.target
&& !update_ports_gui
)
169 for (j
=0; j
< plugin
->param
.count
; j
++)
171 if (plugin
->param
.data
[j
].type
== PARAMETER_OUTPUT
&& (plugin
->param
.data
[j
].hints
& PARAMETER_IS_AUTOMABLE
) > 0)
173 if (update_ports_gui
)
174 osc_send_control(&plugin
->osc
.data
, plugin
->param
.data
[j
].rindex
, plugin
->param
.buffers
[j
]);
176 osc_send_set_parameter_value(&global_osc_data
, plugin
->id
, j
, plugin
->param
.buffers
[j
]);
180 // --------------------------------------------------------------------------------------------------------
181 // Send peak values (OSC)
182 if (global_osc_data
.target
)
184 if (plugin
->ain
.count
> 0)
186 osc_send_set_input_peak_value(&global_osc_data
, plugin
->id
, 1, ains_peak
[(plugin
->id
*2)+0]);
187 osc_send_set_input_peak_value(&global_osc_data
, plugin
->id
, 2, ains_peak
[(plugin
->id
*2)+1]);
189 if (plugin
->aout
.count
> 0)
191 osc_send_set_output_peak_value(&global_osc_data
, plugin
->id
, 1, aouts_peak
[(plugin
->id
*2)+0]);
192 osc_send_set_output_peak_value(&global_osc_data
, plugin
->id
, 2, aouts_peak
[(plugin
->id
*2)+1]);
197 usleep(50000); // 50 ms