13
0

Add GUI support to remove SysEx Events

This commit is contained in:
Robin Gareus 2024-09-08 23:59:56 +02:00
parent 75d2b46ded
commit 3766b22e06
Signed by: rgareus
GPG Key ID: A090BCE02CF57F04
3 changed files with 41 additions and 31 deletions

View File

@ -927,7 +927,6 @@ MidiRegionView::clear_events ()
} }
} }
_note_group->clear (true); _note_group->clear (true);
_events.clear(); _events.clear();
_patch_changes.clear(); _patch_changes.clear();
@ -1460,6 +1459,8 @@ MidiRegionView::display_sysexes()
const std::shared_ptr<MidiRegion> mregion (midi_region()); const std::shared_ptr<MidiRegion> mregion (midi_region());
SysExes to_remove = _sys_exes;
for (MidiModel::SysExes::const_iterator i = _model->sysexes().begin(); i != _model->sysexes().end(); ++i) { for (MidiModel::SysExes::const_iterator i = _model->sysexes().begin(); i != _model->sysexes().end(); ++i) {
MidiModel::SysExPtr sysex_ptr = *i; MidiModel::SysExPtr sysex_ptr = *i;
timepos_t time = timepos_t (sysex_ptr->time()); timepos_t time = timepos_t (sysex_ptr->time());
@ -1490,11 +1491,12 @@ MidiRegionView::display_sysexes()
if (!sysex) { if (!sysex) {
sysex = std::shared_ptr<SysEx>( sysex = std::shared_ptr<SysEx>(
new SysEx (*this, _note_group, text, height, x, 1.0, sysex_ptr)); new SysEx (*this, group, text, height, x, 1.0, sysex_ptr));
_sys_exes.insert (make_pair (sysex_ptr, sysex)); _sys_exes.insert (make_pair (sysex_ptr, sysex));
} else { } else {
sysex->set_height (height); sysex->set_height (height);
sysex->item().set_position (ArdourCanvas::Duple (x, 1.0)); sysex->item().set_position (ArdourCanvas::Duple (x, 1.0));
to_remove.erase (sysex_ptr);
} }
// Show unless message is beyond the region bounds // Show unless message is beyond the region bounds
@ -1504,6 +1506,10 @@ MidiRegionView::display_sysexes()
sysex->show(); sysex->show();
} }
} }
for (auto const& i : to_remove ) {
_sys_exes.erase (i.first);
}
} }
void void
@ -4537,16 +4543,13 @@ MidiRegionView::edit_patch_change (PatchChange* pc)
} }
void void
MidiRegionView::delete_sysex (SysEx* /*sysex*/) MidiRegionView::delete_sysex (SysEx* sysex)
{ {
// CAIROCANVAS MidiModel::SysExDiffCommand* c = _model->new_sysex_diff_command (_("delete sysex"));
// sysyex object doesn't have a pointer to a sysex event c->remove (sysex->sysex ());
// MidiModel::SysExDiffCommand* c = _model->new_sysex_diff_command (_("delete sysex")); _model->apply_diff_command_as_commit (*trackview.session(), c);
// c->remove (sysex->sysex());
// _model->apply_command (*trackview.session(), c);
//_sys_exes.clear (); display_sysexes();
// display_sysexes();
} }
std::string std::string

View File

@ -17,7 +17,13 @@
*/ */
#include <iostream> #include <iostream>
#include "canvas/flag.h" #include "canvas/flag.h"
#include "gtkmm2ext/keyboard.h"
#include "editor.h"
#include "midi_region_view.h"
#include "sys_ex.h" #include "sys_ex.h"
#include "ui_config.h" #include "ui_config.h"
@ -32,6 +38,7 @@ SysEx::SysEx (
double y, double y,
ARDOUR::MidiModel::SysExPtr sysex) ARDOUR::MidiModel::SysExPtr sysex)
: _sysex (sysex) : _sysex (sysex)
, _region (region)
{ {
_flag = new ArdourCanvas::Flag ( _flag = new ArdourCanvas::Flag (
parent, parent,
@ -41,37 +48,34 @@ SysEx::SysEx (
ArdourCanvas::Duple (x, y) ArdourCanvas::Duple (x, y)
); );
_flag->Event.connect (sigc::mem_fun (*this, &SysEx::event_handler));
_flag->set_font_description (UIConfiguration::instance ().get_SmallFont ());
_flag->set_text (text); _flag->set_text (text);
} }
SysEx::~SysEx() SysEx::~SysEx()
{ {
/* do not delete flag because it was added to a parent/container which delete _flag;
will delete it.
*/
_flag = 0;
} }
bool bool
SysEx::event_handler (GdkEvent* ev) SysEx::event_handler (GdkEvent* ev)
{ {
/* XXX: icky dcast */
Editor* e = dynamic_cast<Editor*> (&_region.get_time_axis_view ().editor ());
if (!e->internal_editing ()) {
return false;
}
switch (ev->type) { switch (ev->type) {
case GDK_BUTTON_PRESS: case GDK_BUTTON_PRESS:
if (ev->button.button == 3) { if (Gtkmm2ext::Keyboard::is_delete_event (&ev->button)) {
return true; _region.delete_sysex (this);
} return true;
break; }
default:
case GDK_SCROLL: break;
if (ev->scroll.direction == GDK_SCROLL_UP) {
return true;
} else if (ev->scroll.direction == GDK_SCROLL_DOWN) {
return true;
}
break;
default:
break;
} }
return false; return false;

View File

@ -35,6 +35,8 @@ public:
double y, double y,
ARDOUR::MidiModel::SysExPtr sysex); ARDOUR::MidiModel::SysExPtr sysex);
SysEx (SysEx const&) = delete;
~SysEx (); ~SysEx ();
void hide (); void hide ();
@ -43,12 +45,13 @@ public:
void set_height (ArdourCanvas::Distance h) { _flag->set_height (h); } void set_height (ArdourCanvas::Distance h) { _flag->set_height (h); }
ArdourCanvas::Item& item() const { return *_flag; } ArdourCanvas::Item& item() const { return *_flag; }
ARDOUR::MidiModel::SysExPtr sysex () const { return _sysex; }
private: private:
bool event_handler (GdkEvent* ev); bool event_handler (GdkEvent* ev);
SysEx(const SysEx& rhs){}
ArdourCanvas::Flag* _flag; ArdourCanvas::Flag* _flag;
ARDOUR::MidiModel::SysExPtr _sysex; ARDOUR::MidiModel::SysExPtr _sysex;
MidiRegionView& _region;
}; };
#endif /* __SYSEX_H__ */ #endif /* __SYSEX_H__ */