diff options
author | Paul Davis <paul@linuxaudiosystems.com> | 2018-09-02 13:23:36 -0400 |
---|---|---|
committer | Paul Davis <paul@linuxaudiosystems.com> | 2018-09-02 13:23:57 -0400 |
commit | 6e419a961e0b17227f4341880055c5690410607c (patch) | |
tree | e7dfe0d5ce26b2fd73b09521e61b76dd8069ad0e | |
parent | 67f733bb9768e60fe7108613b3f9335675c7d08d (diff) |
use boost::shared_ptr<> to manage Button/Pad lifetimes in Push2 code
-rw-r--r-- | libs/surfaces/push2/buttons.cc | 31 | ||||
-rw-r--r-- | libs/surfaces/push2/mix.cc | 11 | ||||
-rw-r--r-- | libs/surfaces/push2/mix.h | 2 | ||||
-rw-r--r-- | libs/surfaces/push2/push2.cc | 42 | ||||
-rw-r--r-- | libs/surfaces/push2/push2.h | 12 | ||||
-rw-r--r-- | libs/surfaces/push2/scale.cc | 6 | ||||
-rw-r--r-- | libs/surfaces/push2/scale.h | 2 | ||||
-rw-r--r-- | libs/surfaces/push2/track_mix.cc | 10 |
8 files changed, 60 insertions, 56 deletions
diff --git a/libs/surfaces/push2/buttons.cc b/libs/surfaces/push2/buttons.cc index 05f68774ec..03d2272af7 100644 --- a/libs/surfaces/push2/buttons.cc +++ b/libs/surfaces/push2/buttons.cc @@ -37,10 +37,10 @@ Push2::build_maps () { /* Pads */ - Pad* pad; + boost::shared_ptr<Pad> pad; #define MAKE_PAD(x,y,nn) \ - pad = new Pad ((x), (y), (nn)); \ + pad.reset (new Pad ((x), (y), (nn))); \ nn_pad_map.insert (std::make_pair (pad->extra(), pad)); MAKE_PAD (0, 0, 92); @@ -110,18 +110,18 @@ Push2::build_maps () /* Now color buttons */ - Button *button; + boost::shared_ptr<Button> button; #define MAKE_COLOR_BUTTON(i,cc) \ - button = new ColorButton ((i), (cc)); \ + button.reset (new ColorButton ((i), (cc))); \ cc_button_map.insert (std::make_pair (button->controller_number(), button)); \ id_button_map.insert (std::make_pair (button->id, button)); #define MAKE_COLOR_BUTTON_PRESS(i,cc,p)\ - button = new ColorButton ((i), (cc), (p)); \ + button.reset (new ColorButton ((i), (cc), (p))); \ cc_button_map.insert (std::make_pair (button->controller_number(), button)); \ id_button_map.insert (std::make_pair (button->id, button)) #define MAKE_COLOR_BUTTON_PRESS_RELEASE_LONG(i,cc,p,r,l) \ - button = new ColorButton ((i), (cc), (p), (r), (l)); \ + button.reset (new ColorButton ((i), (cc), (p), (r), (l))); \ cc_button_map.insert (std::make_pair (button->controller_number(), button)); \ id_button_map.insert (std::make_pair (button->id, button)) @@ -158,19 +158,19 @@ Push2::build_maps () MAKE_COLOR_BUTTON_PRESS (Play, 85, &Push2::button_play); #define MAKE_WHITE_BUTTON(i,cc)\ - button = new WhiteButton ((i), (cc)); \ + button.reset (new WhiteButton ((i), (cc))); \ cc_button_map.insert (std::make_pair (button->controller_number(), button)); \ id_button_map.insert (std::make_pair (button->id, button)) #define MAKE_WHITE_BUTTON_PRESS(i,cc,p)\ - button = new WhiteButton ((i), (cc), (p)); \ + button.reset (new WhiteButton ((i), (cc), (p))); \ cc_button_map.insert (std::make_pair (button->controller_number(), button)); \ id_button_map.insert (std::make_pair (button->id, button)) #define MAKE_WHITE_BUTTON_PRESS_RELEASE(i,cc,p,r) \ - button = new WhiteButton ((i), (cc), (p), (r)); \ + button.reset (new WhiteButton ((i), (cc), (p), (r))); \ cc_button_map.insert (std::make_pair (button->controller_number(), button)); \ id_button_map.insert (std::make_pair (button->id, button)) #define MAKE_WHITE_BUTTON_PRESS_RELEASE_LONG(i,cc,p,r,l) \ - button = new WhiteButton ((i), (cc), (p), (r), (l)); \ + button.reset (new WhiteButton ((i), (cc), (p), (r), (l))); \ cc_button_map.insert (std::make_pair (button->controller_number(), button)); \ id_button_map.insert (std::make_pair (button->id, button)) @@ -615,7 +615,7 @@ Push2::button_select_press () { cerr << "start select\n"; _modifier_state = ModifierState (_modifier_state | ModSelect); - Button* b = id_button_map[Select]; + boost::shared_ptr<Button> b = id_button_map[Select]; b->set_color (Push2::LED::White); b->set_state (Push2::LED::Blinking16th); write (b->state_msg()); @@ -629,7 +629,7 @@ Push2::button_select_release () if (_modifier_state & ModSelect) { cerr << "end select\n"; _modifier_state = ModifierState (_modifier_state & ~(ModSelect)); - Button* b = id_button_map[Select]; + boost::shared_ptr<Button> b = id_button_map[Select]; b->timeout_connection.disconnect (); b->set_color (Push2::LED::White); b->set_state (Push2::LED::OneShot24th); @@ -650,7 +650,7 @@ Push2::button_long_press_timeout (ButtonID id) { if (buttons_down.find (id) != buttons_down.end()) { DEBUG_TRACE (DEBUG::Push2, string_compose ("long press timeout for %1, invoking method\n", id)); - Button* button = id_button_map[id]; + boost::shared_ptr<Button> button = id_button_map[id]; (this->*button->long_press_method) (); } else { DEBUG_TRACE (DEBUG::Push2, string_compose ("long press timeout for %1, expired/cancelled\n", id)); @@ -666,10 +666,11 @@ Push2::button_long_press_timeout (ButtonID id) } void -Push2::start_press_timeout (Button& button, ButtonID id) +Push2::start_press_timeout (boost::shared_ptr<Button> button, ButtonID id) { + assert (button); Glib::RefPtr<Glib::TimeoutSource> timeout = Glib::TimeoutSource::create (500); // milliseconds - button.timeout_connection = timeout->connect (sigc::bind (sigc::mem_fun (*this, &Push2::button_long_press_timeout), id)); + button->timeout_connection = timeout->connect (sigc::bind (sigc::mem_fun (*this, &Push2::button_long_press_timeout), id)); timeout->attach (main_loop()->get_context()); } diff --git a/libs/surfaces/push2/mix.cc b/libs/surfaces/push2/mix.cc index 69ed1ba7a1..573adf432c 100644 --- a/libs/surfaces/push2/mix.cc +++ b/libs/surfaces/push2/mix.cc @@ -175,7 +175,7 @@ MixLayout::show () for (size_t n = 0; n < sizeof (upper_buttons) / sizeof (upper_buttons[0]); ++n) { - Push2::Button* b = p2.button_by_id (upper_buttons[n]); + boost::shared_ptr<Push2::Button> b = p2.button_by_id (upper_buttons[n]); if (b != mode_button) { b->set_color (Push2::LED::DarkGray); @@ -200,7 +200,7 @@ MixLayout::render (Rect const& area, Cairo::RefPtr<Cairo::Context> context) cons void MixLayout::button_upper (uint32_t n) { - Push2::Button* b; + boost::shared_ptr<Push2::Button> b; switch (n) { case 0: vpot_mode = Volume; @@ -267,7 +267,7 @@ MixLayout::show_vpot_mode () for (int s = 0; s < 8; ++s) { if (stripable[s]) { gain_meter[s]->knob->set_controllable (stripable[s]->gain_control()); - boost::shared_ptr<PeakMeter> pm = stripable[s]->peak_meter(); + boost::shared_ptr<PeakMeter> pm = stripable[s]->peak_meter(); if (pm) { gain_meter[s]->meter->set_meter (pm.get()); } else { @@ -601,7 +601,7 @@ MixLayout::switch_bank (uint32_t base) } - Push2::Button* b; + boost::shared_ptr<Push2::Button> b; switch (n) { case 0: @@ -777,6 +777,8 @@ MixLayout::update_meters () MixLayout::GainMeter::GainMeter (Item* parent, Push2& p2) : Container (parent) { + /* knob and meter become owned by their parent on the canvas */ + knob = new Push2Knob (p2, this); knob->set_radius (25); /* leave position at (0,0) */ @@ -784,3 +786,4 @@ MixLayout::GainMeter::GainMeter (Item* parent, Push2& p2) meter = new LevelMeter (p2, this, 90, ArdourCanvas::Meter::Vertical); meter->set_position (Duple (40, -60)); } + diff --git a/libs/surfaces/push2/mix.h b/libs/surfaces/push2/mix.h index c3d12cea49..bf7436a17d 100644 --- a/libs/surfaces/push2/mix.h +++ b/libs/surfaces/push2/mix.h @@ -99,7 +99,7 @@ class MixLayout : public Push2Layout Send1, Send2, Send3, Send4, Send5 }; - Push2::Button* mode_button; + boost::shared_ptr<Push2::Button> mode_button; VPotMode vpot_mode; void show_vpot_mode (); diff --git a/libs/surfaces/push2/push2.cc b/libs/surfaces/push2/push2.cc index baef27ed5f..67c97b14dd 100644 --- a/libs/surfaces/push2/push2.cc +++ b/libs/surfaces/push2/push2.cc @@ -365,7 +365,7 @@ Push2::strip_buttons_off () Lower1, Lower2, Lower3, Lower4, Lower5, Lower6, Lower7, Lower8, }; for (size_t n = 0; n < sizeof (strip_buttons) / sizeof (strip_buttons[0]); ++n) { - Button* b = id_button_map[strip_buttons[n]]; + boost::shared_ptr<Button> b = id_button_map[strip_buttons[n]]; b->set_color (LED::Black); b->set_state (LED::OneShot24th); @@ -387,7 +387,7 @@ Push2::init_buttons (bool startup) }; for (size_t n = 0; n < sizeof (buttons) / sizeof (buttons[0]); ++n) { - Button* b = id_button_map[buttons[n]]; + boost::shared_ptr<Button> b = id_button_map[buttons[n]]; if (startup) { b->set_color (LED::White); @@ -407,7 +407,7 @@ Push2::init_buttons (bool startup) Accent, Note, Session, }; for (size_t n = 0; n < sizeof (off_buttons) / sizeof (off_buttons[0]); ++n) { - Button* b = id_button_map[off_buttons[n]]; + boost::shared_ptr<Button> b = id_button_map[off_buttons[n]]; b->set_color (LED::Black); b->set_state (LED::OneShot24th); @@ -417,7 +417,7 @@ Push2::init_buttons (bool startup) if (!startup) { for (NNPadMap::iterator pi = nn_pad_map.begin(); pi != nn_pad_map.end(); ++pi) { - Pad* pad = pi->second; + boost::shared_ptr<Pad> pad = pi->second; pad->set_color (LED::Black); pad->set_state (LED::OneShot24th); @@ -629,18 +629,18 @@ Push2::handle_midi_controller_message (MIDI::Parser&, MIDI::EventTwoBytes* ev) if (ev->value) { /* any press cancels any pending long press timeouts */ for (set<ButtonID>::iterator x = buttons_down.begin(); x != buttons_down.end(); ++x) { - Button* bb = id_button_map[*x]; + boost::shared_ptr<Button> bb = id_button_map[*x]; bb->timeout_connection.disconnect (); } } if (b != cc_button_map.end()) { - Button* button = b->second; + boost::shared_ptr<Button> button = b->second; if (ev->value) { buttons_down.insert (button->id); - start_press_timeout (*button, button->id); + start_press_timeout (button, button->id); } else { buttons_down.erase (button->id); button->timeout_connection.disconnect (); @@ -781,7 +781,7 @@ Push2::handle_midi_note_on_message (MIDI::Parser& parser, MIDI::EventTwoBytes* e return; } - const Pad * const pad_pressed = pm->second; + boost::shared_ptr<const Pad> pad_pressed = pm->second; pair<FNPadMap::iterator,FNPadMap::iterator> pads_with_note = fn_pad_map.equal_range (pad_pressed->filtered); @@ -790,7 +790,7 @@ Push2::handle_midi_note_on_message (MIDI::Parser& parser, MIDI::EventTwoBytes* e } for (FNPadMap::iterator pi = pads_with_note.first; pi != pads_with_note.second; ++pi) { - Pad* pad = pi->second; + boost::shared_ptr<Pad> pad = pi->second; pad->set_color (contrast_color); pad->set_state (LED::OneShot24th); @@ -819,7 +819,7 @@ Push2::handle_midi_note_off_message (MIDI::Parser&, MIDI::EventTwoBytes* ev) return; } - const Pad * const pad_pressed = pm->second; + boost::shared_ptr<const Pad> const pad_pressed = pm->second; pair<FNPadMap::iterator,FNPadMap::iterator> pads_with_note = fn_pad_map.equal_range (pad_pressed->filtered); @@ -828,7 +828,7 @@ Push2::handle_midi_note_off_message (MIDI::Parser&, MIDI::EventTwoBytes* ev) } for (FNPadMap::iterator pi = pads_with_note.first; pi != pads_with_note.second; ++pi) { - Pad* pad = pi->second; + boost::shared_ptr<Pad> pad = pi->second; if (pad->do_when_pressed == Pad::FlashOn) { pad->set_color (LED::Black); @@ -908,7 +908,7 @@ Push2::notify_record_state_changed () void Push2::notify_transport_state_changed () { - Button* b = id_button_map[Play]; + boost::shared_ptr<Button> b = id_button_map[Play]; if (session->transport_rolling()) { b->set_state (LED::OneShot24th); @@ -916,7 +916,7 @@ Push2::notify_transport_state_changed () } else { /* disable any blink on FixedLength from pending edit range op */ - Button* fl = id_button_map[FixedLength]; + boost::shared_ptr<Button> fl = id_button_map[FixedLength]; fl->set_color (LED::Black); fl->set_state (LED::NoTransition); @@ -1091,7 +1091,7 @@ Push2::start_shift () { cerr << "start shift\n"; _modifier_state = ModifierState (_modifier_state | ModShift); - Button* b = id_button_map[Shift]; + boost::shared_ptr<Button> b = id_button_map[Shift]; b->set_color (LED::White); b->set_state (LED::Blinking16th); write (b->state_msg()); @@ -1103,7 +1103,7 @@ Push2::end_shift () if (_modifier_state & ModShift) { cerr << "end shift\n"; _modifier_state = ModifierState (_modifier_state & ~(ModShift)); - Button* b = id_button_map[Shift]; + boost::shared_ptr<Button> b = id_button_map[Shift]; b->timeout_connection.disconnect (); b->set_color (LED::White); b->set_state (LED::OneShot24th); @@ -1133,7 +1133,7 @@ Push2::pad_filter (MidiBuffer& in, MidiBuffer& out) const NNPadMap::const_iterator nni = nn_pad_map.find (n); if (nni != nn_pad_map.end()) { - Pad const * pad = nni->second; + boost::shared_ptr<const Pad> pad = nni->second; /* shift for output to the shadow port */ if (pad->filtered >= 0) { (*ev).set_note (pad->filtered + (octave_shift*12)); @@ -1368,7 +1368,7 @@ Push2::set_pad_scale (int root, int octave, MusicalMode::Type mode, bool inkey) for (int col = 0; col < 8; ++col) { int index = 36 + (row*8) + col; - Pad* pad = nn_pad_map[index]; + boost::shared_ptr<Pad> pad = nn_pad_map[index]; int notenum; if (notei != mode_vector.end()) { @@ -1406,7 +1406,7 @@ Push2::set_pad_scale (int root, int octave, MusicalMode::Type mode, bool inkey) for (note = 36; note < 100; ++note) { - Pad* pad = nn_pad_map[note]; + boost::shared_ptr<Pad> pad = nn_pad_map[note]; /* Chromatic: all pads play, half-tone steps. Light * those in the scale, and highlight root notes @@ -1487,7 +1487,7 @@ Push2::set_percussive_mode (bool yn) for (int col = 0; col < 4; ++col) { int index = 36 + (row*8) + col; - Pad* pad = nn_pad_map[index]; + boost::shared_ptr<Pad> pad = nn_pad_map[index]; pad->filtered = drum_note; drum_note++; @@ -1499,7 +1499,7 @@ Push2::set_percussive_mode (bool yn) for (int col = 4; col < 8; ++col) { int index = 36 + (row*8) + col; - Pad* pad = nn_pad_map[index]; + boost::shared_ptr<Pad> pad = nn_pad_map[index]; pad->filtered = drum_note; drum_note++; @@ -1581,7 +1581,7 @@ Push2::stripable_selection_changed () tml->set_stripable (first_selected_stripable()); } -Push2::Button* +boost::shared_ptr<Push2::Button> Push2::button_by_id (ButtonID bid) { return id_button_map[bid]; diff --git a/libs/surfaces/push2/push2.h b/libs/surfaces/push2/push2.h index 7c9d147e7d..89982928bd 100644 --- a/libs/surfaces/push2/push2.h +++ b/libs/surfaces/push2/push2.h @@ -352,7 +352,7 @@ class Push2 : public ARDOUR::ControlProtocol ModifierState modifier_state() const { return _modifier_state; } - Button* button_by_id (ButtonID); + boost::shared_ptr<Button> button_by_id (ButtonID); static std::string button_name_by_id (ButtonID); void strip_buttons_off (); @@ -387,16 +387,16 @@ class Push2 : public ARDOUR::ControlProtocol void relax () {} /* map of Buttons by CC */ - typedef std::map<int,Button*> CCButtonMap; + typedef std::map<int,boost::shared_ptr<Button> > CCButtonMap; CCButtonMap cc_button_map; /* map of Buttons by ButtonID */ - typedef std::map<ButtonID,Button*> IDButtonMap; + typedef std::map<ButtonID,boost::shared_ptr<Button> > IDButtonMap; IDButtonMap id_button_map; std::set<ButtonID> buttons_down; std::set<ButtonID> consumed; bool button_long_press_timeout (ButtonID id); - void start_press_timeout (Button&, ButtonID); + void start_press_timeout (boost::shared_ptr<Button>, ButtonID); void init_buttons (bool startup); void init_touch_strip (); @@ -404,12 +404,12 @@ class Push2 : public ARDOUR::ControlProtocol /* map of Pads by note number (the "fixed" note number sent by the * hardware, not the note number generated if the pad is touched) */ - typedef std::map<int,Pad*> NNPadMap; + typedef std::map<int,boost::shared_ptr<Pad> > NNPadMap; NNPadMap nn_pad_map; /* map of Pads by note number they generate (their "filtered" value) */ - typedef std::multimap<int,Pad*> FNPadMap; + typedef std::multimap<int,boost::shared_ptr<Pad> > FNPadMap; FNPadMap fn_pad_map; void set_button_color (ButtonID, uint8_t color_index); diff --git a/libs/surfaces/push2/scale.cc b/libs/surfaces/push2/scale.cc index e5f04604d4..7cc2d423f9 100644 --- a/libs/surfaces/push2/scale.cc +++ b/libs/surfaces/push2/scale.cc @@ -290,7 +290,7 @@ ScaleLayout::button_right () void ScaleLayout::show () { - Push2::Button* b; + boost::shared_ptr<Push2::Button> b; last_vpot = -1; @@ -559,7 +559,7 @@ ScaleLayout::show_root_state () } - Push2::Button* b = p2.button_by_id (bid); + boost::shared_ptr<Push2::Button> b = p2.button_by_id (bid); if (b != root_button) { if (root_button) { @@ -610,7 +610,7 @@ ScaleLayout::menu_rearranged () void ScaleLayout::update_cursor_buttons () { - Push2::Button* b; + boost::shared_ptr<Push2::Button> b; bool change; b = p2.button_by_id (Push2::Up); diff --git a/libs/surfaces/push2/scale.h b/libs/surfaces/push2/scale.h index b87d86986b..6b85930795 100644 --- a/libs/surfaces/push2/scale.h +++ b/libs/surfaces/push2/scale.h @@ -65,7 +65,7 @@ class ScaleLayout : public Push2Layout Push2Menu* scale_menu; int last_vpot; int vpot_delta_cnt; - Push2::Button* root_button; + boost::shared_ptr<Push2::Button> root_button; void build_scale_menu (); PBD::ScopedConnectionList menu_connections; diff --git a/libs/surfaces/push2/track_mix.cc b/libs/surfaces/push2/track_mix.cc index 5c0b111ef9..fb5a5653f0 100644 --- a/libs/surfaces/push2/track_mix.cc +++ b/libs/surfaces/push2/track_mix.cc @@ -177,7 +177,7 @@ TrackMixLayout::show () Push2::Lower5, Push2::Lower6, Push2::Lower7, Push2::Lower8 }; for (size_t n = 0; n < sizeof (lower_buttons) / sizeof (lower_buttons[0]); ++n) { - Push2::Button* b = p2.button_by_id (lower_buttons[n]); + boost::shared_ptr<Push2::Button> b = p2.button_by_id (lower_buttons[n]); b->set_color (Push2::LED::DarkGray); b->set_state (Push2::LED::OneShot24th); p2.write (b->state_msg()); @@ -289,7 +289,7 @@ TrackMixLayout::simple_control_change (boost::shared_ptr<AutomationControl> ac, return; } - Push2::Button* b = p2.button_by_id (bid); + boost::shared_ptr<Push2::Button> b = p2.button_by_id (bid); if (!b) { return; @@ -311,7 +311,7 @@ TrackMixLayout::solo_mute_change () return; } - Push2::Button* b = p2.button_by_id (Push2::Lower2); + boost::shared_ptr<Push2::Button> b = p2.button_by_id (Push2::Lower2); if (b) { boost::shared_ptr<SoloControl> sc = stripable->solo_control(); @@ -402,8 +402,8 @@ TrackMixLayout::monitoring_change () return; } - Push2::Button* b1 = p2.button_by_id (Push2::Lower4); - Push2::Button* b2 = p2.button_by_id (Push2::Lower5); + boost::shared_ptr<Push2::Button> b1 = p2.button_by_id (Push2::Lower4); + boost::shared_ptr<Push2::Button> b2 = p2.button_by_id (Push2::Lower5); uint8_t b1_color; uint8_t b2_color; |