13
0

some state mgmt for EditingContexts

This commit is contained in:
Paul Davis 2024-02-13 16:32:29 -07:00
parent fcf5bb88d5
commit 0d01e73b86
6 changed files with 122 additions and 80 deletions

View File

@ -36,6 +36,7 @@
#include "ardour_ui.h"
#include "edit_note_dialog.h"
#include "editing_context.h"
#include "editing_convert.h"
#include "editor_drag.h"
#include "keyboard.h"
#include "midi_region_view.h"
@ -2211,3 +2212,88 @@ EditingContext::on_velocity_scroll_event (GdkEventScroll* ev)
set_draw_velocity_to(v);
return true;
}
void
EditingContext::set_common_editing_state (XMLNode const & node)
{
double z;
if (node.get_property ("zoom", z)) {
/* older versions of ardour used floating point samples_per_pixel */
reset_zoom (llrintf (z));
} else {
reset_zoom (samples_per_pixel);
}
GridType grid_type;
if (!node.get_property ("grid-type", grid_type)) {
grid_type = _grid_type;
}
grid_type_selection_done (grid_type);
GridType draw_length;
if (!node.get_property ("draw-length", draw_length)) {
draw_length = _draw_length;
}
draw_length_selection_done (draw_length);
int draw_vel;
if (!node.get_property ("draw-velocity", draw_vel)) {
draw_vel = _draw_velocity;
}
draw_velocity_selection_done (draw_vel);
int draw_chan;
if (!node.get_property ("draw-channel", draw_chan)) {
draw_chan = DRAW_CHAN_AUTO;
}
draw_channel_selection_done (draw_chan);
SnapMode sm;
if (node.get_property ("snap-mode", sm)) {
snap_mode_selection_done(sm);
/* set text of Dropdown. in case _snap_mode == SnapOff (default)
* snap_mode_selection_done() will only mark an already active item as active
* which does not trigger set_text().
*/
set_snap_mode (sm);
} else {
set_snap_mode (_snap_mode);
}
node.get_property ("internal-grid-type", internal_grid_type);
node.get_property ("internal-snap-mode", internal_snap_mode);
node.get_property ("pre-internal-grid-type", pre_internal_grid_type);
node.get_property ("pre-internal-snap-mode", pre_internal_snap_mode);
std::string mm_str;
if (node.get_property ("mouse-mode", mm_str)) {
MouseMode m = str2mousemode(mm_str);
set_mouse_mode (m, true);
} else {
set_mouse_mode (MouseObject, true);
}
samplepos_t lf_pos;
if (node.get_property ("left-frame", lf_pos)) {
if (lf_pos < 0) {
lf_pos = 0;
}
reset_x_origin (lf_pos);
}
}
void
EditingContext::get_common_editing_state (XMLNode& node) const
{
node.set_property ("zoom", samples_per_pixel);
node.set_property ("grid-type", _grid_type);
node.set_property ("snap-mode", _snap_mode);
node.set_property ("internal-grid-type", internal_grid_type);
node.set_property ("internal-snap-mode", internal_snap_mode);
node.set_property ("pre-internal-grid-type", pre_internal_grid_type);
node.set_property ("pre-internal-snap-mode", pre_internal_snap_mode);
node.set_property ("draw-length", _draw_length);
node.set_property ("draw-velocity", _draw_velocity);
node.set_property ("draw-channel", _draw_channel);
node.set_property ("left-frame", _leftmost_sample);
}

View File

@ -556,6 +556,9 @@ public:
Editing::MouseMode mouse_mode;
void set_common_editing_state (XMLNode const & node);
void get_common_editing_state (XMLNode& node) const;
private:
static std::queue<EditingContext*> ec_stack;

View File

