Fix DSP load sorting with inactive plugins
[ardour.git] / gtk2_ardour / piano_roll_header.cc
1 /*
2  * Copyright (C) 2008-2014 David Robillard <d@drobilla.net>
3  * Copyright (C) 2009-2011 Carl Hetherington <carl@carlh.net>
4  * Copyright (C) 2009-2013 Paul Davis <paul@linuxaudiosystems.com>
5  * Copyright (C) 2014-2017 Robin Gareus <robin@gareus.org>
6  *
7  * This program is free software; you can redistribute it and/or modify
8  * it under the terms of the GNU General Public License as published by
9  * the Free Software Foundation; either version 2 of the License, or
10  * (at your option) any later version.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License along
18  * with this program; if not, write to the Free Software Foundation, Inc.,
19  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
20  */
21
22 #include <iostream>
23 #include "evoral/midi_events.h"
24 #include "ardour/midi_track.h"
25
26 #include "gtkmm2ext/keyboard.h"
27
28 #include "editing.h"
29 #include "piano_roll_header.h"
30 #include "midi_time_axis.h"
31 #include "midi_streamview.h"
32 #include "public_editor.h"
33 #include "ui_config.h"
34
35 using namespace std;
36 using namespace Gtkmm2ext;
37
38 PianoRollHeader::Color PianoRollHeader::white = PianoRollHeader::Color(0.77f, 0.78f, 0.76f);
39 PianoRollHeader::Color PianoRollHeader::white_highlight = PianoRollHeader::Color(1.00f, 0.40f, 0.40f);
40 PianoRollHeader::Color PianoRollHeader::white_shade_light = PianoRollHeader::Color(0.95f, 0.95f, 0.95f);
41 PianoRollHeader::Color PianoRollHeader::white_shade_dark = PianoRollHeader::Color(0.56f, 0.56f, 0.56f);
42
43 PianoRollHeader::Color PianoRollHeader::black = PianoRollHeader::Color(0.24f, 0.24f, 0.24f);
44 PianoRollHeader::Color PianoRollHeader::black_highlight = PianoRollHeader::Color(0.60f, 0.10f, 0.10f);
45 PianoRollHeader::Color PianoRollHeader::black_shade_light = PianoRollHeader::Color(0.46f, 0.46f, 0.46f);
46 PianoRollHeader::Color PianoRollHeader::black_shade_dark = PianoRollHeader::Color(0.1f, 0.1f, 0.1f);
47
48 PianoRollHeader::Color::Color()
49         : r(1.0f)
50         , g(1.0f)
51         , b(1.0f)
52 {
53 }
54
55 PianoRollHeader::Color::Color(double _r, double _g, double _b)
56         : r(_r)
57         , g(_g)
58         , b(_b)
59 {
60 }
61
62 inline void
63 PianoRollHeader::Color::set(const PianoRollHeader::Color& c)
64 {
65         r = c.r;
66         g = c.g;
67         b = c.b;
68 }
69
70 PianoRollHeader::PianoRollHeader(MidiStreamView& v)
71         : _view(v)
72         , _highlighted_note(NO_MIDI_NOTE)
73         , _clicked_note(NO_MIDI_NOTE)
74         , _dragging(false)
75 {
76         add_events (Gdk::BUTTON_PRESS_MASK |
77                     Gdk::BUTTON_RELEASE_MASK |
78                     Gdk::POINTER_MOTION_MASK |
79                     Gdk::ENTER_NOTIFY_MASK |
80                     Gdk::LEAVE_NOTIFY_MASK |
81                     Gdk::SCROLL_MASK);
82
83         for (int i = 0; i < 128; ++i) {
84                 _active_notes[i] = false;
85         }
86
87         _view.NoteRangeChanged.connect (sigc::mem_fun (*this, &PianoRollHeader::note_range_changed));
88 }
89
90 inline void
91 create_path(Cairo::RefPtr<Cairo::Context> cr, double x[], double y[], int start, int stop)
92 {
93         cr->move_to(x[start], y[start]);
94
95         for (int i = start+1; i <= stop; ++i) {
96                 cr->line_to(x[i], y[i]);
97         }
98 }
99
100 inline void
101 render_rect(Cairo::RefPtr<Cairo::Context> cr, int /*note*/, double x[], double y[],
102              PianoRollHeader::Color& bg, PianoRollHeader::Color& tl_shadow, PianoRollHeader::Color& br_shadow)
103 {
104         cr->set_source_rgb(bg.r, bg.g, bg.b);
105         create_path(cr, x, y, 0, 4);
106         cr->fill();
107
108         cr->set_source_rgb(tl_shadow.r, tl_shadow.g, tl_shadow.b);
109         create_path(cr, x, y, 0, 2);
110         cr->stroke();
111
112         cr->set_source_rgb(br_shadow.r, br_shadow.g, br_shadow.b);
113         create_path(cr, x, y, 2, 4);
114         cr->stroke();
115 }
116
117 inline void
118 render_cf(Cairo::RefPtr<Cairo::Context> cr, int /*note*/, double x[], double y[],
119                 PianoRollHeader::Color& bg, PianoRollHeader::Color& tl_shadow, PianoRollHeader::Color& br_shadow)
120 {
121         cr->set_source_rgb(bg.r, bg.g, bg.b);
122         create_path(cr, x, y, 0, 6);
123         cr->fill();
124
125         cr->set_source_rgb(tl_shadow.r, tl_shadow.g, tl_shadow.b);
126         create_path(cr, x, y, 0, 4);
127         cr->stroke();
128
129         cr->set_source_rgb(br_shadow.r, br_shadow.g, br_shadow.b);
130         create_path(cr, x, y, 4, 6);
131         cr->stroke();
132 }
133
134 inline void
135 render_eb(Cairo::RefPtr<Cairo::Context> cr, int /*note*/, double x[], double y[],
136                 PianoRollHeader::Color& bg, PianoRollHeader::Color& tl_shadow, PianoRollHeader::Color& br_shadow)
137 {
138         cr->set_source_rgb(bg.r, bg.g, bg.b);
139         create_path(cr, x, y, 0, 6);
140         cr->fill();
141
142         cr->set_source_rgb(tl_shadow.r, tl_shadow.g, tl_shadow.b);
143         create_path(cr, x, y, 0, 2);
144         cr->stroke();
145         create_path(cr, x, y, 4, 5);
146         cr->stroke();
147
148         cr->set_source_rgb(br_shadow.r, br_shadow.g, br_shadow.b);
149         create_path(cr, x, y, 2, 4);
150         cr->stroke();
151         create_path(cr, x, y, 5, 6);
152         cr->stroke();
153 }
154
155 inline void
156 render_dga(Cairo::RefPtr<Cairo::Context> cr, int /*note*/, double x[], double y[],
157                  PianoRollHeader::Color& bg, PianoRollHeader::Color& tl_shadow, PianoRollHeader::Color& br_shadow)
158 {
159         cr->set_source_rgb(bg.r, bg.g, bg.b);
160         create_path(cr, x, y, 0, 8);
161         cr->fill();
162
163         cr->set_source_rgb(tl_shadow.r, tl_shadow.g, tl_shadow.b);
164         create_path(cr, x, y, 0, 4);
165         cr->stroke();
166         create_path(cr, x, y, 6, 7);
167         cr->stroke();
168
169         cr->set_source_rgb(br_shadow.r, br_shadow.g, br_shadow.b);
170         create_path(cr, x, y, 4, 6);
171         cr->stroke();
172         create_path(cr, x, y, 7, 8);
173         cr->stroke();
174 }
175
176 void
177 PianoRollHeader::get_path(PianoRollHeader::ItemType note_type, int note, double x[], double y[])
178 {
179         double y_pos = floor(_view.note_to_y(note)) + 1.5f;
180         double note_height;
181         double other_y1 = floor(_view.note_to_y(note+1)) + floor(_note_height / 2.0f) + 2.5f;
182         double other_y2 = floor(_view.note_to_y(note-1)) + floor(_note_height / 2.0f) + 1.0f;
183         double width = get_width();
184
185         if (note == 0) {
186                 note_height = floor(_view.contents_height()) - y_pos + 2.;
187         } else {
188                 note_height = floor(_view.note_to_y(note - 1)) - y_pos + 2.;
189         }
190
191         switch (note_type) {
192         case BLACK_SEPARATOR:
193                 x[0] = 1.5f;
194                 y[0] = y_pos;
195                 x[1] = _black_note_width;
196                 y[1] = y_pos;
197                 break;
198         case BLACK_MIDDLE_SEPARATOR:
199                 x[0] = _black_note_width;
200                 y[0] = y_pos + floor(_note_height / 2.0f);
201                 x[1] = width - 1.0f;
202                 y[1] = y[0];
203                 break;
204         case BLACK:
205                 x[0] = 1.5f;
206                 y[0] = y_pos + note_height - 0.5f;
207                 x[1] = 1.5f;
208                 y[1] = y_pos + 1.0f;
209                 x[2] = _black_note_width;
210                 y[2] = y_pos + 1.0f;
211                 x[3] = _black_note_width;
212                 y[3] = y_pos + note_height - 0.5f;
213                 x[4] = 1.5f;
214                 y[4] = y_pos + note_height - 0.5f;
215                 return;
216         case WHITE_SEPARATOR:
217                 x[0] = 1.5f;
218                 y[0] = y_pos;
219                 x[1] = width - 1.5f;
220                 y[1] = y_pos;
221                 break;
222         case WHITE_RECT:
223                 x[0] = 1.5f;
224                 y[0] = y_pos + note_height - 0.5f;
225                 x[1] = 1.5f;
226                 y[1] = y_pos + 1.0f;
227                 x[2] = width - 1.5f;
228                 y[2] = y_pos + 1.0f;
229                 x[3] = width - 1.5f;
230                 y[3] = y_pos + note_height - 0.5f;
231                 x[4] = 1.5f;
232                 y[4] = y_pos + note_height - 0.5f;
233                 return;
234         case WHITE_CF:
235                 x[0] = 1.5f;
236                 y[0] = y_pos + note_height - 1.5f;
237                 x[1] = 1.5f;
238                 y[1] = y_pos + 1.0f;
239                 x[2] = _black_note_width + 1.0f;
240                 y[2] = y_pos + 1.0f;
241                 x[3] = _black_note_width + 1.0f;
242                 y[3] = other_y1;
243                 x[4] = width - 1.5f;
244                 y[4] = other_y1;
245                 x[5] = width - 1.5f;
246                 y[5] = y_pos + note_height - 1.5f;
247                 x[6] = 1.5f;
248                 y[6] = y_pos + note_height - 1.5f;
249                 return;
250         case WHITE_EB:
251                 x[0] = 1.5f;
252                 y[0] = y_pos + note_height - 1.5f;
253                 x[1] = 1.5f;
254                 y[1] = y_pos + 1.0f;
255                 x[2] = width - 1.5f;
256                 y[2] = y_pos + 1.0f;
257                 x[3] = width - 1.5f;
258                 y[3] = other_y2;
259                 x[4] = _black_note_width + 1.0f;
260                 y[4] = other_y2;
261                 x[5] = _black_note_width + 1.0f;
262                 y[5] = y_pos + note_height - 1.5f;
263                 x[6] = 1.5f;
264                 y[6] = y_pos + note_height - 1.5f;
265                 return;
266         case WHITE_DGA:
267                 x[0] = 1.5f;
268                 y[0] = y_pos + note_height - 1.5f;
269                 x[1] = 1.5f;
270                 y[1] = y_pos + 1.0f;
271                 x[2] = _black_note_width + 1.0f;
272                 y[2] = y_pos + 1.0f;
273                 x[3] = _black_note_width + 1.0f;
274                 y[3] = other_y1;
275                 x[4] = width - 1.5f;
276                 y[4] = other_y1;
277                 x[5] = width - 1.5f;
278                 y[5] = other_y2;
279                 x[6] = _black_note_width + 1.0f;
280                 y[6] = other_y2;
281                 x[7] = _black_note_width + 1.0f;
282                 y[7] = y_pos + note_height - 1.5f;
283                 x[8] = 1.5f;
284                 y[8] = y_pos + note_height - 1.5f;
285                 return;
286         default:
287                 return;
288         }
289 }
290
291 bool
292 PianoRollHeader::on_expose_event (GdkEventExpose* ev)
293 {
294         GdkRectangle& rect = ev->area;
295         double font_size;
296         int lowest, highest;
297         Cairo::RefPtr<Cairo::Context> cr = get_window()->create_cairo_context();
298         Cairo::RefPtr<Cairo::LinearGradient> pat = Cairo::LinearGradient::create(0, 0, _black_note_width, 0);
299         double x[9];
300         double y[9];
301         Color bg, tl_shadow, br_shadow;
302         int oct_rel;
303         int y1 = max(rect.y, 0);
304         int y2 = min(rect.y + rect.height, (int) floor(_view.contents_height() - 1.0f));
305
306         //Cairo::TextExtents te;
307         lowest = max(_view.lowest_note(), _view.y_to_note(y2));
308         highest = min(_view.highest_note(), _view.y_to_note(y1));
309
310         if (lowest > 127) {
311                 lowest = 0;
312         }
313
314         cr->select_font_face ("Georgia", Cairo::FONT_SLANT_NORMAL, Cairo::FONT_WEIGHT_BOLD);
315         font_size = min((double) 10.0f, _note_height - 4.0f);
316         cr->set_font_size(font_size);
317
318         /* fill the entire rect with the color for non-highlighted white notes.
319          * then we won't have to draw the background for those notes,
320          * and would only have to draw the background for the one highlighted white note*/
321         //cr->rectangle(rect.x, rect.y, rect.width, rect.height);
322         //cr->set_source_rgb(white.r, white.g, white.b);
323         //cr->fill();
324
325         cr->set_line_width(1.0f);
326
327         /* draw vertical lines with shade at both ends of the widget */
328         cr->set_source_rgb(0.0f, 0.0f, 0.0f);
329         cr->move_to(0.5f, rect.y);
330         cr->line_to(0.5f, rect.y + rect.height);
331         cr->stroke();
332         cr->move_to(get_width() - 0.5f, rect.y);
333         cr->line_to(get_width() - 0.5f, rect.y + rect.height);
334         cr->stroke();
335
336         //pat->add_color_stop_rgb(0.0, 0.33, 0.33, 0.33);
337         //pat->add_color_stop_rgb(0.2, 0.39, 0.39, 0.39);
338         //pat->add_color_stop_rgb(1.0, 0.22, 0.22, 0.22);
339         //cr->set_source(pat);
340
341         for (int i = lowest; i <= highest; ++i) {
342                 oct_rel = i % 12;
343
344                 switch (oct_rel) {
345                 case 1:
346                 case 3:
347                 case 6:
348                 case 8:
349                 case 10:
350                         /* black note */
351                         if (i == _highlighted_note) {
352                                 bg.set(black_highlight);
353                         } else {
354                                 bg.set(black);
355                         }
356
357                         if (_active_notes[i]) {
358                                 tl_shadow.set(black_shade_dark);
359                                 br_shadow.set(black_shade_light);
360                         } else {
361                                 tl_shadow.set(black_shade_light);
362                                 br_shadow.set(black_shade_dark);
363                         }
364
365                         /* draw black separators */
366                         cr->set_source_rgb(0.0f, 0.0f, 0.0f);
367                         get_path(BLACK_SEPARATOR, i, x, y);
368                         create_path(cr, x, y, 0, 1);
369                         cr->stroke();
370
371                         get_path(BLACK_MIDDLE_SEPARATOR, i, x, y);
372                         create_path(cr, x, y, 0, 1);
373                         cr->stroke();
374
375                         get_path(BLACK, i, x, y);
376                         render_rect(cr, i, x, y, bg, tl_shadow, br_shadow);
377                         break;
378
379                 default:
380                         /* white note */
381                         if (i == _highlighted_note) {
382                                 bg.set(white_highlight);
383                         } else {
384                                 bg.set(white);
385                         }
386
387                         if (_active_notes[i]) {
388                                 tl_shadow.set(white_shade_dark);
389                                 br_shadow.set(white_shade_light);
390                         } else {
391                                 tl_shadow.set(white_shade_light);
392                                 br_shadow.set(white_shade_dark);
393                         }
394
395                         switch(oct_rel) {
396                         case 0:
397                         case 5:
398                                 if (i == _view.highest_note()) {
399                                         get_path(WHITE_RECT, i, x, y);
400                                         render_rect(cr, i, x, y, bg, tl_shadow, br_shadow);
401                                 } else {
402                                         get_path(WHITE_CF, i, x, y);
403                                         render_cf(cr, i, x, y, bg, tl_shadow, br_shadow);
404                                 }
405                                 break;
406
407                         case 2:
408                         case 7:
409                         case 9:
410                                 if (i == _view.highest_note()) {
411                                         get_path(WHITE_EB, i, x, y);
412                                         render_eb(cr, i, x, y, bg, tl_shadow, br_shadow);
413                                 } else if (i == _view.lowest_note()) {
414                                         get_path(WHITE_CF, i, x, y);
415                                         render_cf(cr, i, x, y, bg, tl_shadow, br_shadow);
416                                 } else {
417                                         get_path(WHITE_DGA, i, x, y);
418                                         render_dga(cr, i, x, y, bg, tl_shadow, br_shadow);
419                                 }
420                                 break;
421
422                         case 4:
423                         case 11:
424                                 cr->set_source_rgb(0.0f, 0.0f, 0.0f);
425                                 get_path(WHITE_SEPARATOR, i, x, y);
426                                 create_path(cr, x, y, 0, 1);
427                                 cr->stroke();
428
429                                 if (i == _view.lowest_note()) {
430                                         get_path(WHITE_RECT, i, x, y);
431                                         render_rect(cr, i, x, y, bg, tl_shadow, br_shadow);
432                                 } else {
433                                         get_path(WHITE_EB, i, x, y);
434                                         render_eb(cr, i, x, y, bg, tl_shadow, br_shadow);
435                                 }
436                                 break;
437
438                         default:
439                                 break;
440
441                         }
442                         break;
443
444                 }
445
446                 /* render the name of which C this is */
447                 if (oct_rel == 0) {
448                         std::stringstream s;
449                         double y = floor(_view.note_to_y(i)) - 0.5f;
450                         double note_height = floor(_view.note_to_y(i - 1)) - y;
451
452                         int cn = i / 12 - 1;
453                         s << "C" << cn;
454
455                         //cr->get_text_extents(s.str(), te);
456                         cr->set_source_rgb(0.30f, 0.30f, 0.30f);
457                         cr->move_to(2.0f, y + note_height - 1.0f - (note_height - font_size) / 2.0f);
458                         cr->show_text(s.str());
459                 }
460         }
461
462         return true;
463 }
464
465 bool
466 PianoRollHeader::on_motion_notify_event (GdkEventMotion* ev)
467 {
468         int note = _view.y_to_note(ev->y);
469         set_note_highlight (note);
470
471         if (_dragging) {
472
473                 if ( false /*editor().current_mouse_mode() == Editing::MouseRange*/ ) {   //ToDo:  fix this.  this mode is buggy, and of questionable utility anyway
474
475                         /* select note range */
476
477                         if (Keyboard::no_modifiers_active (ev->state)) {
478                                 AddNoteSelection (note); // EMIT SIGNAL
479                         }
480
481                 } else {
482                         /* play notes */
483                         /* redraw already taken care of above in set_note_highlight */
484                         if (_clicked_note != NO_MIDI_NOTE && _clicked_note != note) {
485                                 _active_notes[_clicked_note] = false;
486                                 send_note_off(_clicked_note);
487
488                                 _clicked_note = note;
489
490                                 if (!_active_notes[note]) {
491                                         _active_notes[note] = true;
492                                         send_note_on(note);
493                                 }
494                         }
495                 }
496         }
497
498         //win->process_updates(false);
499
500         return true;
501 }
502
503 bool
504 PianoRollHeader::on_button_press_event (GdkEventButton* ev)
505 {
506         int note = _view.y_to_note(ev->y);
507         bool tertiary = Keyboard::modifier_state_contains (ev->state, Keyboard::TertiaryModifier);
508
509         if (ev->button == 2 && Keyboard::no_modifiers_active (ev->state)) {
510                 SetNoteSelection (note); // EMIT SIGNAL
511                 return true;
512         } else if (tertiary && (ev->button == 1 || ev->button == 2)) {
513                 ExtendNoteSelection (note); // EMIT SIGNAL
514                 return true;
515         } else if (ev->button == 1 && note >= 0 && note < 128) {
516                 add_modal_grab();
517                 _dragging = true;
518
519                 if (!_active_notes[note]) {
520                         _active_notes[note] = true;
521                         _clicked_note = note;
522                         send_note_on(note);
523
524                         invalidate_note_range(note, note);
525                 } else {
526                         reset_clicked_note(note);
527                 }
528         }
529
530         return true;
531 }
532
533 bool
534 PianoRollHeader::on_button_release_event (GdkEventButton* ev)
535 {
536         int note = _view.y_to_note(ev->y);
537
538         if (false /*editor().current_mouse_mode() == Editing::MouseRange*/ ) {  //Todo:  this mode is buggy, and of questionable utility anyway
539
540                 if (Keyboard::no_modifiers_active (ev->state)) {
541                         AddNoteSelection (note); // EMIT SIGNAL
542                 } else if (Keyboard::modifier_state_equals (ev->state, Keyboard::PrimaryModifier)) {
543                         ToggleNoteSelection (note); // EMIT SIGNAL
544                 } else if (Keyboard::modifier_state_equals (ev->state, Keyboard::RangeSelectModifier)) {
545                         ExtendNoteSelection (note); // EMIT SIGNAL
546                 }
547
548         } else {
549
550                 if (_dragging) {
551                         remove_modal_grab();
552
553                         if (note == _clicked_note) {
554                                 reset_clicked_note(note);
555                         }
556                 }
557         }
558
559         _dragging = false;
560         return true;
561 }
562
563 void
564 PianoRollHeader::set_note_highlight (uint8_t note) {
565         if (_highlighted_note == note) {
566                 return;
567         }
568
569         if (_highlighted_note != NO_MIDI_NOTE) {
570                 if (note > _highlighted_note) {
571                         invalidate_note_range (_highlighted_note, note);
572                 } else {
573                         invalidate_note_range (note, _highlighted_note);
574                 }
575         }
576
577         _highlighted_note = note;
578
579         if (_highlighted_note != NO_MIDI_NOTE) {
580                 invalidate_note_range (_highlighted_note, _highlighted_note);
581         }
582 }
583
584 bool
585 PianoRollHeader::on_enter_notify_event (GdkEventCrossing* ev)
586 {
587         set_note_highlight (_view.y_to_note(ev->y));
588         return true;
589 }
590
591 bool
592 PianoRollHeader::on_leave_notify_event (GdkEventCrossing*)
593 {
594         invalidate_note_range(_highlighted_note, _highlighted_note);
595
596         if (_clicked_note != NO_MIDI_NOTE) {
597                 reset_clicked_note(_clicked_note, _clicked_note != _highlighted_note);
598         }
599
600         _highlighted_note = NO_MIDI_NOTE;
601         return true;
602 }
603
604 bool
605 PianoRollHeader::on_scroll_event (GdkEventScroll*)
606 {
607         return true;
608 }
609
610 void
611 PianoRollHeader::note_range_changed()
612 {
613         _note_height = floor(_view.note_height()) + 0.5f;
614         queue_draw();
615 }
616
617 void
618 PianoRollHeader::invalidate_note_range(int lowest, int highest)
619 {
620         Glib::RefPtr<Gdk::Window> win = get_window();
621         Gdk::Rectangle rect;
622
623         // the non-rectangular geometry of some of the notes requires more
624         // redraws than the notes that actually changed.
625         switch(lowest % 12) {
626         case 0:
627         case 5:
628                 lowest = max((int) _view.lowest_note(), lowest);
629                 break;
630         default:
631                 lowest = max((int) _view.lowest_note(), lowest - 1);
632                 break;
633         }
634
635         switch(highest % 12) {
636         case 4:
637         case 11:
638                 highest = min((int) _view.highest_note(), highest);
639                 break;
640         case 1:
641         case 3:
642         case 6:
643         case 8:
644         case 10:
645                 highest = min((int) _view.highest_note(), highest + 1);
646                 break;
647         default:
648                 highest = min((int) _view.highest_note(), highest + 2);
649                 break;
650         }
651
652         double y = _view.note_to_y(highest);
653         double height = _view.note_to_y(lowest - 1) - y;
654
655         rect.set_x(0);
656         rect.set_width(get_width());
657         rect.set_y((int) floor(y));
658         rect.set_height((int) floor(height));
659
660         if (win) {
661                 win->invalidate_rect(rect, false);
662         }
663 }
664
665 void
666 PianoRollHeader::on_size_request(Gtk::Requisition* r)
667 {
668         r->width = std::max (20.f, rintf (20.f * UIConfiguration::instance().get_ui_scale()));
669 }
670
671 void
672 PianoRollHeader::on_size_allocate(Gtk::Allocation& a)
673 {
674         DrawingArea::on_size_allocate(a);
675
676         _black_note_width = floor(0.7 * get_width()) + 0.5f;
677 }
678
679 void
680 PianoRollHeader::send_note_on(uint8_t note)
681 {
682         boost::shared_ptr<ARDOUR::MidiTrack> track = _view.trackview().midi_track();
683         MidiTimeAxisView* mtv = dynamic_cast<MidiTimeAxisView*> (&_view.trackview ());
684
685         //cerr << "note on: " << (int) note << endl;
686
687         if (track) {
688                 _event[0] = (MIDI_CMD_NOTE_ON | mtv->get_channel_for_add ());
689                 _event[1] = note;
690                 _event[2] = 100;
691
692                 track->write_immediate_event(3, _event);
693         }
694 }
695
696 void
697 PianoRollHeader::send_note_off(uint8_t note)
698 {
699         boost::shared_ptr<ARDOUR::MidiTrack> track = _view.trackview().midi_track();
700         MidiTimeAxisView* mtv = dynamic_cast<MidiTimeAxisView*> (&_view.trackview ());
701
702         if (track) {
703                 _event[0] = (MIDI_CMD_NOTE_OFF | mtv->get_channel_for_add ());
704                 _event[1] = note;
705                 _event[2] = 100;
706
707                 track->write_immediate_event(3, _event);
708         }
709 }
710
711 void
712 PianoRollHeader::reset_clicked_note (uint8_t note, bool invalidate)
713 {
714         _active_notes[note] = false;
715         _clicked_note = NO_MIDI_NOTE;
716         send_note_off (note);
717         if (invalidate) {
718                 invalidate_note_range (note, note);
719         }
720 }
721
722 PublicEditor&
723 PianoRollHeader::editor() const
724 {
725         return _view.trackview().editor();
726 }