2020-02-20 07:12:36 -05:00
|
|
|
/*
|
2021-06-13 10:32:18 -04:00
|
|
|
* Copyright (C) 2020 Luciano Iam <oss@lucianoiam.com>
|
2020-02-20 07:12:36 -05:00
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation; either version 2 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License along
|
|
|
|
* with this program; if not, write to the Free Software Foundation, Inc.,
|
|
|
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
|
|
|
*/
|
|
|
|
|
2020-02-22 07:50:24 -05:00
|
|
|
#include <boost/assign.hpp>
|
|
|
|
|
2020-02-20 07:12:36 -05:00
|
|
|
#include "ardour/plugin_insert.h"
|
|
|
|
|
|
|
|
#include "ardour_websockets.h"
|
2020-02-23 10:03:59 -05:00
|
|
|
#include "dispatcher.h"
|
2020-02-20 07:12:36 -05:00
|
|
|
#include "state.h"
|
|
|
|
|
|
|
|
using namespace ARDOUR;
|
2020-08-30 15:15:07 -04:00
|
|
|
using namespace ArdourSurface;
|
2020-02-20 07:12:36 -05:00
|
|
|
|
2020-02-23 10:03:59 -05:00
|
|
|
#define NODE_METHOD_PAIR(x) (Node::x, &WebsocketsDispatcher::x##_handler)
|
2020-02-20 07:12:36 -05:00
|
|
|
|
|
|
|
WebsocketsDispatcher::NodeMethodMap
|
2020-04-14 16:58:44 -04:00
|
|
|
WebsocketsDispatcher::_node_to_method = boost::assign::map_list_of
|
2020-05-30 13:08:27 -04:00
|
|
|
NODE_METHOD_PAIR (transport_tempo)
|
2020-04-18 08:56:46 -04:00
|
|
|
NODE_METHOD_PAIR (transport_roll)
|
2020-05-30 13:08:27 -04:00
|
|
|
NODE_METHOD_PAIR (transport_record)
|
2020-02-23 10:03:59 -05:00
|
|
|
NODE_METHOD_PAIR (strip_gain)
|
2020-04-14 16:58:44 -04:00
|
|
|
NODE_METHOD_PAIR (strip_pan)
|
|
|
|
NODE_METHOD_PAIR (strip_mute)
|
|
|
|
NODE_METHOD_PAIR (strip_plugin_enable)
|
|
|
|
NODE_METHOD_PAIR (strip_plugin_param_value);
|
2020-02-20 07:12:36 -05:00
|
|
|
|
|
|
|
void
|
|
|
|
WebsocketsDispatcher::dispatch (Client client, const NodeStateMessage& msg)
|
|
|
|
{
|
2020-02-23 10:03:59 -05:00
|
|
|
NodeMethodMap::iterator it = _node_to_method.find (msg.state ().node ());
|
|
|
|
if (it != _node_to_method.end ()) {
|
|
|
|
try {
|
|
|
|
(this->*it->second) (client, msg);
|
|
|
|
} catch (const std::exception& e) {
|
|
|
|
std::cerr << e.what () << std::endl;
|
|
|
|
}
|
|
|
|
}
|
2020-02-20 07:12:36 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
WebsocketsDispatcher::update_all_nodes (Client client)
|
|
|
|
{
|
2020-08-29 14:06:00 -04:00
|
|
|
for (ArdourMixer::StripMap::iterator it = mixer().strips().begin(); it != mixer().strips().end(); ++it) {
|
2020-08-30 16:50:25 -04:00
|
|
|
uint32_t strip_id = it->first;
|
|
|
|
ArdourMixerStrip& strip = *it->second;
|
2020-04-21 09:18:23 -04:00
|
|
|
|
2020-04-21 10:20:16 -04:00
|
|
|
AddressVector strip_addr = AddressVector ();
|
2020-08-29 18:42:07 -04:00
|
|
|
strip_addr.push_back (strip_id);
|
2022-01-09 16:19:20 -05:00
|
|
|
|
2020-04-21 10:20:16 -04:00
|
|
|
ValueVector strip_desc = ValueVector ();
|
2020-08-29 11:01:35 -04:00
|
|
|
strip_desc.push_back (strip.name ());
|
2020-09-05 07:12:04 -04:00
|
|
|
strip_desc.push_back ((int)strip.stripable ()->presentation_info ().flags ());
|
2022-01-09 16:19:20 -05:00
|
|
|
|
2020-04-21 10:20:16 -04:00
|
|
|
update (client, Node::strip_description, strip_addr, strip_desc);
|
2022-01-09 16:19:20 -05:00
|
|
|
|
2020-08-29 18:42:07 -04:00
|
|
|
update (client, Node::strip_gain, strip_id, strip.gain ());
|
|
|
|
update (client, Node::strip_mute, strip_id, strip.mute ());
|
2020-04-21 09:18:23 -04:00
|
|
|
|
2020-09-01 16:28:00 -04:00
|
|
|
if (strip.has_pan ()) {
|
|
|
|
update (client, Node::strip_pan, strip_id, strip.pan ());
|
2020-02-23 10:03:59 -05:00
|
|
|
}
|
|
|
|
|
2020-08-29 14:06:00 -04:00
|
|
|
for (ArdourMixerStrip::PluginMap::iterator it = strip.plugins ().begin (); it != strip.plugins ().end (); ++it) {
|
2020-08-30 05:56:24 -04:00
|
|
|
uint32_t plugin_id = it->first;
|
2023-02-16 18:33:28 -05:00
|
|
|
std::shared_ptr<PluginInsert> insert = it->second->insert ();
|
|
|
|
std::shared_ptr<Plugin> plugin = insert->plugin ();
|
2020-02-23 10:03:59 -05:00
|
|
|
|
2020-08-29 18:42:07 -04:00
|
|
|
update (client, Node::strip_plugin_description, strip_id, plugin_id,
|
2020-02-23 10:03:59 -05:00
|
|
|
static_cast<std::string> (plugin->name ()));
|
|
|
|
|
2020-08-29 18:42:07 -04:00
|
|
|
update (client, Node::strip_plugin_enable, strip_id, plugin_id,
|
|
|
|
strip.plugin (plugin_id).enabled ());
|
2020-02-23 10:03:59 -05:00
|
|
|
|
2020-08-29 18:42:07 -04:00
|
|
|
for (uint32_t param_id = 0; param_id < plugin->parameter_count (); ++param_id) {
|
2023-02-16 18:33:28 -05:00
|
|
|
std::shared_ptr<AutomationControl> a_ctrl;
|
2020-08-29 14:06:00 -04:00
|
|
|
|
|
|
|
try {
|
2020-08-29 18:42:07 -04:00
|
|
|
a_ctrl = strip.plugin (plugin_id).param_control (param_id);
|
2020-08-30 15:15:33 -04:00
|
|
|
} catch (ArdourMixerNotFoundException& err) {
|
2020-02-23 10:03:59 -05:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
AddressVector addr = AddressVector ();
|
2020-08-29 18:42:07 -04:00
|
|
|
addr.push_back (strip_id);
|
|
|
|
addr.push_back (plugin_id);
|
|
|
|
addr.push_back (param_id);
|
2020-02-23 10:03:59 -05:00
|
|
|
|
|
|
|
ValueVector val = ValueVector ();
|
|
|
|
val.push_back (a_ctrl->name ());
|
|
|
|
|
|
|
|
// possible flags: enumeration, integer_step, logarithmic, sr_dependent, toggled
|
|
|
|
ParameterDescriptor pd = a_ctrl->desc ();
|
|
|
|
|
|
|
|
if (pd.toggled) {
|
|
|
|
val.push_back (std::string ("b"));
|
|
|
|
} else if (pd.enumeration || pd.integer_step) {
|
|
|
|
val.push_back (std::string ("i"));
|
|
|
|
val.push_back (pd.lower);
|
|
|
|
val.push_back (pd.upper);
|
|
|
|
} else {
|
|
|
|
val.push_back (std::string ("d"));
|
|
|
|
val.push_back (pd.lower);
|
|
|
|
val.push_back (pd.upper);
|
|
|
|
val.push_back (pd.logarithmic);
|
|
|
|
}
|
|
|
|
|
2020-04-18 06:44:00 -04:00
|
|
|
update (client, Node::strip_plugin_param_description, addr, val);
|
2020-02-23 10:03:59 -05:00
|
|
|
|
2020-08-29 18:42:07 -04:00
|
|
|
TypedValue value = strip.plugin (plugin_id).param_value (param_id);
|
|
|
|
update (client, Node::strip_plugin_param_value, strip_id, plugin_id, param_id, value);
|
2020-02-23 10:03:59 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2020-05-29 05:37:34 -04:00
|
|
|
|
2020-05-30 13:08:27 -04:00
|
|
|
update (client, Node::transport_tempo, transport ().tempo ());
|
|
|
|
update (client, Node::transport_time, transport ().time ());
|
2022-01-09 16:19:20 -05:00
|
|
|
update (client, Node::transport_bbt, transport ().bbt ());
|
2020-05-30 13:08:27 -04:00
|
|
|
update (client, Node::transport_roll, transport ().roll ());
|
|
|
|
update (client, Node::transport_record, transport ().record ());
|
2020-02-20 07:12:36 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2020-05-30 13:08:27 -04:00
|
|
|
WebsocketsDispatcher::transport_tempo_handler (Client client, const NodeStateMessage& msg)
|
2020-02-20 07:12:36 -05:00
|
|
|
{
|
2020-04-16 08:35:21 -04:00
|
|
|
const NodeState& state = msg.state ();
|
|
|
|
|
|
|
|
if (msg.is_write () && (state.n_val () > 0)) {
|
2020-05-30 13:08:27 -04:00
|
|
|
transport ().set_tempo (state.nth_val (0));
|
2020-02-23 10:03:59 -05:00
|
|
|
} else {
|
2020-05-30 13:08:27 -04:00
|
|
|
update (client, Node::transport_tempo, transport ().tempo ());
|
2020-02-23 10:03:59 -05:00
|
|
|
}
|
2020-02-20 07:12:36 -05:00
|
|
|
}
|
|
|
|
|
2020-04-18 08:56:46 -04:00
|
|
|
void
|
|
|
|
WebsocketsDispatcher::transport_roll_handler (Client client, const NodeStateMessage& msg)
|
|
|
|
{
|
|
|
|
const NodeState& state = msg.state ();
|
|
|
|
|
|
|
|
if (msg.is_write () && (state.n_val () > 0)) {
|
2020-05-30 13:08:27 -04:00
|
|
|
transport ().set_roll (state.nth_val (0));
|
2020-04-18 08:56:46 -04:00
|
|
|
} else {
|
2020-05-30 13:08:27 -04:00
|
|
|
update (client, Node::transport_roll, transport ().roll ());
|
2020-04-18 08:56:46 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2020-05-30 13:08:27 -04:00
|
|
|
WebsocketsDispatcher::transport_record_handler (Client client, const NodeStateMessage& msg)
|
2020-04-18 08:56:46 -04:00
|
|
|
{
|
|
|
|
const NodeState& state = msg.state ();
|
|
|
|
|
|
|
|
if (msg.is_write () && (state.n_val () > 0)) {
|
2020-05-30 13:08:27 -04:00
|
|
|
transport ().set_record (state.nth_val (0));
|
2020-04-18 08:56:46 -04:00
|
|
|
} else {
|
2020-05-30 13:08:27 -04:00
|
|
|
update (client, Node::transport_record, transport ().record ());
|
2020-04-18 08:56:46 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-02-20 07:12:36 -05:00
|
|
|
void
|
|
|
|
WebsocketsDispatcher::strip_gain_handler (Client client, const NodeStateMessage& msg)
|
|
|
|
{
|
2020-04-16 08:35:21 -04:00
|
|
|
const NodeState& state = msg.state ();
|
|
|
|
|
|
|
|
if (state.n_addr () < 1) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
uint32_t strip_id = state.nth_addr (0);
|
2020-02-20 07:12:36 -05:00
|
|
|
|
2020-04-16 08:35:21 -04:00
|
|
|
if (msg.is_write () && (state.n_val () > 0)) {
|
2020-08-29 14:06:00 -04:00
|
|
|
mixer ().strip (strip_id).set_gain (state.nth_val (0));
|
2020-02-23 10:03:59 -05:00
|
|
|
} else {
|
2020-08-29 14:06:00 -04:00
|
|
|
update (client, Node::strip_gain, strip_id, mixer ().strip (strip_id).gain ());
|
2020-02-23 10:03:59 -05:00
|
|
|
}
|
2020-02-20 07:12:36 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
WebsocketsDispatcher::strip_pan_handler (Client client, const NodeStateMessage& msg)
|
|
|
|
{
|
2020-04-16 08:35:21 -04:00
|
|
|
const NodeState& state = msg.state ();
|
2020-02-20 07:12:36 -05:00
|
|
|
|
2020-04-16 08:35:21 -04:00
|
|
|
if (state.n_addr () < 1) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
uint32_t strip_id = state.nth_addr (0);
|
|
|
|
|
|
|
|
if (msg.is_write () && (state.n_val () > 0)) {
|
2020-08-29 14:06:00 -04:00
|
|
|
mixer ().strip (strip_id).set_pan (state.nth_val (0));
|
2020-02-23 10:03:59 -05:00
|
|
|
} else {
|
2020-08-29 14:06:00 -04:00
|
|
|
update (client, Node::strip_pan, strip_id, mixer ().strip (strip_id).pan ());
|
2020-02-23 10:03:59 -05:00
|
|
|
}
|
2020-02-20 07:12:36 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
WebsocketsDispatcher::strip_mute_handler (Client client, const NodeStateMessage& msg)
|
|
|
|
{
|
2020-04-16 08:35:21 -04:00
|
|
|
const NodeState& state = msg.state ();
|
|
|
|
|
|
|
|
if (state.n_addr () < 1) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
uint32_t strip_id = state.nth_addr (0);
|
2020-02-20 07:12:36 -05:00
|
|
|
|
2020-04-16 08:35:21 -04:00
|
|
|
if (msg.is_write () && (state.n_val () > 0)) {
|
2020-08-29 14:06:00 -04:00
|
|
|
mixer ().strip (strip_id).set_mute (state.nth_val (0));
|
2020-02-23 10:03:59 -05:00
|
|
|
} else {
|
2020-08-29 14:06:00 -04:00
|
|
|
update (client, Node::strip_mute, strip_id, mixer ().strip (strip_id).mute ());
|
2020-02-23 10:03:59 -05:00
|
|
|
}
|
2020-02-20 07:12:36 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
WebsocketsDispatcher::strip_plugin_enable_handler (Client client, const NodeStateMessage& msg)
|
|
|
|
{
|
2020-04-16 08:35:21 -04:00
|
|
|
const NodeState& state = msg.state ();
|
|
|
|
|
|
|
|
if (state.n_addr () < 2) {
|
|
|
|
return;
|
|
|
|
}
|
2020-02-23 10:03:59 -05:00
|
|
|
|
2020-04-16 08:35:21 -04:00
|
|
|
uint32_t strip_id = state.nth_addr (0);
|
|
|
|
uint32_t plugin_id = state.nth_addr (1);
|
|
|
|
|
|
|
|
if (msg.is_write () && (state.n_val () > 0)) {
|
2020-08-29 14:06:00 -04:00
|
|
|
mixer ().strip (strip_id).plugin (plugin_id).set_enabled (state.nth_val (0));
|
2020-02-23 10:03:59 -05:00
|
|
|
} else {
|
|
|
|
update (client, Node::strip_plugin_enable, strip_id, plugin_id,
|
2020-08-29 14:06:00 -04:00
|
|
|
mixer ().strip (strip_id).plugin (plugin_id).enabled ());
|
2020-02-23 10:03:59 -05:00
|
|
|
}
|
2020-02-20 07:12:36 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
WebsocketsDispatcher::strip_plugin_param_value_handler (Client client, const NodeStateMessage& msg)
|
|
|
|
{
|
2020-04-16 08:35:21 -04:00
|
|
|
const NodeState& state = msg.state ();
|
|
|
|
|
|
|
|
if (state.n_addr () < 3) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
uint32_t strip_id = state.nth_addr (0);
|
|
|
|
uint32_t plugin_id = state.nth_addr (1);
|
|
|
|
uint32_t param_id = state.nth_addr (2);
|
2020-02-23 10:03:59 -05:00
|
|
|
|
2020-04-16 08:35:21 -04:00
|
|
|
if (msg.is_write () && (state.n_val () > 0)) {
|
2020-08-29 14:06:00 -04:00
|
|
|
mixer ().strip (strip_id).plugin (plugin_id).set_param_value (param_id,
|
2020-04-16 08:35:21 -04:00
|
|
|
state.nth_val (0));
|
2020-02-23 10:03:59 -05:00
|
|
|
} else {
|
2020-08-29 14:06:00 -04:00
|
|
|
TypedValue value = mixer ().strip (strip_id).plugin (plugin_id).param_value (param_id);
|
2020-02-23 10:03:59 -05:00
|
|
|
update (client, Node::strip_plugin_param_value, strip_id, plugin_id, param_id, value);
|
|
|
|
}
|
2020-02-22 07:50:24 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
WebsocketsDispatcher::update (Client client, std::string node, TypedValue val1)
|
|
|
|
{
|
2020-02-23 10:03:59 -05:00
|
|
|
update (client, node, ADDR_NONE, ADDR_NONE, ADDR_NONE, val1);
|
2020-02-22 07:50:24 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2020-08-29 18:42:07 -04:00
|
|
|
WebsocketsDispatcher::update (Client client, std::string node, uint32_t strip_id, TypedValue val1)
|
2020-02-22 07:50:24 -05:00
|
|
|
{
|
2020-08-29 18:42:07 -04:00
|
|
|
update (client, node, strip_id, ADDR_NONE, ADDR_NONE, val1);
|
2020-02-22 07:50:24 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2020-08-29 18:42:07 -04:00
|
|
|
WebsocketsDispatcher::update (Client client, std::string node, uint32_t strip_id, uint32_t plugin_id,
|
2020-02-23 10:03:59 -05:00
|
|
|
TypedValue val1)
|
2020-02-22 07:50:24 -05:00
|
|
|
{
|
2020-08-29 18:42:07 -04:00
|
|
|
update (client, node, strip_id, plugin_id, ADDR_NONE, val1);
|
2020-02-22 07:50:24 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2020-08-29 18:42:07 -04:00
|
|
|
WebsocketsDispatcher::update (Client client, std::string node, uint32_t strip_id, uint32_t plugin_id,
|
|
|
|
uint32_t param_id, TypedValue val1)
|
2020-02-22 07:50:24 -05:00
|
|
|
{
|
2020-02-23 10:03:59 -05:00
|
|
|
AddressVector addr = AddressVector ();
|
2020-02-22 07:50:24 -05:00
|
|
|
|
2020-08-29 18:42:07 -04:00
|
|
|
if (strip_id != ADDR_NONE) {
|
|
|
|
addr.push_back (strip_id);
|
2020-02-23 10:03:59 -05:00
|
|
|
}
|
2020-02-22 07:50:24 -05:00
|
|
|
|
2020-08-29 18:42:07 -04:00
|
|
|
if (plugin_id != ADDR_NONE) {
|
|
|
|
addr.push_back (plugin_id);
|
2020-02-23 10:03:59 -05:00
|
|
|
}
|
2020-02-22 07:50:24 -05:00
|
|
|
|
2020-08-29 18:42:07 -04:00
|
|
|
if (param_id != ADDR_NONE) {
|
|
|
|
addr.push_back (param_id);
|
2020-02-23 10:03:59 -05:00
|
|
|
}
|
2020-02-22 07:50:24 -05:00
|
|
|
|
2020-02-23 10:03:59 -05:00
|
|
|
ValueVector val = ValueVector ();
|
2020-02-22 07:50:24 -05:00
|
|
|
|
2020-02-23 10:03:59 -05:00
|
|
|
if (!val1.empty ()) {
|
|
|
|
val.push_back (val1);
|
|
|
|
}
|
2020-02-22 07:50:24 -05:00
|
|
|
|
2020-02-23 10:03:59 -05:00
|
|
|
update (client, node, addr, val);
|
2020-02-20 07:12:36 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2020-02-22 07:50:24 -05:00
|
|
|
WebsocketsDispatcher::update (Client client, std::string node, const AddressVector& addr,
|
2020-02-23 10:03:59 -05:00
|
|
|
const ValueVector& val)
|
2020-02-20 07:12:36 -05:00
|
|
|
{
|
2020-02-23 10:03:59 -05:00
|
|
|
server ().update_client (client, NodeState (node, addr, val), true);
|
2020-02-20 07:12:36 -05:00
|
|
|
}
|