@ -2213,75 +2213,12 @@ Editor::set_state (const XMLNode& node, int version)
node.get_property ("marker-click-behavior", marker_click_behavior);
marker_click_behavior_selection_done (marker_click_behavior);
double z;
if (node.get_property ("zoom", z)) {
/* older versions of ardour used floating point samples_per_pixel */
reset_zoom (llrintf (z));
} else {
reset_zoom (samples_per_pixel);
}
int32_t cnt;
if (node.get_property ("visible-track-count", cnt)) {
set_visible_track_count (cnt);
}
GridType grid_type;
if (!node.get_property ("grid-type", grid_type)) {
grid_type = _grid_type;
}
grid_type_selection_done (grid_type);
GridType draw_length;
if (!node.get_property ("draw-length", draw_length)) {
draw_length = _draw_length;
}
draw_length_selection_done (draw_length);
int draw_vel;
if (!node.get_property ("draw-velocity", draw_vel)) {
draw_vel = _draw_velocity;
}
draw_velocity_selection_done (draw_vel);
int draw_chan;
if (!node.get_property ("draw-channel", draw_chan)) {
draw_chan = DRAW_CHAN_AUTO;
}
draw_channel_selection_done (draw_chan);
SnapMode sm;
if (node.get_property ("snap-mode", sm)) {
snap_mode_selection_done(sm);
/* set text of Dropdown. in case _snap_mode == SnapOff (default)
* snap_mode_selection_done() will only mark an already active item as active
* which does not trigger set_text().
*/
set_snap_mode (sm);
} else {
set_snap_mode (_snap_mode);
}
node.get_property ("internal-grid-type", internal_grid_type);
node.get_property ("internal-snap-mode", internal_snap_mode);
node.get_property ("pre-internal-grid-type", pre_internal_grid_type);
node.get_property ("pre-internal-snap-mode", pre_internal_snap_mode);
std::string mm_str;
if (node.get_property ("mouse-mode", mm_str)) {
MouseMode m = str2mousemode(mm_str);
set_mouse_mode (m, true);
} else {
set_mouse_mode (MouseObject, true);
}
samplepos_t lf_pos;
if (node.get_property ("left-frame", lf_pos)) {
if (lf_pos < 0) {
lf_pos = 0;
}
reset_x_origin (lf_pos);
}
set_common_editing_state (node);
double y_origin;
if (node.get_property ("y-origin", y_origin)) {
@ -2415,23 +2352,13 @@ Editor::get_state () const
node->set_property ("zoom-focus", zoom_focus);
node->set_property ("zoom", samples_per_pixel);
node->set_property ("grid-type", _grid_type);
node->set_property ("snap-mode", _snap_mode);
node->set_property ("internal-grid-type", internal_grid_type);
node->set_property ("internal-snap-mode", internal_snap_mode);
node->set_property ("pre-internal-grid-type", pre_internal_grid_type);
node->set_property ("pre-internal-snap-mode", pre_internal_snap_mode);
node->set_property ("edit-point", _edit_point);
node->set_property ("visible-track-count", _visible_track_count);
node->set_property ("marker-click-behavior", marker_click_behavior);
node->set_property ("draw-length", _draw_length);
node->set_property ("draw-velocity", _draw_velocity);
node->set_property ("draw-channel", _draw_channel);
get_common_editing_state (*node);
node->set_property ("playhead", _playhead_cursor->current_sample ());
node->set_property ("left-frame", _leftmost_sample);
node->set_property ("y-origin", vertical_adjustment.get_value ());
node->set_property ("maximised", _maximised);

View File

@ -154,12 +154,12 @@ MidiCueEditor::setup_toolbar ()
Gtk::HBox* _toolbar_inner = manage (new Gtk::HBox);
Gtk::HBox* _toolbar_outer = manage (new Gtk::HBox);
_toolbar_inner->pack_start (*mouse_mode_box, false, true);
_toolbar_inner->pack_start (snap_box, false, true);
_toolbar_inner->pack_start (grid_box, false, true);
_toolbar_inner->pack_start (draw_box, false, true);
_toolbar_inner->pack_start (*mouse_mode_box, false, false);
_toolbar_inner->pack_start (snap_box, false, false);
_toolbar_inner->pack_start (grid_box, false, false);
_toolbar_inner->pack_start (draw_box, false, false);
_toolbar_outer->pack_start (*_toolbar_inner, true, true);
_toolbar_outer->pack_start (*_toolbar_inner, true, false);
_toolbox.pack_start (*_toolbar_outer, false, false);
Bindings* pr_bindings = Bindings::get_bindings (X_("Pianoroll"));
@ -1009,3 +1009,18 @@ MidiCueEditor::mouse_mode_toggled (Editing::MouseMode m)
_canvas->re_enter ();
}
}
int
MidiCueEditor::set_state (XMLNode const & node, int version)
{
set_common_editing_state (node);
return 0;
}
XMLNode&
MidiCueEditor::get_state () const
{
XMLNode* node (new XMLNode (_("MIDICueEditor")));
get_common_editing_state (*node);
return *node;
}

View File

@ -87,6 +87,9 @@ class MidiCueEditor : public CueEditor
ArdourCanvas::GtkCanvasViewport* get_canvas_viewport() const;
ArdourCanvas::Canvas* get_canvas() const;
int set_state (const XMLNode&, int version);
XMLNode& get_state () const;
protected:
Temporal::timepos_t snap_to_grid (Temporal::timepos_t const & start,
Temporal::RoundMode direction,

View File

@ -224,6 +224,8 @@ TriggerPage::get_state () const
node->set_property (X_("triggerpage-hpane-pos"), _pane_upper.get_divider ());
node->set_property (X_("triggerpage-sidebar-page"), _sidebar_notebook.get_current_page ());
node->add_child_nocopy (_midi_editor->get_state());
return *node;
}
@ -234,6 +236,12 @@ TriggerPage::set_state (const XMLNode& node, int version)
if (node.get_property (X_("triggerpage-sidebar-page"), sidebar_page)) {
_sidebar_notebook.set_current_page (sidebar_page);
}
XMLNode* mn = node.child (X_("MIDICueEditor"));
if (mn) {
_midi_editor->set_state (*mn, version);
}
return Tabbable::set_state (node, version);
}