2020-02-20 07:12:36 -05:00
|
|
|
/*
|
|
|
|
* Copyright (C) 2020 Luciano Iam <lucianito@gmail.com>
|
|
|
|
*
|
|
|
|
* 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.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "ardour/dB.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;
|
|
|
|
|
|
|
|
int
|
2020-05-30 13:08:27 -04:00
|
|
|
ArdourMixer::start ()
|
2020-02-20 07:12:36 -05:00
|
|
|
{
|
2020-02-23 10:03:59 -05:00
|
|
|
/* take an indexed snapshot of current strips */
|
|
|
|
StripableList strips;
|
|
|
|
session ().get_stripables (strips, PresentationInfo::AllStripables);
|
2020-02-20 07:12:36 -05:00
|
|
|
|
2020-02-23 10:03:59 -05:00
|
|
|
for (StripableList::iterator strip = strips.begin (); strip != strips.end (); ++strip) {
|
|
|
|
_strips.push_back (*strip);
|
|
|
|
}
|
2020-02-20 07:12:36 -05:00
|
|
|
|
2020-02-23 10:03:59 -05:00
|
|
|
return 0;
|
2020-02-20 07:12:36 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
int
|
2020-05-30 13:08:27 -04:00
|
|
|
ArdourMixer::stop ()
|
2020-02-20 07:12:36 -05:00
|
|
|
{
|
2020-02-23 10:03:59 -05:00
|
|
|
_strips.clear ();
|
|
|
|
return 0;
|
2020-02-20 07:12:36 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
double
|
2020-05-30 13:08:27 -04:00
|
|
|
ArdourMixer::to_db (double k)
|
2020-02-20 07:12:36 -05:00
|
|
|
{
|
2020-02-23 10:03:59 -05:00
|
|
|
if (k == 0) {
|
|
|
|
return -std::numeric_limits<double>::infinity ();
|
|
|
|
}
|
2020-02-20 07:12:36 -05:00
|
|
|
|
2020-02-23 10:03:59 -05:00
|
|
|
float db = accurate_coefficient_to_dB (static_cast<float> (k));
|
2020-02-20 07:12:36 -05:00
|
|
|
|
2020-02-23 10:03:59 -05:00
|
|
|
return static_cast<double> (db);
|
2020-02-20 07:12:36 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
double
|
2020-05-30 13:08:27 -04:00
|
|
|
ArdourMixer::from_db (double db)
|
2020-02-20 07:12:36 -05:00
|
|
|
{
|
2020-02-23 10:03:59 -05:00
|
|
|
if (db < -192) {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
float k = dB_to_coefficient (static_cast<float> (db));
|
2020-02-20 07:12:36 -05:00
|
|
|
|
2020-02-23 10:03:59 -05:00
|
|
|
return static_cast<double> (k);
|
2020-02-20 07:12:36 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
double
|
2020-05-30 13:08:27 -04:00
|
|
|
ArdourMixer::strip_gain (uint32_t strip_n) const
|
2020-02-20 07:12:36 -05:00
|
|
|
{
|
2020-02-23 10:03:59 -05:00
|
|
|
return to_db (nth_strip (strip_n)->gain_control ()->get_value ());
|
2020-02-20 07:12:36 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2020-05-30 13:08:27 -04:00
|
|
|
ArdourMixer::set_strip_gain (uint32_t strip_n, double db)
|
2020-02-20 07:12:36 -05:00
|
|
|
{
|
2020-02-23 10:03:59 -05:00
|
|
|
nth_strip (strip_n)->gain_control ()->set_value (from_db (db), PBD::Controllable::NoGroup);
|
2020-02-20 07:12:36 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
double
|
2020-05-30 13:08:27 -04:00
|
|
|
ArdourMixer::strip_pan (uint32_t strip_n) const
|
2020-02-20 07:12:36 -05:00
|
|
|
{
|
2020-02-23 13:12:26 -05:00
|
|
|
boost::shared_ptr<AutomationControl> ac = nth_strip (strip_n)->pan_azimuth_control ();
|
|
|
|
if (!ac) {
|
|
|
|
/* TODO: inform GUI that strip has no panner */
|
|
|
|
return 0;
|
|
|
|
}
|
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-05-30 13:08:27 -04:00
|
|
|
ArdourMixer::set_strip_pan (uint32_t strip_n, double value)
|
2020-02-20 07:12:36 -05:00
|
|
|
{
|
2020-02-23 13:12:26 -05:00
|
|
|
boost::shared_ptr<AutomationControl> ac = nth_strip (strip_n)->pan_azimuth_control ();
|
2020-02-23 09:50:59 -05:00
|
|
|
if (!ac) {
|
|
|
|
return;
|
|
|
|
}
|
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-05-30 13:08:27 -04:00
|
|
|
ArdourMixer::strip_mute (uint32_t strip_n) const
|
2020-02-20 07:12:36 -05:00
|
|
|
{
|
2020-02-23 10:03:59 -05:00
|
|
|
return nth_strip (strip_n)->mute_control ()->muted ();
|
2020-02-20 07:12:36 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2020-05-30 13:08:27 -04:00
|
|
|
ArdourMixer::set_strip_mute (uint32_t strip_n, bool mute)
|
2020-02-20 07:12:36 -05:00
|
|
|
{
|
2020-02-23 10:03:59 -05:00
|
|
|
nth_strip (strip_n)->mute_control ()->set_value (mute ? 1.0 : 0.0, PBD::Controllable::NoGroup);
|
2020-02-20 07:12:36 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
2020-05-30 13:08:27 -04:00
|
|
|
ArdourMixer::strip_plugin_enabled (uint32_t strip_n, uint32_t plugin_n) const
|
2020-02-20 07:12:36 -05:00
|
|
|
{
|
2020-02-23 10:03:59 -05:00
|
|
|
return strip_plugin_insert (strip_n, plugin_n)->enabled ();
|
2020-02-20 07:12:36 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2020-05-30 13:08:27 -04:00
|
|
|
ArdourMixer::set_strip_plugin_enabled (uint32_t strip_n, uint32_t plugin_n, bool enabled)
|
2020-02-20 07:12:36 -05:00
|
|
|
{
|
2020-02-23 10:03:59 -05:00
|
|
|
strip_plugin_insert (strip_n, plugin_n)->enable (enabled);
|
2020-02-20 07:12:36 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
TypedValue
|
2020-05-30 13:08:27 -04:00
|
|
|
ArdourMixer::strip_plugin_param_value (uint32_t strip_n, uint32_t plugin_n,
|
2020-02-23 10:03:59 -05:00
|
|
|
uint32_t param_n) const
|
2020-02-20 07:12:36 -05:00
|
|
|
{
|
2020-02-23 10:03:59 -05:00
|
|
|
return plugin_param_value (strip_plugin_param_control (strip_n, plugin_n, param_n));
|
2020-02-20 07:12:36 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2020-05-30 13:08:27 -04:00
|
|
|
ArdourMixer::set_strip_plugin_param_value (uint32_t strip_n, uint32_t plugin_n,
|
2020-02-23 10:03:59 -05:00
|
|
|
uint32_t param_n, TypedValue value)
|
2020-02-20 07:12:36 -05:00
|
|
|
{
|
2020-02-23 10:03:59 -05:00
|
|
|
boost::shared_ptr<AutomationControl> control = strip_plugin_param_control (
|
|
|
|
strip_n, plugin_n, param_n);
|
2020-02-20 07:12:36 -05:00
|
|
|
|
2020-02-23 10:03:59 -05:00
|
|
|
if (control) {
|
|
|
|
ParameterDescriptor pd = control->desc ();
|
|
|
|
double dbl_val;
|
2020-02-20 07:12:36 -05:00
|
|
|
|
2020-02-23 10:03:59 -05:00
|
|
|
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-20 07:12:36 -05:00
|
|
|
|
2020-02-23 10:03:59 -05:00
|
|
|
control->set_value (dbl_val, PBD::Controllable::NoGroup);
|
|
|
|
}
|
2020-02-20 07:12:36 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
uint32_t
|
2020-05-30 13:08:27 -04:00
|
|
|
ArdourMixer::strip_count () const
|
2020-02-20 07:12:36 -05:00
|
|
|
{
|
2020-02-23 10:03:59 -05:00
|
|
|
return _strips.size ();
|
2020-02-20 07:12:36 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
boost::shared_ptr<Stripable>
|
2020-05-30 13:08:27 -04:00
|
|
|
ArdourMixer::nth_strip (uint32_t strip_n) const
|
2020-02-20 07:12:36 -05:00
|
|
|
{
|
2020-02-23 10:03:59 -05:00
|
|
|
if (strip_n < _strips.size ()) {
|
|
|
|
return _strips[strip_n];
|
|
|
|
}
|
2020-02-20 07:12:36 -05:00
|
|
|
|
2020-02-23 10:03:59 -05:00
|
|
|
return boost::shared_ptr<Stripable> ();
|
2020-02-20 07:12:36 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
TypedValue
|
2020-05-30 13:08:27 -04:00
|
|
|
ArdourMixer::plugin_param_value (boost::shared_ptr<ARDOUR::AutomationControl> control)
|
2020-02-20 07:12:36 -05:00
|
|
|
{
|
2020-02-23 10:03:59 -05:00
|
|
|
TypedValue value = TypedValue ();
|
2020-02-20 07:12:36 -05:00
|
|
|
|
2020-02-23 10:03:59 -05:00
|
|
|
if (control) {
|
|
|
|
ParameterDescriptor pd = control->desc ();
|
|
|
|
|
|
|
|
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 ());
|
|
|
|
}
|
|
|
|
}
|
2020-02-20 07:12:36 -05:00
|
|
|
|
2020-02-23 10:03:59 -05:00
|
|
|
return value;
|
2020-02-20 07:12:36 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
boost::shared_ptr<PluginInsert>
|
2020-05-30 13:08:27 -04:00
|
|
|
ArdourMixer::strip_plugin_insert (uint32_t strip_n, uint32_t plugin_n) const
|
2020-02-20 07:12:36 -05:00
|
|
|
{
|
2020-04-21 09:18:23 -04:00
|
|
|
boost::shared_ptr<Stripable> strip = nth_strip (strip_n);
|
|
|
|
|
|
|
|
if ((strip->presentation_info ().flags () & ARDOUR::PresentationInfo::VCA) == 0) {
|
|
|
|
boost::shared_ptr<Route> route = boost::dynamic_pointer_cast<Route> (strip);
|
|
|
|
|
|
|
|
if (route) {
|
|
|
|
boost::shared_ptr<Processor> processor = route->nth_plugin (plugin_n);
|
2020-02-20 07:12:36 -05:00
|
|
|
|
2020-04-21 09:18:23 -04:00
|
|
|
if (processor) {
|
|
|
|
boost::shared_ptr<PluginInsert> insert =
|
|
|
|
boost::static_pointer_cast<PluginInsert> (processor);
|
2020-02-20 07:12:36 -05:00
|
|
|
|
2020-04-21 09:18:23 -04:00
|
|
|
if (insert) {
|
|
|
|
return insert;
|
|
|
|
}
|
|
|
|
}
|
2020-02-23 10:03:59 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return boost::shared_ptr<PluginInsert> ();
|
2020-02-20 07:12:36 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
boost::shared_ptr<AutomationControl>
|
2020-05-30 13:08:27 -04:00
|
|
|
ArdourMixer::strip_plugin_param_control (uint32_t strip_n, uint32_t plugin_n,
|
2020-02-23 10:03:59 -05:00
|
|
|
uint32_t param_n) const
|
2020-02-20 07:12:36 -05:00
|
|
|
{
|
2020-02-23 10:03:59 -05:00
|
|
|
boost::shared_ptr<PluginInsert> insert = strip_plugin_insert (strip_n, plugin_n);
|
2020-02-20 07:12:36 -05:00
|
|
|
|
2020-02-23 10:03:59 -05:00
|
|
|
if (insert) {
|
|
|
|
bool ok = false;
|
|
|
|
boost::shared_ptr<Plugin> plugin = insert->plugin ();
|
|
|
|
uint32_t control_id = plugin->nth_parameter (param_n, ok);
|
2020-02-20 07:12:36 -05:00
|
|
|
|
2020-02-23 10:03:59 -05:00
|
|
|
if (ok && plugin->parameter_is_input (control_id)) {
|
|
|
|
boost::shared_ptr<AutomationControl> control =
|
|
|
|
insert->automation_control (Evoral::Parameter (PluginAutomation, 0, control_id));
|
|
|
|
return control;
|
|
|
|
}
|
|
|
|
}
|
2020-02-20 07:12:36 -05:00
|
|
|
|
2020-02-23 10:03:59 -05:00
|
|
|
return boost::shared_ptr<AutomationControl> ();
|
2020-02-20 07:12:36 -05:00
|
|
|
}
|