#include "transform_dialog.h"
-#include "i18n.h"
+#include "pbd/i18n.h"
-using namespace std;
-using namespace Gtk;
using namespace ARDOUR;
TransformDialog::Model::Model()
Gtk::HBox* add_hbox = Gtk::manage(new Gtk::HBox);
_add_button.add(
- *manage(new Gtk::Image(Gtk::Stock::ADD, Gtk::ICON_SIZE_BUTTON)));
+ *Gtk::manage(new Gtk::Image(Gtk::Stock::ADD, Gtk::ICON_SIZE_BUTTON)));
add_hbox->pack_start(_add_button, false, false);
_add_button.signal_clicked().connect(
sigc::mem_fun(*this, &TransformDialog::add_clicked));
get_vbox()->pack_start(_operations_box, false, false);
get_vbox()->pack_start(*add_hbox, false, false);
- add_button(Stock::CANCEL, Gtk::RESPONSE_CANCEL);
+ add_button(Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL);
add_button(_("Transform"), Gtk::RESPONSE_OK);
show_all();
_seed_chooser->value_spinner.hide();
+ _seed_chooser->source_changed();
}
TransformDialog::ValueChooser::ValueChooser(const Model& model)
spinner.set_digits(2);
break;
case MidiModel::NoteDiffCommand::Channel:
- spinner.get_adjustment()->set_lower(0);
- spinner.get_adjustment()->set_upper(15);
+ spinner.get_adjustment()->set_lower(1);
+ spinner.get_adjustment()->set_upper(16);
spinner.get_adjustment()->set_step_increment(1);
spinner.get_adjustment()->set_page_increment(10);
spinner.set_digits(0);
break;
}
+ spinner.set_value(
+ std::min(spinner.get_adjustment()->get_upper(),
+ std::max(spinner.get_adjustment()->get_lower(), spinner.get_value())));
}
void
}
}
+double
+TransformDialog::ValueChooser::get_value() const
+{
+ const bool is_channel = target_property == MidiModel::NoteDiffCommand::Channel;
+ return value_spinner.get_value() + (is_channel ? -1.0 : 0.0);
+}
+
+double
+TransformDialog::ValueChooser::get_max() const
+{
+ const bool is_channel = target_property == MidiModel::NoteDiffCommand::Channel;
+ return max_spinner.get_value() + (is_channel ? -1.0 : 0.0);
+}
+
void
TransformDialog::ValueChooser::get(std::list<Operation>& ops)
{
if (source == Transform::Value::RANDOM) {
/* Special case: a RANDOM value is always 0..1, so here we produce some
code to produce a random number in a range: "rand value *". */
- const double a = value_spinner.get_value();
- const double b = max_spinner.get_value();
+ const double a = get_value();
+ const double b = get_max();
const double min = std::min(a, b);
const double max = std::max(a, b);
const double range = max - min;
- // "rand range * min +" (i.e. (rand * range) + min)
+ // "rand range * min +" ((rand * range) + min)
ops.push_back(Operation(Operation::PUSH, Value(Value::RANDOM)));
ops.push_back(Operation(Operation::PUSH, Value(range)));
ops.push_back(Operation(Operation::MULT));
/* Special case: hijack NOWHERE for ramps (see above). The language
knows nothing of ramps, we generate code to calculate the
appropriate value here. */
- const double first = value_spinner.get_value();
- const double last = max_spinner.get_value();
+ const double first = get_value();
+ const double last = get_max();
const double rise = last - first;
- // "index rise * n_notes / first +" (i.e. index * rise / n_notes + first)
+ // "index rise * n_notes 1 - / first +" (index * rise / (n_notes - 1) + first)
ops.push_back(Operation(Operation::PUSH, Value(Value::INDEX)));
ops.push_back(Operation(Operation::PUSH, Value(rise)));
ops.push_back(Operation(Operation::MULT));
ops.push_back(Operation(Operation::PUSH, Value(Value::N_NOTES)));
+ ops.push_back(Operation(Operation::PUSH, Value(1)));
+ ops.push_back(Operation(Operation::SUB));
ops.push_back(Operation(Operation::DIV));
ops.push_back(Operation(Operation::PUSH, Value(first)));
ops.push_back(Operation(Operation::ADD));
} else if (val.source == Transform::Value::LITERAL) {
val.value = Variant(
MidiModel::NoteDiffCommand::value_type(target_property),
- value_spinner.get_value());
+ get_value());
}
ops.push_back(Operation(Operation::PUSH, val));
}
pack_start(remove_button, false, false);
remove_button.add(
- *manage(new Gtk::Image(Gtk::Stock::REMOVE, Gtk::ICON_SIZE_BUTTON)));
+ *Gtk::manage(new Gtk::Image(Gtk::Stock::REMOVE, Gtk::ICON_SIZE_BUTTON)));
remove_button.signal_clicked().connect(
sigc::mem_fun(*this, &TransformDialog::OperationChooser::remove_clicked));
show_all();
value_chooser.property_combo.hide();
value_chooser.value_spinner.set_value(1);
+ value_chooser.source_changed();
}
void