X-Git-Url: https://main.carlh.net/gitweb/?a=blobdiff_plain;ds=sidebyside;f=gtk2_ardour%2Fpiano_roll_header.cc;h=878cbb72d876e1d815857ea7946dbe170ec27f15;hb=adea8ab68fc8a29984264a4a17ad7cf74439c521;hp=28398678a139cdcde0efca4ee98d597bced2ffa7;hpb=d9101a15611f3e96a2b313dd86d522605588c32b;p=ardour.git diff --git a/gtk2_ardour/piano_roll_header.cc b/gtk2_ardour/piano_roll_header.cc index 28398678a1..878cbb72d8 100644 --- a/gtk2_ardour/piano_roll_header.cc +++ b/gtk2_ardour/piano_roll_header.cc @@ -22,9 +22,11 @@ #include "gtkmm2ext/keyboard.h" +#include "editing.h" #include "piano_roll_header.h" #include "midi_time_axis.h" #include "midi_streamview.h" +#include "public_editor.h" const int no_note = 0xff; @@ -172,16 +174,16 @@ render_dga(Cairo::RefPtr cr, int /*note*/, double x[], double y[ void PianoRollHeader::get_path(PianoRollHeader::ItemType note_type, int note, double x[], double y[]) { - double y_pos = floor(_view.note_to_y(note)) - 0.5f; + double y_pos = floor(_view.note_to_y(note)) + 1.5f; double note_height; - double other_y1 = floor(_view.note_to_y(note+1)) + floor(_note_height / 2.0f) + 0.5f; - double other_y2 = floor(_view.note_to_y(note-1)) + floor(_note_height / 2.0f) - 1.0f; + double other_y1 = floor(_view.note_to_y(note+1)) + floor(_note_height / 2.0f) + 2.5f; + double other_y2 = floor(_view.note_to_y(note-1)) + floor(_note_height / 2.0f) + 1.0f; double width = get_width(); if (note == 0) { - note_height = floor(_view.contents_height()) - y_pos; + note_height = floor(_view.contents_height()) - y_pos + 2.; } else { - note_height = floor(_view.note_to_y(note - 1)) - y_pos; + note_height = floor(_view.note_to_y(note - 1)) - y_pos + 2.; } switch (note_type) { @@ -445,7 +447,7 @@ PianoRollHeader::on_expose_event (GdkEventExpose* ev) double y = floor(_view.note_to_y(i)) - 0.5f; double note_height = floor(_view.note_to_y(i - 1)) - y; - int cn = i / 12; + int cn = i / 12 - 1; s << "C" << cn; //cr->get_text_extents(s.str(), te); @@ -465,26 +467,39 @@ PianoRollHeader::on_motion_notify_event (GdkEventMotion* ev) int note = _view.y_to_note(ev->y); - if (_highlighted_note != no_note) { - if (note > _highlighted_note) { - invalidate_note_range(_highlighted_note, note); - } else { - invalidate_note_range(note, _highlighted_note); + if (editor().current_mouse_mode() == Editing::MouseRange) { + + /* select note range */ + + if (Keyboard::no_modifiers_active (ev->state)) { + AddNoteSelection (note); // EMIT SIGNAL } + + } else { - _highlighted_note = note; - } - - /* redraw already taken care of above */ - if (_clicked_note != no_note && _clicked_note != note) { - _active_notes[_clicked_note] = false; - send_note_off(_clicked_note); + /* play notes */ - _clicked_note = note; + if (_highlighted_note != no_note) { + if (note > _highlighted_note) { + invalidate_note_range(_highlighted_note, note); + } else { + invalidate_note_range(note, _highlighted_note); + } + + _highlighted_note = note; + } - if (!_active_notes[note]) { - _active_notes[note] = true; - send_note_on(note); + /* redraw already taken care of above */ + if (_clicked_note != no_note && _clicked_note != note) { + _active_notes[_clicked_note] = false; + send_note_off(_clicked_note); + + _clicked_note = note; + + if (!_active_notes[note]) { + _active_notes[note] = true; + send_note_on(note); + } } } } @@ -499,25 +514,27 @@ PianoRollHeader::on_button_press_event (GdkEventButton* ev) { int note = _view.y_to_note(ev->y); - if (ev->button == 2) { - send_note_on (note); - /* relax till release */ - } else { + if (ev->button == 2 && ev->type == GDK_BUTTON_PRESS) { + if (Keyboard::no_modifiers_active (ev->state)) { + SetNoteSelection (note); // EMIT SIGNAL + return true; + } + return false; + } + + if (ev->button == 1 && ev->type == GDK_BUTTON_PRESS && note >= 0 && note < 128) { - if (ev->type == GDK_BUTTON_PRESS && note >= 0 && note < 128) { - - add_modal_grab(); - _dragging = true; + add_modal_grab(); + _dragging = true; + + if (!_active_notes[note]) { + _active_notes[note] = true; + _clicked_note = note; + send_note_on(note); - if (!_active_notes[note]) { - _active_notes[note] = true; - _clicked_note = note; - send_note_on(note); - - invalidate_note_range(note, note); - } else { - reset_clicked_note(note); - } + invalidate_note_range(note, note); + } else { + reset_clicked_note(note); } } @@ -529,12 +546,11 @@ PianoRollHeader::on_button_release_event (GdkEventButton* ev) { int note = _view.y_to_note(ev->y); - if (ev->button == 2) { - send_note_off (note); + if (editor().current_mouse_mode() == Editing::MouseRange) { if (Keyboard::no_modifiers_active (ev->state)) { AddNoteSelection (note); // EMIT SIGNAL - } else if (Keyboard::modifier_state_equals (ev->state, Keyboard::PrimaryModifier)) { + } else if (Keyboard::modifier_state_equals (ev->state, Keyboard::PrimaryModifier)) { ToggleNoteSelection (note); // EMIT SIGNAL } else if (Keyboard::modifier_state_equals (ev->state, Keyboard::RangeSelectModifier)) { ExtendNoteSelection (note); // EMIT SIGNAL @@ -544,14 +560,14 @@ PianoRollHeader::on_button_release_event (GdkEventButton* ev) if (_dragging) { remove_modal_grab(); - _dragging = false; - + if (note == _clicked_note) { reset_clicked_note(note); } - } + } } + _dragging = false; return true; } @@ -587,14 +603,7 @@ void PianoRollHeader::note_range_changed() { _note_height = floor(_view.note_height()) + 0.5f; - queue_draw(); - - Glib::RefPtr win = get_window(); - - if (win) { - win->process_updates(false); - } } void @@ -663,11 +672,12 @@ void PianoRollHeader::send_note_on(uint8_t note) { boost::shared_ptr track = _view.trackview().midi_track(); + MidiTimeAxisView* mtv = dynamic_cast (&_view.trackview ()); //cerr << "note on: " << (int) note << endl; if (track) { - _event[0] = (MIDI_CMD_NOTE_ON | track->default_channel()); + _event[0] = (MIDI_CMD_NOTE_ON | mtv->get_channel_for_add ()); _event[1] = note; _event[2] = 100; @@ -679,9 +689,10 @@ void PianoRollHeader::send_note_off(uint8_t note) { boost::shared_ptr track = _view.trackview().midi_track(); + MidiTimeAxisView* mtv = dynamic_cast (&_view.trackview ()); if (track) { - _event[0] = (MIDI_CMD_NOTE_OFF | track->default_channel()); + _event[0] = (MIDI_CMD_NOTE_OFF | mtv->get_channel_for_add ()); _event[1] = note; _event[2] = 100; @@ -699,3 +710,9 @@ PianoRollHeader::reset_clicked_note (uint8_t note, bool invalidate) invalidate_note_range (note, note); } } + +PublicEditor& +PianoRollHeader::editor() const +{ + return _view.trackview().editor(); +}