make StepEntry into a singleton.

More work to follow to clean up the details, and more comments to
explain the relationship between StepEntry and StepEditor.
This commit is contained in:
Paul Davis
2018-12-22 14:45:28 -05:00
parent fb1387b740
commit 126def9e1a
4 changed files with 158 additions and 127 deletions

View File

@@ -35,7 +35,6 @@ using namespace std;
StepEditor::StepEditor (PublicEditor& e, boost::shared_ptr<MidiTrack> t, MidiTimeAxisView& mtv)
: _editor (e)
, _track (t)
, step_editor (0)
, _mtv (mtv)
{
step_edit_insert_position = 0;
@@ -52,7 +51,7 @@ StepEditor::StepEditor (PublicEditor& e, boost::shared_ptr<MidiTrack> t, MidiTim
StepEditor::~StepEditor()
{
delete step_editor;
StepEntry::instance().set_step_editor (0);
}
void
@@ -73,16 +72,14 @@ StepEditor::start_step_editing ()
assert (step_edit_region);
assert (step_edit_region_view);
if (step_editor == 0) {
step_editor = new StepEntry (*this);
step_editor->signal_delete_event().connect (sigc::mem_fun (*this, &StepEditor::step_editor_hidden));
step_editor->signal_hide().connect (sigc::mem_fun (*this, &StepEditor::step_editor_hide));
}
StepEntry::instance().set_step_editor (this);
StepEntry::instance().signal_delete_event().connect (sigc::mem_fun (*this, &StepEditor::step_entry_hidden));
StepEntry::instance(). signal_hide().connect (sigc::mem_fun (*this, &StepEditor::step_entry_hide));
step_edit_region_view->show_step_edit_cursor (step_edit_beat_pos);
step_edit_region_view->set_step_edit_cursor_width (step_editor->note_length());
step_edit_region_view->set_step_edit_cursor_width (StepEntry::instance().note_length());
step_editor->present ();
StepEntry::instance().present ();
}
void
@@ -149,14 +146,14 @@ StepEditor::reset_step_edit_beat_pos ()
}
bool
StepEditor::step_editor_hidden (GdkEventAny*)
StepEditor::step_entry_hidden (GdkEventAny*)
{
step_editor_hide ();
step_entry_hide ();
return true; // XXX remember position ?!
}
void
StepEditor::step_editor_hide ()
StepEditor::step_entry_hide ()
{
/* everything else will follow the change in the model */
_track->set_step_editing (false);
@@ -165,9 +162,7 @@ StepEditor::step_editor_hide ()
void
StepEditor::stop_step_editing ()
{
if (step_editor) {
step_editor->hide ();
}
StepEntry::instance().hide ();
if (step_edit_region_view) {
step_edit_region_view->hide_step_edit_cursor();
@@ -256,14 +251,14 @@ StepEditor::step_add_note (uint8_t channel, uint8_t pitch, uint8_t velocity, Tem
prepare_step_edit_region ();
reset_step_edit_beat_pos ();
step_edit_region_view->show_step_edit_cursor (step_edit_beat_pos);
step_edit_region_view->set_step_edit_cursor_width (step_editor->note_length());
step_edit_region_view->set_step_edit_cursor_width (StepEntry::instance().note_length());
}
assert (step_edit_region);
assert (step_edit_region_view);
if (beat_duration == 0.0 && step_editor) {
beat_duration = step_editor->note_length();
if (beat_duration == 0.0) {
beat_duration = StepEntry::instance().note_length();
} else if (beat_duration == 0.0) {
bool success;
beat_duration = _editor.get_grid_type_as_beats (success, step_edit_insert_position);
@@ -324,7 +319,7 @@ StepEditor::step_add_note (uint8_t channel, uint8_t pitch, uint8_t velocity, Tem
_step_edit_chord_duration = max (_step_edit_chord_duration, beat_duration);
}
step_edit_region_view->set_step_edit_cursor_width (step_editor->note_length());
step_edit_region_view->set_step_edit_cursor_width (StepEntry::instance().note_length());
return 0;
}

View File

@@ -78,15 +78,14 @@ private:
PBD::ScopedConnection step_edit_region_connection;
PublicEditor& _editor;
boost::shared_ptr<ARDOUR::MidiTrack> _track;
StepEntry* step_editor;
MidiTimeAxisView& _mtv;
int8_t last_added_pitch;
Temporal::Beats last_added_end;
void region_removed (boost::weak_ptr<ARDOUR::Region>);
void playlist_changed ();
bool step_editor_hidden (GdkEventAny*);
void step_editor_hide ();
bool step_entry_hidden (GdkEventAny*);
void step_entry_hide ();
void resync_step_edit_position ();
void prepare_step_edit_region ();
};

View File

@@ -46,7 +46,7 @@ using namespace ARDOUR_UI_UTILS;
using namespace ArdourWidgets;
Gtkmm2ext::Bindings* StepEntry::bindings = 0;
StepEntry* StepEntry::_current_step_entry = 0;
StepEntry* StepEntry::_instance = 0;
static void
_note_off_event_handler (GtkWidget* /*widget*/, int note, gpointer arg)
@@ -60,8 +60,18 @@ _rest_event_handler (GtkWidget* /*widget*/, gpointer arg)
((StepEntry*)arg)->rest_event_handler ();
}
StepEntry::StepEntry (StepEditor& seditor)
: ArdourWindow (string_compose (_("Step Entry: %1"), seditor.name()))
StepEntry&
StepEntry::instance()
{
if (!_instance) {
_instance = new StepEntry;
}
return *_instance;
}
StepEntry::StepEntry ()
: ArdourWindow (string())
, _current_note_length (1.0)
, _current_note_velocity (64)
, triplet_button ("3")
@@ -89,27 +99,10 @@ StepEntry::StepEntry (StepEditor& seditor)
, program_button (_("+"))
, _piano (0)
, piano (0)
, se (&seditor)
, se (0)
{
set_data ("ardour-bindings", bindings);
#if 0
/* set channel selector to first selected channel. if none
are selected, it will remain at the value set in its
constructor, above (1)
*/
uint16_t chn_mask = se->channel_selector().get_selected_channels();
for (uint32_t i = 0; i < 16; ++i) {
if (chn_mask & (1<<i)) {
channel_adjustment.set_value (i+1);
break;
}
}
#endif
RadioButtonGroup length_group = length_1_button.get_group();
length_2_button.set_group (length_group);
length_4_button.set_group (length_group);
@@ -473,6 +466,35 @@ StepEntry::~StepEntry()
{
}
void
StepEntry::set_step_editor (StepEditor* seditor)
{
se = seditor;
if (se) {
set_title (string_compose (_("Step Entry: %1"), se->name()));
#if 0
/* set channel selector to first selected channel. if none
are selected, it will remain at the value set in its
constructor, above (1)
*/
uint16_t chn_mask = se->channel_selector().get_selected_channels();
for (uint32_t i = 0; i < 16; ++i) {
if (chn_mask & (1<<i)) {
channel_adjustment.set_value (i+1);
break;
}
}
#endif
} else {
hide ();
}
}
void
StepEntry::length_changed ()
{
@@ -514,7 +536,9 @@ StepEntry::on_key_release_event (GdkEventKey* ev)
void
StepEntry::rest_event_handler ()
{
se->step_edit_rest (Temporal::Beats());
if (se) {
se->step_edit_rest (Temporal::Beats());
}
}
Temporal::Beats
@@ -569,13 +593,17 @@ StepEntry::on_show ()
void
StepEntry::beat_resync_click ()
{
se->step_edit_beat_sync ();
if (se) {
se->step_edit_beat_sync ();
}
}
void
StepEntry::bar_resync_click ()
{
se->step_edit_bar_sync ();
if (se) {
se->step_edit_bar_sync ();
}
}
void
@@ -699,13 +727,17 @@ StepEntry::load_bindings ()
void
StepEntry::toggle_triplet ()
{
se->set_step_edit_cursor_width (note_length());
if (se) {
se->set_step_edit_cursor_width (note_length());
}
}
void
StepEntry::toggle_chord ()
{
se->step_edit_toggle_chord ();
if (se) {
se->step_edit_toggle_chord ();
}
}
void
@@ -752,31 +784,41 @@ StepEntry::dot_value_change ()
dot2_button.set_inconsistent (inconsistent);
dot3_button.set_inconsistent (inconsistent);
se->set_step_edit_cursor_width (note_length());
if (se) {
se->set_step_edit_cursor_width (note_length());
}
}
void
StepEntry::program_click ()
{
se->step_add_program_change (note_channel(), (int8_t) floor (program_adjustment.get_value()));
if (se) {
se->step_add_program_change (note_channel(), (int8_t) floor (program_adjustment.get_value()));
}
}
void
StepEntry::bank_click ()
{
se->step_add_bank_change (note_channel(), (int8_t) floor (bank_adjustment.get_value()));
if (se) {
se->step_add_bank_change (note_channel(), (int8_t) floor (bank_adjustment.get_value()));
}
}
void
StepEntry::insert_rest ()
{
se->step_edit_rest (note_length());
if (se) {
se->step_edit_rest (note_length());
}
}
void
StepEntry::insert_grid_rest ()
{
se->step_edit_rest (Temporal::Beats());
if (se) {
se->step_edit_rest (Temporal::Beats());
}
}
void
@@ -786,7 +828,9 @@ StepEntry::insert_note (uint8_t note)
return;
}
se->step_add_note (note_channel(), note, note_velocity(), note_length());
if (se) {
se->step_add_note (note_channel(), note, note_velocity(), note_length());
}
}
void
StepEntry::insert_c ()
@@ -935,7 +979,6 @@ StepEntry::length_value_change ()
{
RefPtr<Action> act;
RefPtr<RadioAction> ract;
double val = length_divisor_adjustment.get_value();
bool inconsistent = true;
vector<const char*> length_actions;
@@ -964,7 +1007,9 @@ StepEntry::length_value_change ()
length_32_button.set_inconsistent (inconsistent);
length_64_button.set_inconsistent (inconsistent);
se->set_step_edit_cursor_width (note_length());
if (se) {
se->set_step_edit_cursor_width (note_length());
}
}
bool
@@ -1124,31 +1169,23 @@ StepEntry::octave_n (int n)
void
StepEntry::do_sustain ()
{
se->step_edit_sustain (note_length());
if (se) {
se->step_edit_sustain (note_length());
}
}
void
StepEntry::back ()
{
se->move_step_edit_beat_pos (-note_length());
if (se) {
se->move_step_edit_beat_pos (-note_length());
}
}
void
StepEntry::sync_to_edit_point ()
{
se->resync_step_edit_to_edit_point ();
}
bool
StepEntry::on_focus_in_event (GdkEventFocus* ev)
{
_current_step_entry = this;
return ArdourWindow::on_focus_in_event (ev);
}
bool
StepEntry::on_focus_out_event (GdkEventFocus* ev)
{
_current_step_entry = 0;
return ArdourWindow::on_focus_out_event (ev);
if (se) {
se->resync_step_edit_to_edit_point ();
}
}

View File

@@ -35,9 +35,12 @@ class StepEditor;
class StepEntry : public ArdourWindow
{
public:
StepEntry (StepEditor&);
static StepEntry& instance();
~StepEntry ();
void set_step_editor (StepEditor*);
void note_off_event_handler (int note);
void rest_event_handler ();
@@ -49,11 +52,10 @@ class StepEntry : public ArdourWindow
static void setup_actions_and_bindings ();
protected:
bool on_focus_in_event (GdkEventFocus*);
bool on_focus_out_event (GdkEventFocus*);
private:
static StepEntry* _instance;
StepEntry ();
Temporal::Beats _current_note_length;
uint8_t _current_note_velocity;
@@ -198,55 +200,53 @@ class StepEntry : public ArdourWindow
having an actual StepEntry object.
*/
static StepEntry* _current_step_entry;
static void se_insert_rest () { if (_current_step_entry) { _current_step_entry->insert_rest (); } }
static void se_insert_grid_rest () { if (_current_step_entry) { _current_step_entry->insert_grid_rest (); } }
static void se_insert_a () { if (_current_step_entry) { _current_step_entry->insert_a (); } }
static void se_insert_asharp () { if (_current_step_entry) { _current_step_entry->insert_asharp (); } }
static void se_insert_b () { if (_current_step_entry) { _current_step_entry->insert_b (); } }
static void se_insert_c () { if (_current_step_entry) { _current_step_entry->insert_c (); } }
static void se_insert_csharp () { if (_current_step_entry) { _current_step_entry->insert_csharp (); } }
static void se_insert_d () { if (_current_step_entry) { _current_step_entry->insert_d (); } }
static void se_insert_dsharp () { if (_current_step_entry) { _current_step_entry->insert_dsharp (); } }
static void se_insert_e () { if (_current_step_entry) { _current_step_entry->insert_e (); } }
static void se_insert_f () { if (_current_step_entry) { _current_step_entry->insert_f (); } }
static void se_insert_fsharp () { if (_current_step_entry) { _current_step_entry->insert_fsharp (); } }
static void se_insert_g () { if (_current_step_entry) { _current_step_entry->insert_g (); } }
static void se_insert_gsharp () { if (_current_step_entry) { _current_step_entry->insert_gsharp (); } }
static void se_note_length_change (GtkAction* act) { if (_current_step_entry) { _current_step_entry->note_length_change (act); } }
static void se_note_velocity_change (GtkAction* act) { if (_current_step_entry) { _current_step_entry->note_velocity_change (act); } }
static bool se_radio_button_press (GdkEventButton* ev) { if (_current_step_entry) { return _current_step_entry->radio_button_press (ev); } return false; }
static bool se_radio_button_release (GdkEventButton* ev, Gtk::RadioButton* rb, int n) { if (_current_step_entry) { return _current_step_entry->radio_button_release (ev, rb, n); } return false; }
static void se_inc_note_velocity () { if (_current_step_entry) { _current_step_entry->inc_note_velocity (); } }
static void se_dec_note_velocity () { if (_current_step_entry) { _current_step_entry->dec_note_velocity (); } }
static void se_next_note_velocity () { if (_current_step_entry) { _current_step_entry->next_note_velocity (); } }
static void se_prev_note_velocity () { if (_current_step_entry) { _current_step_entry->prev_note_velocity (); } }
static void se_inc_note_length () { if (_current_step_entry) { _current_step_entry->inc_note_length (); } }
static void se_dec_note_length () { if (_current_step_entry) { _current_step_entry->dec_note_length (); } }
static void se_next_note_length () { if (_current_step_entry) { _current_step_entry->next_note_length (); } }
static void se_prev_note_length () { if (_current_step_entry) { _current_step_entry->prev_note_length (); } }
static void se_next_octave () { if (_current_step_entry) { _current_step_entry->next_octave (); } }
static void se_prev_octave () { if (_current_step_entry) { _current_step_entry->prev_octave (); } }
static void se_octave_n (int n) { if (_current_step_entry) { _current_step_entry->octave_n (n); } }
static void se_octave_0 () { if (_current_step_entry) { _current_step_entry->octave_0 (); } }
static void se_octave_1 () { if (_current_step_entry) { _current_step_entry->octave_1 (); } }
static void se_octave_2 () { if (_current_step_entry) { _current_step_entry->octave_2 (); } }
static void se_octave_3 () { if (_current_step_entry) { _current_step_entry->octave_3 (); } }
static void se_octave_4 () { if (_current_step_entry) { _current_step_entry->octave_4 (); } }
static void se_octave_5 () { if (_current_step_entry) { _current_step_entry->octave_5 (); } }
static void se_octave_6 () { if (_current_step_entry) { _current_step_entry->octave_6 (); } }
static void se_octave_7 () { if (_current_step_entry) { _current_step_entry->octave_7 (); } }
static void se_octave_8 () { if (_current_step_entry) { _current_step_entry->octave_8 (); } }
static void se_octave_9 () { if (_current_step_entry) { _current_step_entry->octave_9 (); } }
static void se_octave_10 () { if (_current_step_entry) { _current_step_entry->octave_10 (); } }
static void se_dot_change (GtkAction* act) { if (_current_step_entry) { _current_step_entry->dot_change (act); } }
static void se_dot_value_change () { if (_current_step_entry) { _current_step_entry->dot_value_change (); } }
static void se_toggle_triplet() { if (_current_step_entry) { _current_step_entry->toggle_triplet (); } }
static void se_toggle_chord() { if (_current_step_entry) { _current_step_entry->toggle_chord (); } }
static void se_do_sustain () { if (_current_step_entry) { _current_step_entry->do_sustain (); } }
static void se_back() { if (_current_step_entry) { _current_step_entry->back (); } }
static void se_sync_to_edit_point () { if (_current_step_entry) { _current_step_entry->sync_to_edit_point (); } }
static void se_insert_rest () { if (_instance) { _instance->insert_rest (); } }
static void se_insert_grid_rest () { if (_instance) { _instance->insert_grid_rest (); } }
static void se_insert_a () { if (_instance) { _instance->insert_a (); } }
static void se_insert_asharp () { if (_instance) { _instance->insert_asharp (); } }
static void se_insert_b () { if (_instance) { _instance->insert_b (); } }
static void se_insert_c () { if (_instance) { _instance->insert_c (); } }
static void se_insert_csharp () { if (_instance) { _instance->insert_csharp (); } }
static void se_insert_d () { if (_instance) { _instance->insert_d (); } }
static void se_insert_dsharp () { if (_instance) { _instance->insert_dsharp (); } }
static void se_insert_e () { if (_instance) { _instance->insert_e (); } }
static void se_insert_f () { if (_instance) { _instance->insert_f (); } }
static void se_insert_fsharp () { if (_instance) { _instance->insert_fsharp (); } }
static void se_insert_g () { if (_instance) { _instance->insert_g (); } }
static void se_insert_gsharp () { if (_instance) { _instance->insert_gsharp (); } }
static void se_note_length_change (GtkAction* act) { if (_instance) { _instance->note_length_change (act); } }
static void se_note_velocity_change (GtkAction* act) { if (_instance) { _instance->note_velocity_change (act); } }
static bool se_radio_button_press (GdkEventButton* ev) { if (_instance) { return _instance->radio_button_press (ev); } return false; }
static bool se_radio_button_release (GdkEventButton* ev, Gtk::RadioButton* rb, int n) { if (_instance) { return _instance->radio_button_release (ev, rb, n); } return false; }
static void se_inc_note_velocity () { if (_instance) { _instance->inc_note_velocity (); } }
static void se_dec_note_velocity () { if (_instance) { _instance->dec_note_velocity (); } }
static void se_next_note_velocity () { if (_instance) { _instance->next_note_velocity (); } }
static void se_prev_note_velocity () { if (_instance) { _instance->prev_note_velocity (); } }
static void se_inc_note_length () { if (_instance) { _instance->inc_note_length (); } }
static void se_dec_note_length () { if (_instance) { _instance->dec_note_length (); } }
static void se_next_note_length () { if (_instance) { _instance->next_note_length (); } }
static void se_prev_note_length () { if (_instance) { _instance->prev_note_length (); } }
static void se_next_octave () { if (_instance) { _instance->next_octave (); } }
static void se_prev_octave () { if (_instance) { _instance->prev_octave (); } }
static void se_octave_n (int n) { if (_instance) { _instance->octave_n (n); } }
static void se_octave_0 () { if (_instance) { _instance->octave_0 (); } }
static void se_octave_1 () { if (_instance) { _instance->octave_1 (); } }
static void se_octave_2 () { if (_instance) { _instance->octave_2 (); } }
static void se_octave_3 () { if (_instance) { _instance->octave_3 (); } }
static void se_octave_4 () { if (_instance) { _instance->octave_4 (); } }
static void se_octave_5 () { if (_instance) { _instance->octave_5 (); } }
static void se_octave_6 () { if (_instance) { _instance->octave_6 (); } }
static void se_octave_7 () { if (_instance) { _instance->octave_7 (); } }
static void se_octave_8 () { if (_instance) { _instance->octave_8 (); } }
static void se_octave_9 () { if (_instance) { _instance->octave_9 (); } }
static void se_octave_10 () { if (_instance) { _instance->octave_10 (); } }
static void se_dot_change (GtkAction* act) { if (_instance) { _instance->dot_change (act); } }
static void se_dot_value_change () { if (_instance) { _instance->dot_value_change (); } }
static void se_toggle_triplet() { if (_instance) { _instance->toggle_triplet (); } }
static void se_toggle_chord() { if (_instance) { _instance->toggle_chord (); } }
static void se_do_sustain () { if (_instance) { _instance->do_sustain (); } }
static void se_back() { if (_instance) { _instance->back (); } }
static void se_sync_to_edit_point () { if (_instance) { _instance->sync_to_edit_point (); } }
static void load_bindings ();
static Gtkmm2ext::Bindings* bindings;