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-08-29 11:16:38 -04:00
|
|
|
#include <boost/lexical_cast.hpp>
|
|
|
|
|
2020-02-20 07:12:36 -05:00
|
|
|
#include "ardour/dB.h"
|
2020-08-29 11:01:35 -04:00
|
|
|
#include "ardour/meter.h"
|
2020-02-23 10:03:59 -05:00
|
|
|
#include "ardour/plugin_insert.h"
|
|
|
|
#include "ardour/session.h"
|
2020-02-20 07:12:36 -05:00
|
|
|
#include "pbd/controllable.h"
|
|
|
|
|
2020-05-30 13:08:27 -04:00
|
|
|
#include "mixer.h"
|
2020-02-20 07:12:36 -05:00
|
|
|
|
|
|
|
using namespace ARDOUR;
|
2020-08-30 15:15:07 -04:00
|
|
|
using namespace ArdourSurface;
|
2020-02-20 07:12:36 -05:00
|
|
|
|
2023-02-16 18:33:28 -05:00
|
|
|
ArdourMixerPlugin::ArdourMixerPlugin (std::shared_ptr<ARDOUR::PluginInsert> insert)
|
2020-08-29 11:01:35 -04:00
|
|
|
: _insert (insert)
|
|
|
|
{}
|
|
|
|
|
2020-08-29 16:41:47 -04:00
|
|
|
ArdourMixerPlugin::~ArdourMixerPlugin ()
|
|
|
|
{
|
2020-08-30 16:50:25 -04:00
|
|
|
drop_connections ();
|
2020-08-29 16:41:47 -04:00
|
|
|
}
|
|
|
|
|
2023-02-16 18:33:28 -05:00
|
|
|
std::shared_ptr<ARDOUR::PluginInsert>
|
2020-08-29 11:01:35 -04:00
|
|
|
ArdourMixerPlugin::insert () const
|
2020-02-20 07:12:36 -05:00
|
|
|
{
|
2020-08-29 11:01:35 -04:00
|
|
|
return _insert;
|
|
|
|
}
|
2020-02-20 07:12:36 -05:00
|
|
|
|
2020-08-29 11:01:35 -04:00
|
|
|
bool
|
|
|
|
ArdourMixerPlugin::enabled () const
|
|
|
|
{
|
2020-08-29 14:06:00 -04:00
|
|
|
return insert ()->enabled ();
|
2020-08-29 11:01:35 -04:00
|
|
|
}
|
2020-02-20 07:12:36 -05:00
|
|
|
|
2020-08-29 11:01:35 -04:00
|
|
|
void
|
|
|
|
ArdourMixerPlugin::set_enabled (bool enabled)
|
|
|
|
{
|
|
|
|
insert ()->enable (enabled);
|
2020-02-20 07:12:36 -05:00
|
|
|
}
|
|
|
|
|
2020-08-29 16:41:47 -04:00
|
|
|
uint32_t
|
|
|
|
ArdourMixerPlugin::param_count () const
|
|
|
|
{
|
|
|
|
return _insert->plugin ()->parameter_count ();
|
|
|
|
}
|
|
|
|
|
2020-08-29 11:01:35 -04:00
|
|
|
TypedValue
|
2020-08-29 18:42:07 -04:00
|
|
|
ArdourMixerPlugin::param_value (uint32_t param_id)
|
2020-02-20 07:12:36 -05:00
|
|
|
{
|
2020-08-29 18:42:07 -04:00
|
|
|
return param_value (param_control (param_id));
|
2020-02-20 07:12:36 -05:00
|
|
|
}
|
|
|
|
|
2020-08-29 11:01:35 -04:00
|
|
|
void
|
2020-08-29 18:42:07 -04:00
|
|
|
ArdourMixerPlugin::set_param_value (uint32_t param_id, TypedValue value)
|
2020-02-20 07:12:36 -05:00
|
|
|
{
|
2023-02-16 18:33:28 -05:00
|
|
|
std::shared_ptr<AutomationControl> control = param_control (param_id);
|
2020-08-29 14:06:00 -04:00
|
|
|
ParameterDescriptor pd = control->desc ();
|
|
|
|
double dbl_val;
|
|
|
|
|
|
|
|
if (pd.toggled) {
|
|
|
|
dbl_val = static_cast<double> (static_cast<bool> (value));
|
|
|
|
} else if (pd.enumeration || pd.integer_step) {
|
|
|
|
dbl_val = static_cast<double> (static_cast<int> (value));
|
|
|
|
} else {
|
|
|
|
dbl_val = static_cast<double> (value);
|
2020-02-23 10:03:59 -05:00
|
|
|
}
|
2020-08-29 14:06:00 -04:00
|
|
|
|
|
|
|
control->set_value (dbl_val, PBD::Controllable::NoGroup);
|
2020-08-29 11:01:35 -04:00
|
|
|
}
|
2020-02-20 07:12:36 -05:00
|
|
|
|
2023-02-16 18:33:28 -05:00
|
|
|
std::shared_ptr<ARDOUR::AutomationControl>
|
2020-08-29 18:42:07 -04:00
|
|
|
ArdourMixerPlugin::param_control (uint32_t param_id) const
|
2020-08-29 11:01:35 -04:00
|
|
|
{
|
|
|
|
bool ok = false;
|
2023-02-16 18:33:28 -05:00
|
|
|
std::shared_ptr<Plugin> plugin = _insert->plugin ();
|
2020-08-29 18:42:07 -04:00
|
|
|
uint32_t control_id = plugin->nth_parameter (param_id, ok);
|
2020-02-20 07:12:36 -05:00
|
|
|
|
2020-08-29 11:01:35 -04:00
|
|
|
if (!ok || !plugin->parameter_is_input (control_id)) {
|
2020-08-30 15:15:33 -04:00
|
|
|
throw ArdourMixerNotFoundException ("invalid automation control for param id = "
|
2020-08-29 18:42:07 -04:00
|
|
|
+ boost::lexical_cast<std::string>(param_id));
|
2020-08-29 11:01:35 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
return _insert->automation_control (Evoral::Parameter (PluginAutomation, 0, control_id));
|
2020-02-20 07:12:36 -05:00
|
|
|
}
|
|
|
|
|
2020-08-29 16:41:47 -04:00
|
|
|
TypedValue
|
2023-02-16 18:33:28 -05:00
|
|
|
ArdourMixerPlugin::param_value (std::shared_ptr<ARDOUR::AutomationControl> control)
|
2020-08-29 16:41:47 -04:00
|
|
|
{
|
|
|
|
ParameterDescriptor pd = control->desc ();
|
|
|
|
TypedValue value = TypedValue ();
|
|
|
|
|
|
|
|
if (pd.toggled) {
|
|
|
|
value = TypedValue (static_cast<bool> (control->get_value ()));
|
|
|
|
} else if (pd.enumeration || pd.integer_step) {
|
|
|
|
value = TypedValue (static_cast<int> (control->get_value ()));
|
|
|
|
} else {
|
|
|
|
value = TypedValue (control->get_value ());
|
|
|
|
}
|
|
|
|
|
|
|
|
return value;
|
|
|
|
}
|
|
|
|
|
2023-02-16 18:33:28 -05:00
|
|
|
ArdourMixerStrip::ArdourMixerStrip (std::shared_ptr<ARDOUR::Stripable> stripable, PBD::EventLoop* event_loop)
|
2020-08-29 11:01:35 -04:00
|
|
|
: _stripable (stripable)
|
2020-02-20 07:12:36 -05:00
|
|
|
{
|
2023-02-16 18:33:28 -05:00
|
|
|
std::shared_ptr<Route> route = std::dynamic_pointer_cast<Route> (_stripable);
|
2020-02-20 07:12:36 -05:00
|
|
|
|
2020-08-29 11:01:35 -04:00
|
|
|
if (!route) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2020-08-29 18:42:07 -04:00
|
|
|
for (uint32_t plugin_id = 0;; ++plugin_id) {
|
2023-02-16 18:33:28 -05:00
|
|
|
std::shared_ptr<Processor> processor = route->nth_plugin (plugin_id);
|
2020-08-29 11:01:35 -04:00
|
|
|
|
2020-08-29 14:06:00 -04:00
|
|
|
if (!processor) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2023-02-16 18:33:28 -05:00
|
|
|
std::shared_ptr<PluginInsert> insert = std::static_pointer_cast<PluginInsert> (processor);
|
2020-08-29 11:01:35 -04:00
|
|
|
|
2020-08-29 14:06:00 -04:00
|
|
|
if (insert) {
|
2023-02-16 18:33:28 -05:00
|
|
|
_plugins[plugin_id] = std::shared_ptr<ArdourMixerPlugin> (new ArdourMixerPlugin (insert));
|
2020-08-30 16:50:25 -04:00
|
|
|
insert->DropReferences.connect (*_plugins[plugin_id], MISSING_INVALIDATOR,
|
|
|
|
boost::bind (&ArdourMixerStrip::on_drop_plugin, this, plugin_id), event_loop);
|
2020-08-29 11:01:35 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-08-29 16:41:47 -04:00
|
|
|
ArdourMixerStrip::~ArdourMixerStrip ()
|
|
|
|
{
|
2020-08-30 16:50:25 -04:00
|
|
|
drop_connections ();
|
2020-08-29 16:41:47 -04:00
|
|
|
}
|
|
|
|
|
2023-02-16 18:33:28 -05:00
|
|
|
std::shared_ptr<ARDOUR::Stripable>
|
2020-08-29 11:01:35 -04:00
|
|
|
ArdourMixerStrip::stripable () const
|
|
|
|
{
|
|
|
|
return _stripable;
|
|
|
|
}
|
|
|
|
|
|
|
|
ArdourMixerPlugin&
|
2020-08-29 18:42:07 -04:00
|
|
|
ArdourMixerStrip::plugin (uint32_t plugin_id)
|
2020-08-29 11:01:35 -04:00
|
|
|
{
|
2020-08-29 18:42:07 -04:00
|
|
|
if (_plugins.find (plugin_id) == _plugins.end ()) {
|
|
|
|
throw ArdourMixerNotFoundException ("plugin id = " + boost::lexical_cast<std::string>(plugin_id) + " not found");
|
2020-08-29 11:01:35 -04:00
|
|
|
}
|
|
|
|
|
2020-08-31 01:52:48 -04:00
|
|
|
return *_plugins[plugin_id];
|
2020-08-29 14:06:00 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
ArdourMixerStrip::PluginMap&
|
|
|
|
ArdourMixerStrip::plugins ()
|
|
|
|
{
|
|
|
|
return _plugins;
|
2020-02-20 07:12:36 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
double
|
2020-08-29 11:01:35 -04:00
|
|
|
ArdourMixerStrip::gain () const
|
2020-02-20 07:12:36 -05:00
|
|
|
{
|
2020-09-05 07:12:04 -04:00
|
|
|
double val = _stripable->gain_control ()->get_value ();
|
|
|
|
return is_midi () ? static_cast<double> (to_velocity (val)) : to_db (val);
|
2020-02-20 07:12:36 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2020-09-05 07:12:04 -04:00
|
|
|
ArdourMixerStrip::set_gain (double gain)
|
2020-02-20 07:12:36 -05:00
|
|
|
{
|
2020-09-05 07:12:04 -04:00
|
|
|
double val = is_midi () ? from_velocity (static_cast<int> (gain)) : from_db (gain);
|
|
|
|
_stripable->gain_control ()->set_value (val, PBD::Controllable::NoGroup);
|
2020-02-20 07:12:36 -05:00
|
|
|
}
|
|
|
|
|
2020-09-01 16:28:00 -04:00
|
|
|
bool
|
|
|
|
ArdourMixerStrip::has_pan () const
|
|
|
|
{
|
|
|
|
return _stripable->pan_azimuth_control () != 0;
|
|
|
|
}
|
|
|
|
|
2020-02-20 07:12:36 -05:00
|
|
|
double
|
2020-08-29 11:01:35 -04:00
|
|
|
ArdourMixerStrip::pan () const
|
2020-02-20 07:12:36 -05:00
|
|
|
{
|
2023-02-16 18:33:28 -05:00
|
|
|
std::shared_ptr<AutomationControl> ac = _stripable->pan_azimuth_control ();
|
2020-08-29 14:06:00 -04:00
|
|
|
|
2020-02-23 13:12:26 -05:00
|
|
|
if (!ac) {
|
2020-08-29 11:16:38 -04:00
|
|
|
throw ArdourMixerNotFoundException ("strip has no panner");
|
2020-02-23 13:12:26 -05:00
|
|
|
}
|
2020-08-29 14:06:00 -04:00
|
|
|
|
2020-07-19 10:31:31 -04:00
|
|
|
return ac->internal_to_interface (ac->get_value ());
|
2020-02-20 07:12:36 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2020-08-29 11:01:35 -04:00
|
|
|
ArdourMixerStrip::set_pan (double value)
|
2020-02-20 07:12:36 -05:00
|
|
|
{
|
2023-02-16 18:33:28 -05:00
|
|
|
std::shared_ptr<AutomationControl> ac = _stripable->pan_azimuth_control ();
|
2020-08-29 14:06:00 -04:00
|
|
|
|
2020-02-23 09:50:59 -05:00
|
|
|
if (!ac) {
|
|
|
|
return;
|
|
|
|
}
|
2020-08-29 14:06:00 -04:00
|
|
|
|
2020-07-19 10:31:31 -04:00
|
|
|
ac->set_value (ac->interface_to_internal (value), PBD::Controllable::NoGroup);
|
2020-02-20 07:12:36 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
2020-08-29 11:01:35 -04:00
|
|
|
ArdourMixerStrip::mute () const
|
2020-02-20 07:12:36 -05:00
|
|
|
{
|
2020-08-29 11:01:35 -04:00
|
|
|
return _stripable->mute_control ()->muted ();
|
2020-02-20 07:12:36 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2020-08-29 11:01:35 -04:00
|
|
|
ArdourMixerStrip::set_mute (bool mute)
|
2020-02-20 07:12:36 -05:00
|
|
|
{
|
2020-08-29 11:01:35 -04:00
|
|
|
_stripable->mute_control ()->set_value (mute ? 1.0 : 0.0, PBD::Controllable::NoGroup);
|
2020-02-20 07:12:36 -05:00
|
|
|
}
|
|
|
|
|
2020-08-29 11:01:35 -04:00
|
|
|
float
|
|
|
|
ArdourMixerStrip::meter_level_db () const
|
2020-02-20 07:12:36 -05:00
|
|
|
{
|
2023-02-16 18:33:28 -05:00
|
|
|
std::shared_ptr<PeakMeter> meter = _stripable->peak_meter ();
|
2020-08-29 11:01:35 -04:00
|
|
|
return meter ? meter->meter_level (0, MeterMCP) : -193;
|
2020-02-20 07:12:36 -05:00
|
|
|
}
|
|
|
|
|
2020-08-29 11:01:35 -04:00
|
|
|
std::string
|
|
|
|
ArdourMixerStrip::name () const
|
2020-02-20 07:12:36 -05:00
|
|
|
{
|
2020-08-29 11:01:35 -04:00
|
|
|
return _stripable->name ();
|
2020-02-20 07:12:36 -05:00
|
|
|
}
|
|
|
|
|
2020-09-05 07:12:04 -04:00
|
|
|
bool
|
|
|
|
ArdourMixerStrip::is_midi () const
|
|
|
|
{
|
2020-11-20 07:32:20 -05:00
|
|
|
return _stripable->presentation_info ().flags () & PresentationInfo::MidiTrack;
|
2020-09-05 07:12:04 -04:00
|
|
|
}
|
|
|
|
|
2020-08-29 11:01:35 -04:00
|
|
|
void
|
2020-08-29 18:42:07 -04:00
|
|
|
ArdourMixerStrip::on_drop_plugin (uint32_t plugin_id)
|
2020-02-20 07:12:36 -05:00
|
|
|
{
|
2020-08-29 18:42:07 -04:00
|
|
|
_plugins.erase (plugin_id);
|
2020-02-20 07:12:36 -05:00
|
|
|
}
|
|
|
|
|
2020-08-29 11:01:35 -04:00
|
|
|
double
|
|
|
|
ArdourMixerStrip::to_db (double k)
|
2020-02-20 07:12:36 -05:00
|
|
|
{
|
2020-08-29 11:01:35 -04:00
|
|
|
if (k == 0) {
|
|
|
|
return -std::numeric_limits<double>::infinity ();
|
2020-02-23 10:03:59 -05:00
|
|
|
}
|
2020-02-20 07:12:36 -05:00
|
|
|
|
2020-08-29 11:01:35 -04:00
|
|
|
float db = accurate_coefficient_to_dB (static_cast<float> (k));
|
|
|
|
|
|
|
|
return static_cast<double> (db);
|
2020-02-20 07:12:36 -05:00
|
|
|
}
|
|
|
|
|
2020-08-29 11:01:35 -04:00
|
|
|
double
|
|
|
|
ArdourMixerStrip::from_db (double db)
|
2020-02-20 07:12:36 -05:00
|
|
|
{
|
2020-08-29 11:01:35 -04:00
|
|
|
if (db < -192) {
|
|
|
|
return 0;
|
2020-02-23 10:03:59 -05:00
|
|
|
}
|
2020-02-20 07:12:36 -05:00
|
|
|
|
2020-08-29 11:01:35 -04:00
|
|
|
float k = dB_to_coefficient (static_cast<float> (db));
|
|
|
|
|
|
|
|
return static_cast<double> (k);
|
2020-02-20 07:12:36 -05:00
|
|
|
}
|
2020-09-05 07:12:04 -04:00
|
|
|
|
|
|
|
int
|
|
|
|
ArdourMixerStrip::to_velocity (double k)
|
|
|
|
{
|
|
|
|
return static_cast<int> (127.0 * k / 2.0);
|
|
|
|
}
|
|
|
|
|
|
|
|
double
|
|
|
|
ArdourMixerStrip::from_velocity (int k)
|
|
|
|
{
|
|
|
|
return 2.0 * static_cast<double> (k) / 127.0;
|
|
|
|
}
|
2020-02-20 07:12:36 -05:00
|
|
|
|
2020-08-29 11:01:35 -04:00
|
|
|
int
|
|
|
|
ArdourMixer::start ()
|
2020-02-20 07:12:36 -05:00
|
|
|
{
|
2020-08-29 16:41:47 -04:00
|
|
|
/* take a snapshot of current strips */
|
2020-08-29 11:01:35 -04:00
|
|
|
StripableList strips;
|
|
|
|
session ().get_stripables (strips, PresentationInfo::AllStripables);
|
2020-08-29 18:42:07 -04:00
|
|
|
uint32_t strip_id = 0;
|
2020-08-29 11:01:35 -04:00
|
|
|
|
|
|
|
for (StripableList::iterator it = strips.begin (); it != strips.end (); ++it) {
|
2023-02-16 18:33:28 -05:00
|
|
|
_strips[strip_id] = std::shared_ptr<ArdourMixerStrip> (new ArdourMixerStrip (*it, event_loop ()));
|
2020-08-30 16:50:25 -04:00
|
|
|
(*it)->DropReferences.connect (*_strips[strip_id], MISSING_INVALIDATOR,
|
|
|
|
boost::bind (&ArdourMixer::on_drop_strip, this, strip_id), event_loop ());
|
2020-08-29 18:42:07 -04:00
|
|
|
strip_id++;
|
2020-02-23 10:03:59 -05:00
|
|
|
}
|
2020-02-20 07:12:36 -05:00
|
|
|
|
2020-08-29 11:01:35 -04:00
|
|
|
return 0;
|
2020-02-20 07:12:36 -05:00
|
|
|
}
|
|
|
|
|
2020-08-29 11:01:35 -04:00
|
|
|
int
|
|
|
|
ArdourMixer::stop ()
|
2020-02-20 07:12:36 -05:00
|
|
|
{
|
2020-08-29 16:41:47 -04:00
|
|
|
Glib::Threads::Mutex::Lock lock (mixer ().mutex ());
|
2020-08-29 11:01:35 -04:00
|
|
|
_strips.clear ();
|
|
|
|
return 0;
|
|
|
|
}
|
2020-02-20 07:12:36 -05:00
|
|
|
|
2020-08-29 14:06:00 -04:00
|
|
|
ArdourMixer::StripMap&
|
|
|
|
ArdourMixer::strips ()
|
2020-08-29 11:01:35 -04:00
|
|
|
{
|
2020-08-29 14:06:00 -04:00
|
|
|
return _strips;
|
2020-08-29 11:01:35 -04:00
|
|
|
}
|
2020-02-20 07:12:36 -05:00
|
|
|
|
2020-08-29 14:06:00 -04:00
|
|
|
|
2020-08-29 11:01:35 -04:00
|
|
|
ArdourMixerStrip&
|
2020-08-29 18:42:07 -04:00
|
|
|
ArdourMixer::strip (uint32_t strip_id)
|
2020-08-29 11:01:35 -04:00
|
|
|
{
|
2020-08-29 18:42:07 -04:00
|
|
|
if (_strips.find (strip_id) == _strips.end ()) {
|
|
|
|
throw ArdourMixerNotFoundException ("strip id = " + boost::lexical_cast<std::string>(strip_id) + " not found");
|
2020-02-23 10:03:59 -05:00
|
|
|
}
|
|
|
|
|
2020-08-31 01:52:48 -04:00
|
|
|
return *_strips[strip_id];
|
2020-02-20 07:12:36 -05:00
|
|
|
}
|
|
|
|
|
2020-08-29 11:01:35 -04:00
|
|
|
void
|
2020-08-29 18:42:07 -04:00
|
|
|
ArdourMixer::on_drop_strip (uint32_t strip_id)
|
2020-02-20 07:12:36 -05:00
|
|
|
{
|
2020-08-29 16:41:47 -04:00
|
|
|
Glib::Threads::Mutex::Lock lock (_mutex);
|
2020-08-29 18:42:07 -04:00
|
|
|
_strips.erase (strip_id);
|
2020-08-29 16:41:47 -04:00
|
|
|
}
|
2020-08-29 11:01:35 -04:00
|
|
|
|
2020-08-29 16:41:47 -04:00
|
|
|
Glib::Threads::Mutex&
|
|
|
|
ArdourMixer::mutex ()
|
|
|
|
{
|
|
|
|
return _mutex;
|
2020-02-20 07:12:36 -05:00
|
|
|
}
|