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

View File

@ -17,7 +17,13 @@
*/
#include <iostream>
#include "canvas/flag.h"
#include "gtkmm2ext/keyboard.h"
#include "editor.h"
#include "midi_region_view.h"
#include "sys_ex.h"
#include "ui_config.h"
@ -32,6 +38,7 @@ SysEx::SysEx (
double y,
ARDOUR::MidiModel::SysExPtr sysex)
: _sysex (sysex)
, _region (region)
{
_flag = new ArdourCanvas::Flag (
parent,
@ -41,35 +48,32 @@ SysEx::SysEx (
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);
}
SysEx::~SysEx()
{
/* do not delete flag because it was added to a parent/container which
will delete it.
*/
_flag = 0;
delete _flag;
}
bool
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) {
case GDK_BUTTON_PRESS:
if (ev->button.button == 3) {
if (Gtkmm2ext::Keyboard::is_delete_event (&ev->button)) {
_region.delete_sysex (this);
return true;
}
break;
case GDK_SCROLL:
if (ev->scroll.direction == GDK_SCROLL_UP) {
return true;
} else if (ev->scroll.direction == GDK_SCROLL_DOWN) {
return true;
}
break;
default:
break;
}

View File

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