2009-10-14 12:10:01 -04:00
|
|
|
/*
|
2019-08-02 17:26:43 -04:00
|
|
|
* Copyright (C) 2009-2015 David Robillard <d@drobilla.net>
|
|
|
|
* Copyright (C) 2009-2017 Paul Davis <paul@linuxaudiosystems.com>
|
|
|
|
* Copyright (C) 2010-2012 Carl Hetherington <carl@carlh.net>
|
|
|
|
* Copyright (C) 2014-2017 Robin Gareus <robin@gareus.org>
|
|
|
|
* Copyright (C) 2018 Ben Loftis <ben@harrisonconsoles.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.
|
|
|
|
*/
|
2009-08-27 08:47:04 -04:00
|
|
|
|
2009-10-26 22:36:42 -04:00
|
|
|
#include <gtkmm/stock.h>
|
2010-11-03 22:05:30 -04:00
|
|
|
#include <gtkmm/table.h>
|
2009-08-27 08:47:04 -04:00
|
|
|
#include "gtkmm2ext/utils.h"
|
|
|
|
|
2010-02-18 08:59:49 -05:00
|
|
|
#include "pbd/convert.h"
|
2009-08-27 08:47:04 -04:00
|
|
|
#include "quantize_dialog.h"
|
|
|
|
#include "public_editor.h"
|
|
|
|
|
2016-07-14 14:44:52 -04:00
|
|
|
#include "pbd/i18n.h"
|
2021-03-17 13:27:34 -04:00
|
|
|
#include "pbd/integer_division.h"
|
2009-08-27 08:47:04 -04:00
|
|
|
|
|
|
|
using namespace std;
|
|
|
|
using namespace Gtk;
|
|
|
|
using namespace Gtkmm2ext;
|
|
|
|
using namespace ARDOUR;
|
|
|
|
|
|
|
|
static const gchar *_grid_strings[] = {
|
2018-02-09 10:59:39 -05:00
|
|
|
N_("Main Grid"),
|
2018-05-15 10:52:40 -04:00
|
|
|
N_("1/4 Note"),
|
|
|
|
N_("1/8 Note"),
|
|
|
|
N_("1/16 Note"),
|
|
|
|
N_("1/32 Note"),
|
|
|
|
N_("1/64 Note"),
|
|
|
|
N_("1/128 Note"),
|
|
|
|
|
|
|
|
N_("1/3 (8th triplet)"),
|
|
|
|
N_("1/6 (16th triplet)"),
|
|
|
|
N_("1/12 (32nd triplet)"),
|
|
|
|
|
|
|
|
N_("1/5 (8th quintuplet)"),
|
|
|
|
N_("1/10 (16th quintuplet)"),
|
|
|
|
N_("1/20 (32nd quintuplet)"),
|
|
|
|
|
|
|
|
N_("1/7 (8th septuplet)"),
|
|
|
|
N_("1/14 (16th septuplet)"),
|
|
|
|
N_("1/28 (32nd septuplet)"),
|
|
|
|
|
2009-08-27 08:47:04 -04:00
|
|
|
0
|
|
|
|
};
|
|
|
|
|
2017-08-18 06:49:06 -04:00
|
|
|
static const int _grid_beats[] = {
|
|
|
|
0,
|
2018-05-15 10:52:40 -04:00
|
|
|
1, 2, 4, 8, 16, 32,
|
|
|
|
3, 6, 12,
|
|
|
|
5, 10, 20,
|
|
|
|
7, 14, 28,
|
2017-08-18 06:49:06 -04:00
|
|
|
0
|
|
|
|
};
|
|
|
|
|
2009-08-27 08:47:04 -04:00
|
|
|
std::vector<std::string> QuantizeDialog::grid_strings;
|
|
|
|
|
|
|
|
QuantizeDialog::QuantizeDialog (PublicEditor& e)
|
|
|
|
: ArdourDialog (_("Quantize"), false, false)
|
|
|
|
, editor (e)
|
|
|
|
, strength_adjustment (100.0, 0.0, 100.0, 1.0, 10.0)
|
|
|
|
, strength_spinner (strength_adjustment)
|
|
|
|
, strength_label (_("Strength"))
|
Adjust interpretation of swing amount
Previously,
0 -> no swing (1:1, 50%)
50 -> triplet swing (2:1, 66%)
75 -> hard swing (3:1, 75%)
100 -> sextuplet swing (5:1, 83%) (default!)
150 -> absolute maximum (inf:1, 100%)
This is rather confusing...
One common interpretation uses percentages of the beat, where triplet
swing is 66%. However, that causes precision issues since it's really
66.666...
Since we already default to 100 and take "no swing" as zero, let's make
that reference point triplet swing. Then the scale becomes:
0 -> no swing (1:1)
100 -> triplet swing (2:1)
150 -> hard swing (3:1)
200 -> sextuplet swing (5:1)
300 -> absolute maximum (inf:1)
300 doesn't make any sense, so let's change the range to -250 .. 250
which covers all useful values.
Also remove the division through 100 and back, to avoid rounding issues.
Signed-off-by: Asahi Lina <lina@asahilina.net>
2023-09-09 06:48:43 -04:00
|
|
|
, swing_adjustment (100.0, -250.0, 250.0, 1.0, 10.0)
|
2009-08-27 08:47:04 -04:00
|
|
|
, swing_spinner (swing_adjustment)
|
|
|
|
, swing_button (_("Swing"))
|
2020-07-23 19:46:49 -04:00
|
|
|
, threshold_adjustment (0.0, -Temporal::ticks_per_beat, Temporal::ticks_per_beat, 1.0, 10.0)
|
2009-08-27 08:47:04 -04:00
|
|
|
, threshold_spinner (threshold_adjustment)
|
|
|
|
, threshold_label (_("Threshold (ticks)"))
|
|
|
|
, snap_start_button (_("Snap note start"))
|
|
|
|
, snap_end_button (_("Snap note end"))
|
|
|
|
{
|
|
|
|
if (grid_strings.empty()) {
|
|
|
|
grid_strings = I18N (_grid_strings);
|
|
|
|
}
|
|
|
|
|
|
|
|
set_popdown_strings (start_grid_combo, grid_strings);
|
|
|
|
start_grid_combo.set_active_text (grid_strings.front());
|
|
|
|
set_popdown_strings (end_grid_combo, grid_strings);
|
|
|
|
end_grid_combo.set_active_text (grid_strings.front());
|
|
|
|
|
2010-11-03 22:05:30 -04:00
|
|
|
Table* table = manage (new Table (6, 2));
|
|
|
|
table->set_spacings (12);
|
|
|
|
table->set_border_width (12);
|
|
|
|
|
|
|
|
int r = 0;
|
|
|
|
|
|
|
|
table->attach (snap_start_button, 0, 1, r, r + 1);
|
|
|
|
table->attach (start_grid_combo, 1, 2, r, r + 1);
|
|
|
|
++r;
|
|
|
|
|
|
|
|
table->attach (snap_end_button, 0, 1, r, r + 1);
|
|
|
|
table->attach (end_grid_combo, 1, 2, r, r + 1);
|
|
|
|
++r;
|
|
|
|
|
|
|
|
threshold_label.set_alignment (0, 0.5);
|
|
|
|
table->attach (threshold_label, 0, 1, r, r + 1);
|
|
|
|
table->attach (threshold_spinner, 1, 2, r, r + 1);
|
|
|
|
++r;
|
|
|
|
|
|
|
|
strength_label.set_alignment (0, 0.5);
|
|
|
|
table->attach (strength_label, 0, 1, r, r + 1);
|
|
|
|
table->attach (strength_spinner, 1, 2, r, r + 1);
|
|
|
|
++r;
|
|
|
|
|
|
|
|
table->attach (swing_button, 0, 1, r, r + 1);
|
|
|
|
table->attach (swing_spinner, 1, 2, r, r + 1);
|
2009-08-27 08:47:04 -04:00
|
|
|
|
|
|
|
snap_start_button.set_active (true);
|
|
|
|
snap_end_button.set_active (false);
|
2009-10-26 22:36:42 -04:00
|
|
|
|
2010-11-03 22:05:30 -04:00
|
|
|
get_vbox()->pack_start (*table);
|
2016-09-22 17:22:21 -04:00
|
|
|
get_vbox()->show_all ();
|
2010-11-03 22:05:30 -04:00
|
|
|
|
2009-10-26 22:36:42 -04:00
|
|
|
add_button (Stock::CANCEL, RESPONSE_CANCEL);
|
2011-11-14 08:44:18 -05:00
|
|
|
add_button (_("Quantize"), RESPONSE_OK);
|
2009-08-27 08:47:04 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
QuantizeDialog::~QuantizeDialog()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2021-03-17 13:27:34 -04:00
|
|
|
Temporal::Beats
|
2009-08-27 08:47:04 -04:00
|
|
|
QuantizeDialog::start_grid_size () const
|
|
|
|
{
|
|
|
|
return grid_size_to_musical_time (start_grid_combo.get_active_text ());
|
|
|
|
}
|
|
|
|
|
2021-03-17 13:27:34 -04:00
|
|
|
Temporal::Beats
|
2009-08-27 08:47:04 -04:00
|
|
|
QuantizeDialog::end_grid_size () const
|
|
|
|
{
|
2017-08-18 06:49:34 -04:00
|
|
|
return grid_size_to_musical_time (end_grid_combo.get_active_text ());
|
2009-08-27 08:47:04 -04:00
|
|
|
}
|
|
|
|
|
2021-03-17 13:27:34 -04:00
|
|
|
Temporal::Beats
|
2009-08-27 08:47:04 -04:00
|
|
|
QuantizeDialog::grid_size_to_musical_time (const string& txt) const
|
|
|
|
{
|
2018-05-15 10:36:50 -04:00
|
|
|
if ( txt == _grid_strings[0] ) { //"Main Grid"
|
2009-08-27 08:47:04 -04:00
|
|
|
bool success;
|
|
|
|
|
2021-03-17 13:27:34 -04:00
|
|
|
Temporal::Beats b = editor.get_grid_type_as_beats (success, timepos_t (0));
|
2009-08-27 08:47:04 -04:00
|
|
|
if (!success) {
|
2021-03-17 13:27:34 -04:00
|
|
|
return Temporal::Beats (1, 0);
|
2009-08-27 08:47:04 -04:00
|
|
|
}
|
2021-03-17 13:27:34 -04:00
|
|
|
return b;
|
2009-08-27 08:47:04 -04:00
|
|
|
}
|
|
|
|
|
2016-03-07 10:16:01 -05:00
|
|
|
|
2021-03-17 13:27:34 -04:00
|
|
|
Temporal::Beats b (1, 0);
|
|
|
|
|
2017-09-07 00:08:31 -04:00
|
|
|
for (size_t i = 1; i < grid_strings.size(); ++i) {
|
2017-08-18 06:49:06 -04:00
|
|
|
if (txt == grid_strings[i]) {
|
|
|
|
assert (_grid_beats[i] != 0);
|
2023-09-09 06:01:50 -04:00
|
|
|
b = Temporal::Beats::ticks (int_div_round (Temporal::Beats::PPQN, (int32_t) _grid_beats[i]));
|
2017-08-18 06:49:06 -04:00
|
|
|
break;
|
2016-03-07 10:16:01 -05:00
|
|
|
}
|
2009-08-27 08:47:04 -04:00
|
|
|
}
|
2011-06-01 13:00:29 -04:00
|
|
|
|
2021-03-17 13:27:34 -04:00
|
|
|
return b;
|
2009-08-27 08:47:04 -04:00
|
|
|
}
|
|
|
|
|
2009-10-14 12:10:01 -04:00
|
|
|
float
|
2009-08-27 08:47:04 -04:00
|
|
|
QuantizeDialog::swing () const
|
|
|
|
{
|
|
|
|
if (!swing_button.get_active()) {
|
|
|
|
return 0.0f;
|
|
|
|
}
|
|
|
|
|
|
|
|
return swing_adjustment.get_value ();
|
|
|
|
}
|
|
|
|
|
2009-10-14 12:10:01 -04:00
|
|
|
float
|
2009-08-27 08:47:04 -04:00
|
|
|
QuantizeDialog::strength () const
|
|
|
|
{
|
|
|
|
return strength_adjustment.get_value ();
|
|
|
|
}
|
|
|
|
|
2020-07-13 20:03:18 -04:00
|
|
|
Temporal::Beats
|
2009-08-27 08:47:04 -04:00
|
|
|
QuantizeDialog::threshold () const
|
|
|
|
{
|
2023-09-09 06:12:21 -04:00
|
|
|
return Temporal::Beats::ticks (threshold_adjustment.get_value ());
|
2009-08-27 08:47:04 -04:00
|
|
|
}
|