using namespace ARDOUR;
using namespace PBD;
using namespace Editing;
-using namespace ArdourCanvas;
using Gtkmm2ext::Keyboard;
PBD::Signal1<void, MidiRegionView *> MidiRegionView::SelectionCleared;
{
PublicEditor::DropDownKeys.connect (sigc::mem_fun (*this, &MidiRegionView::drop_down_keys));
- NoteBase::CanvasNoteEventDeleted.connect (note_delete_connection, MISSING_INVALIDATOR,
- boost::bind (&MidiRegionView::maybe_remove_deleted_note_from_selection, this, _1),
- gui_context());
-
+ NoteBase::NoteBaseDeleted.connect (note_delete_connection, MISSING_INVALIDATOR,
+ boost::bind (&MidiRegionView::maybe_remove_deleted_note_from_selection, this, _1),
+ gui_context());
+
if (wfd) {
midi_region()->midi_source(0)->load_model();
}
group->canvas_to_item (event_x, event_y);
bool success;
- Evoral::MusicalTime beats = editor.get_grid_type_as_beats (success, editor.pixel_to_frame (event_x));
+ Evoral::MusicalTime beats = editor.get_grid_type_as_beats (success, editor.pixel_to_sample (event_x));
if (!success) {
beats = 1;
*/
beats -= 1.0 / Timecode::BBT_Time::ticks_per_beat;
- create_note_at (editor.pixel_to_frame (event_x), event_y, beats, true);
+ create_note_at (editor.pixel_to_sample (event_x), event_y, beats, true);
}
break;
case MouseDraw:
{
bool success;
- Evoral::MusicalTime beats = editor.get_grid_type_as_beats (success, editor.pixel_to_frame (event_x));
+ Evoral::MusicalTime beats = editor.get_grid_type_as_beats (success, editor.pixel_to_sample (event_x));
if (!success) {
beats = 1;
*/
beats -= 1.0 / Timecode::BBT_Time::ticks_per_beat;
- create_note_at (editor.pixel_to_frame (event_x), event_y, beats, true);
+ create_note_at (editor.pixel_to_sample (event_x), event_y, beats, true);
break;
}
}
void
-MidiRegionView::note_diff_add_change (ArdourCanvas::CanvasNoteEvent* ev,
+MidiRegionView::note_diff_add_change (NoteBase* ev,
MidiModel::NoteDiffCommand::Property property,
uint8_t val)
{
}
void
-MidiRegionView::note_diff_add_change (ArdourCanvas::CanvasNoteEvent* ev,
+MidiRegionView::note_diff_add_change (NoteBase* ev,
MidiModel::NoteDiffCommand::Property property,
Evoral::MusicalTime val)
{
_model->get_notes (notes, op, val, chan_mask);
for (MidiModel::Notes::iterator n = notes.begin(); n != notes.end(); ++n) {
- CanvasNoteEvent* cne = find_canvas_note (*n);
+ NoteBase* cne = find_canvas_note (*n);
if (cne) {
e.push_back (cne);
}
MidiModel::Notes& notes (_model->notes());
_optimization_iterator = _events.begin();
+ bool empty_when_starting = !_events.empty();
+
for (MidiModel::Notes::iterator n = notes.begin(); n != notes.end(); ++n) {
boost::shared_ptr<NoteType> note (*n);
if (note_in_region_range (note, visible)) {
- if ((cne = find_canvas_note (note)) != 0) {
+ if (empty_when_starting && (cne = find_canvas_note (note)) != 0) {
cne->validate ();
} else {
- if ((cne = find_canvas_note (note)) != 0) {
+ if (empty_when_starting && (cne = find_canvas_note (note)) != 0) {
cne->validate ();
cne->hide ();
}
/* remove note items that are no longer valid */
- for (Events::iterator i = _events.begin(); i != _events.end(); ) {
- if (!(*i)->valid ()) {
-
- for (vector<GhostRegion*>::iterator j = ghosts.begin(); j != ghosts.end(); ++j) {
- MidiGhostRegion* gr = dynamic_cast<MidiGhostRegion*> (*j);
- if (gr) {
- gr->remove_note (*i);
+ if (empty_when_starting) {
+ for (Events::iterator i = _events.begin(); i != _events.end(); ) {
+ if (!(*i)->valid ()) {
+
+ for (vector<GhostRegion*>::iterator j = ghosts.begin(); j != ghosts.end(); ++j) {
+ MidiGhostRegion* gr = dynamic_cast<MidiGhostRegion*> (*j);
+ if (gr) {
+ gr->remove_note (*i);
+ }
}
+
+ delete *i;
+ i = _events.erase (i);
+
+ } else {
+ ++i;
}
-
- delete *i;
- i = _events.erase (i);
-
- } else {
- ++i;
}
}
}
string text = str.str();
- const double x = trackview.editor().frame_to_pixel(source_beats_to_region_frames(time));
+ const double x = trackview.editor().sample_to_pixel(source_beats_to_region_frames(time));
double height = midi_stream_view()->contents_height();
- boost::shared_ptr<CanvasSysEx> sysex = boost::shared_ptr<CanvasSysEx>(
- new CanvasSysEx(*this, *_note_group, text, height, x, 1.0, (*i)));
+ // CAIROCANVAS: no longer passing *i (the sysex event) to the
+ // SysEx canvas object!!!
+
+ boost::shared_ptr<SysEx> sysex = boost::shared_ptr<SysEx>(
+ new SysEx (*this, _note_group, text, height, x, 1.0));
// Show unless message is beyond the region bounds
if (time - _region->start() >= _region->length() || time < _region->start()) {
}
for (PatchChanges::iterator x = _patch_changes.begin(); x != _patch_changes.end(); ++x) {
- if ((*x)->width() >= _pixel_width) {
+ if ((*x)->canvas_item()->width() >= _pixel_width) {
(*x)->hide();
} else {
(*x)->show();
midi_stream_view()->highest_note(),
height != old_height + FUDGE);
- if (name_pixbuf) {
- name_pixbuf->raise_to_top();
+ if (name_text) {
+ name_text->raise_to_top();
}
for (PatchChanges::iterator x = _patch_changes.begin(); x != _patch_changes.end(); ++x) {
{
Note* note;
- double unit_position = _region->position () / frames_per_pixel;
+ double unit_position = _region->position () / samples_per_pixel;
MidiTimeAxisView* mtv = dynamic_cast<MidiTimeAxisView*>(&tv);
MidiGhostRegion* ghost;
}
ghost->set_height ();
- ghost->set_duration (_region->length() / frames_per_pixel);
+ ghost->set_duration (_region->length() / samples_per_pixel);
ghosts.push_back (ghost);
GhostRegion::CatchDeletion.connect (*this, invalidator (*this), boost::bind (&RegionView::remove_ghost, this, _1), gui_context());
*/
const framepos_t end_time_frames = region_beats_to_region_frames(end_time);
- _active_notes[note]->set_x1 (trackview.editor().frame_to_pixel(end_time_frames));
+ _active_notes[note]->set_x1 (trackview.editor().sample_to_pixel(end_time_frames));
_active_notes[note]->set_outline_what (0xf);
_active_notes[note] = 0;
}
for (unsigned i=0; i < 128; ++i) {
if (_active_notes[i]) {
- _active_notes[i]->set_x1 (trackview.editor().frame_to_pixel(_region->length()));
+ _active_notes[i]->set_x1 (trackview.editor().sample_to_pixel(_region->length()));
}
}
}
MidiRegionView::update_note (Note* ev, bool update_ghost_regions)
{
boost::shared_ptr<NoteType> note = ev->note();
- const double x = trackview.editor().frame_to_pixel (source_beats_to_region_frames (note->time()));
+ const double x = trackview.editor().sample_to_pixel (source_beats_to_region_frames (note->time()));
const double y0 = midi_stream_view()->note_to_y(note->note());
ev->set_x0 (x);
if (note->length() > 0) {
const framepos_t note_end_frames = min (source_beats_to_region_frames (note->end_time()), _region->length());
- ev->set_x1 (trackview.editor().frame_to_pixel (note_end_frames));
+ ev->set_x1 (trackview.editor().sample_to_pixel (note_end_frames));
} else {
- ev->set_x1 (trackview.editor().frame_to_pixel (_region->length()));
+ ev->set_x1 (trackview.editor().sample_to_pixel (_region->length()));
}
ev->set_y1 (y0 + floor(midi_stream_view()->note_height()));
boost::shared_ptr<NoteType> note = ev->note();
const framepos_t note_start_frames = source_beats_to_region_frames(note->time());
- const double x = trackview.editor().frame_to_pixel(note_start_frames);
+ const double x = trackview.editor().sample_to_pixel(note_start_frames);
const double diamond_size = midi_stream_view()->note_height() / 2.0;
const double y = midi_stream_view()->note_to_y(note->note()) + ((diamond_size-2) / 4.0);
const double diamond_size = midi_stream_view()->note_height() / 2.0;
- Hit* ev_diamond = new CanvasHit (*this, _note_group, diamond_size, note);
+ Hit* ev_diamond = new Hit (*this, _note_group, diamond_size, note);
update_hit (ev_diamond);
* @param active_channel true to display the flag as on an active channel, false to grey it out for an inactive channel.
*/
void
-MidiRegionView::add_canvas_patch_change (MidiModel::PatchChangePtr patch, const string& displaytext, bool active_channel)
+MidiRegionView::add_canvas_patch_change (MidiModel::PatchChangePtr patch, const string& displaytext, bool /*active_channel*/)
{
framecnt_t region_frames = source_beats_to_region_frames (patch->time());
- const double x = trackview.editor().frame_to_pixel (region_frames);
+ const double x = trackview.editor().sample_to_pixel (region_frames);
double const height = midi_stream_view()->contents_height();
- boost::shared_ptr<CanvasPatchChange> patch_change = boost::shared_ptr<CanvasPatchChange>(
- new CanvasPatchChange(*this, group,
- displaytext,
- height,
- x, 1.0,
- instrument_info(),
- patch,
- active_channel));
+ // CAIROCANVAS: active_channel info removed from PatcChange constructor
+ // so we need to do something more sophisticated to keep its color
+ // appearance (MidiPatchChangeFill/MidiPatchChangeInactiveChannelFill)
+ // up to date.
+
+ boost::shared_ptr<PatchChange> patch_change = boost::shared_ptr<PatchChange>(
+ new PatchChange(*this, group,
+ displaytext,
+ height,
+ x, 1.0,
+ instrument_info(),
+ patch));
- if (patch_change->width() < _pixel_width) {
+ if (patch_change->item().width() < _pixel_width) {
// Show unless patch change is beyond the region bounds
if (region_frames < 0 || region_frames >= _region->length()) {
patch_change->hide();
}
void
-MidiRegionView::next_bank (CanvasPatchChange& patch)
+MidiRegionView::next_bank (PatchChange& patch)
{
if (patch.patch()->program() < 127) {
MIDI::Name::PatchPrimaryKey key = patch_change_to_patch_key (patch.patch());
}
void
-MidiRegionView::previous_bank (CanvasPatchChange& patch)
+MidiRegionView::previous_bank (PatchChange& patch)
{
if (patch.patch()->program() > 0) {
MIDI::Name::PatchPrimaryKey key = patch_change_to_patch_key (patch.patch());
}
void
-MidiRegionView::update_drag_selection(double x1, double x2, double y1, double y2, bool extend)
+MidiRegionView::update_drag_selection(double x0, double x1, double y0, double y1, bool extend)
{
// TODO: Make this faster by storing the last updated selection rect, and only
// adjusting things that are in the area that appears/disappeared.
// We probably need a tree to be able to find events in O(log(n)) time.
for (Events::iterator i = _events.begin(); i != _events.end(); ++i) {
- if ((*i)->x1() < x2 && (*i)->x2() > x1 && (*i)->y1() < y2 && (*i)->y2() > y1) {
+ if ((*i)->x0() < x1 && (*i)->x1() > x0 && (*i)->y0() < y1 && (*i)->y1() > y0) {
// Rectangles intersect
if (!(*i)->selected()) {
add_to_selection (*i);
* @return Snapped frame relative to the region position.
*/
framepos_t
-MidiRegionView::snap_pixel_to_frame(double x)
+MidiRegionView::snap_pixel_to_sample(double x)
{
PublicEditor& editor (trackview.editor());
- return snap_frame_to_frame (editor.pixel_to_frame (x));
+ return snap_frame_to_frame (editor.pixel_to_sample (x));
}
/** @param x Pixel relative to the region position.
double
MidiRegionView::snap_to_pixel(double x)
{
- return (double) trackview.editor().frame_to_pixel(snap_pixel_to_frame(x));
+ return (double) trackview.editor().sample_to_pixel(snap_pixel_to_sample(x));
}
double
MidiRegionView::get_position_pixels()
{
framepos_t region_frame = get_position();
- return trackview.editor().frame_to_pixel(region_frame);
+ return trackview.editor().sample_to_pixel(region_frame);
}
double
MidiRegionView::get_end_position_pixels()
{
framepos_t frame = get_position() + get_duration ();
- return trackview.editor().frame_to_pixel(frame);
+ return trackview.editor().sample_to_pixel(frame);
}
framepos_t
_resize_data.clear();
for (Selection::iterator i = _selection.begin(); i != _selection.end(); ++i) {
- Note *note = dynamic_cast<Note**> (*i);
+ Note *note = dynamic_cast<Note*> (*i);
// only insert CanvasNotes into the map
if (note) {
resize_data->note = note;
// create a new SimpleRect from the note which will be the resize preview
- Rectangle *resize_rect = new SimpleRect (_note_group, note->x1(), note->y1(), note->x2(), note->y2());
+ ArdourCanvas::Rectangle *resize_rect = new ArdourCanvas::Rectangle (_note_group,
+ ArdourCanvas::Rect (note->x0(), note->y0(), note->x0(), note->y1()));
// calculate the colors: get the color settings
uint32_t fill_color = UINT_RGBA_CHANGE_A(
// calculate color based on note velocity
resize_rect->set_fill_color (UINT_INTERPOLATE(
- CanvasNoteEvent::meter_style_fill_color(note->note()->velocity(), note->selected()),
+ NoteBase::meter_style_fill_color(note->note()->velocity(), note->selected()),
fill_color,
0.85));
bool cursor_set = false;
for (std::vector<NoteResizeData *>::iterator i = _resize_data.begin(); i != _resize_data.end(); ++i) {
- Rectangle* resize_rect = (*i)->resize_rect;
+ ArdourCanvas::Rectangle* resize_rect = (*i)->resize_rect;
Note* canvas_note = (*i)->note;
double current_x;
if (at_front) {
if (relative) {
- current_x = note->x0() + delta_x;
+ current_x = canvas_note->x0() + delta_x;
} else {
current_x = primary->x0() + delta_x;
}
} else {
if (relative) {
- current_x = note->x1() + delta_x;
+ current_x = canvas_note->x1() + delta_x;
} else {
current_x = primary->x1() + delta_x;
}
if (!cursor_set) {
double beats;
- beats = snap_pixel_to_frame (current_x);
+ beats = snap_pixel_to_sample (current_x);
beats = region_frames_to_region_beats (beats);
double len;
for (std::vector<NoteResizeData *>::iterator i = _resize_data.begin(); i != _resize_data.end(); ++i) {
Note* canvas_note = (*i)->note;
- Rectangle* resize_rect = (*i)->resize_rect;
+ ArdourCanvas::Rectangle* resize_rect = (*i)->resize_rect;
/* Get the new x position for this resize, which is in pixels relative
* to the region position.
if (at_front) {
if (relative) {
- current_x = note->x0() + delta_x;
+ current_x = canvas_note->x0() + delta_x;
} else {
current_x = primary->x0() + delta_x;
}
} else {
if (relative) {
- current_x = note->x1() + delta_x;
+ current_x = canvas_note->x1() + delta_x;
} else {
current_x = primary->x1() + delta_x;
}
}
/* Convert that to a frame within the source */
- current_x = snap_pixel_to_frame (current_x) + _region->start ();
+ current_x = snap_pixel_to_sample (current_x) + _region->start ();
/* and then to beats */
current_x = region_frames_to_region_beats (current_x);
}
void
-MidiRegionView::change_note_channel (NoteBse* event, int8_t chn, bool relative)
+MidiRegionView::change_note_channel (NoteBase* event, int8_t chn, bool relative)
{
uint8_t new_channel;
<< _("Program ") << ((int) p->patch()->program()) + MIDI_BP_ZERO << '\n'
<< _("Channel ") << ((int) p->patch()->channel() + 1);
show_verbose_cursor (s.str(), 10, 20);
- p->grab_focus();
+ p->item().grab_focus();
}
void
}
void
-MidiRegionView::sysex_entered (ArdourCanvas::CanvasSysEx* p)
+MidiRegionView::sysex_entered (SysEx* p)
{
ostringstream s;
- s << p->text();
- show_verbose_cursor (s.str(), 10, 20);
- p->grab_focus();
+ // CAIROCANVAS
+ // need a way to extract text from p->_flag->_text
+ // s << p->text();
+ // show_verbose_cursor (s.str(), 10, 20);
+ p->item().grab_focus();
}
void
-MidiRegionView::sysex_left (ArdourCanvas::CanvasSysEx *)
+MidiRegionView::sysex_left (SysEx *)
{
trackview.editor().verbose_cursor()->hide ();
/* focus will transfer back via the enter-notify event sent to this
}
struct EventNoteTimeEarlyFirstComparator {
- bool operator() (CanvasNoteEvent* a, CanvasNoteEvent* b) {
+ bool operator() (NoteBase* a, NoteBase* b) {
return a->note()->time() < b->note()->time();
}
};
PublicEditor& editor = trackview.editor ();
- framepos_t const unsnapped_frame = editor.pixel_to_frame (x);
+ framepos_t const unsnapped_frame = editor.pixel_to_sample (x);
framecnt_t grid_frames;
framepos_t const f = snap_frame_to_grid_underneath (unsnapped_frame, grid_frames);
if (_step_edit_cursor == 0) {
ArdourCanvas::Group* const group = (ArdourCanvas::Group*)get_canvas_group();
- _step_edit_cursor = new ArdourCanvas::Rectangle (*group);
+ _step_edit_cursor = new ArdourCanvas::Rectangle (group);
_step_edit_cursor->set_y0 (0);
_step_edit_cursor->set_y1 (midi_stream_view()->contents_height());
_step_edit_cursor->set_fill_color (RGBA_TO_UINT (45,0,0,90));
_step_edit_cursor_position = pos;
if (_step_edit_cursor) {
- double pixel = trackview.editor().frame_to_pixel (region_beats_to_region_frames (pos));
+ double pixel = trackview.editor().sample_to_pixel (region_beats_to_region_frames (pos));
_step_edit_cursor->set_x0 (pixel);
set_step_edit_cursor_width (_step_edit_cursor_width);
}
_step_edit_cursor_width = beats;
if (_step_edit_cursor) {
- _step_edit_cursor->set_x1 (_step_edit_cursor->x0() + trackview.editor().frame_to_pixel (region_beats_to_region_frames (beats)));
+ _step_edit_cursor->set_x1 (_step_edit_cursor->x0() + trackview.editor().sample_to_pixel (region_beats_to_region_frames (beats)));
}
}
}
void
-MidiRegionView::delete_sysex (CanvasSysEx* sysex)
+MidiRegionView::delete_sysex (SysEx* /*sysex*/)
{
- MidiModel::SysExDiffCommand* c = _model->new_sysex_diff_command (_("delete sysex"));
- c->remove (sysex->sysex());
- _model->apply_command (*trackview.session(), c);
+ // 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);
- _sys_exes.clear ();
- display_sysexes();
+ //_sys_exes.clear ();
+ // display_sysexes();
}
void
{
double wx, wy;
+ trackview.editor().verbose_cursor()->set_text (text);
trackview.editor().get_pointer_position (wx, wy);
wx += xoffset;
/* Flip the cursor above the mouse pointer if it would overlap the bottom of the canvas */
- double x1, y1, x2, y2;
- trackview.editor().verbose_cursor()->canvas_item()->get_bounds (x1, y1, x2, y2);
+ boost::optional<ArdourCanvas::Rect> bbo = trackview.editor().verbose_cursor()->item().bounding_box();
+
+ assert (bbo);
+
+ ArdourCanvas::Rect bb = bbo.get();
- if ((wy + y2 - y1) > trackview.editor().canvas_height()) {
- wy -= (y2 - y1) + 2 * yoffset;
+ if ((wy + bb.y1 - bb.y0) > trackview.editor().visible_canvas_height()) {
+ wy -= (bb.y1 - bb.y0) + 2 * yoffset;
}
- trackview.editor().verbose_cursor()->set (text, wx, wy);
+ trackview.editor().verbose_cursor()->set_position (wx, wy);
trackview.editor().verbose_cursor()->show ();
}