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