Set mixbufs count in the case of a panner being used, as
[ardour2.git] / gtk2_ardour / midi_scroomer.cc
blobcccc03c507f86a4e2c6d98f87ff739cc8c9f8f04
1 /*
2 Copyright (C) 2008 Paul Davis
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.
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.
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.
19 #include "midi_scroomer.h"
21 #include <cairomm/context.h>
23 #include <iostream>
25 using namespace Gtkmm2ext;
26 using namespace Gtk;
27 using namespace std;
29 //std::map<int, Glib::RefPtr<Gdk::Pixmap> > MidiScroomer::piano_pixmaps;
31 MidiScroomer::MidiScroomer(Adjustment& adj)
32 : Gtkmm2ext::Scroomer(adj)
35 adj.set_lower(0);
36 adj.set_upper(127);
38 /* set minimum view range to one octave */
39 set_min_page_size(12);
42 MidiScroomer::~MidiScroomer()
46 bool
47 MidiScroomer::on_expose_event(GdkEventExpose* ev)
49 Cairo::RefPtr<Cairo::Context> cc = get_window()->create_cairo_context();
50 GdkRectangle comp_rect, clip_rect;
51 Component first_comp = point_in(ev->area.y);
52 Component last_comp = point_in(ev->area.y + ev->area.height);
53 int height = get_height();
54 int lnote, hnote;
55 double y2note = (double) 127 / height;
56 double note2y = (double) height / 127;
57 double note_width = 0.8 * get_width();
58 double note_height = 1.4 * note2y;
59 double black_shift = 0.1 * note2y;
60 double colors[6] = {0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f};
62 //cerr << ev->area.y << " " << ev->area.height << endl;
64 comp_rect.x = 0;
65 comp_rect.width = get_width();
67 for (int i = first_comp; i <= last_comp; ++i) {
68 Component comp = (Component) i;
69 set_comp_rect(comp_rect, comp);
71 if (gdk_rectangle_intersect(&comp_rect, &ev->area, &clip_rect)) {
72 get_colors(colors, comp);
74 cc->rectangle(clip_rect.x, clip_rect.y, clip_rect.width, clip_rect.height);
75 cc->set_source_rgb (colors[3], colors[4], colors[5]);
76 cc->fill_preserve();
77 cc->clip();
79 cc->set_source_rgb(colors[0], colors[1], colors[2]);
80 cc->set_line_width(note_height);
82 lnote = 127 - (int) floor((double) (clip_rect.y + clip_rect.height) * y2note) - 1;
83 hnote = 127 - (int) floor((double) clip_rect.y * y2note) + 1;
85 for (int note = lnote; note < hnote + 1; ++note) {
86 double y = height - note * note2y;
87 bool draw = false;
89 switch (note % 12) {
90 case 1:
91 case 6:
92 y -= black_shift;
93 draw = true;
94 break;
95 case 3:
96 case 10:
97 y += black_shift;
98 draw = true;
99 break;
100 case 8:
101 draw = true;
102 break;
103 default:
104 break;
107 if(draw) {
108 cc->set_line_width(1.4 * note2y);
109 cc->move_to(0, y);
110 cc->line_to(note_width, y);
111 cc->stroke();
115 if (i == Handle1 || i == Handle2) {
116 cc->rectangle(comp_rect.x + 0.5f, comp_rect.y + 0.5f, comp_rect.width - 1.0f, comp_rect.height - 1.0f);
117 cc->set_line_width(1.0f);
118 cc->set_source_rgb (1.0f, 1.0f, 1.0f);
119 cc->stroke();
122 cc->reset_clip();
126 return true;
129 void
130 MidiScroomer::get_colors(double color[], Component comp)
132 switch (comp) {
133 case TopBase:
134 case BottomBase:
135 color[0] = 0.24f;
136 color[1] = 0.24f;
137 color[2] = 0.24f;
138 color[3] = 0.33f;
139 color[4] = 0.33f;
140 color[5] = 0.33f;
141 break;
142 case Handle1:
143 case Handle2:
144 color[0] = 0.91f;
145 color[1] = 0.91f;
146 color[2] = 0.91f;
147 color[3] = 0.0f;
148 color[4] = 0.0f;
149 color[5] = 0.0f;
150 break;
151 case Slider:
152 color[0] = 0.38f;
153 color[1] = 0.38f;
154 color[2] = 0.38f;
155 color[3] = 0.77f;
156 color[4] = 0.77f;
157 color[5] = 0.77f;
158 break;
159 default:
160 break;
164 void
165 MidiScroomer::on_size_request(Gtk::Requisition* r)
167 r->width = 12;
168 r->height = 100;
171 void
172 MidiScroomer::on_size_allocate(Gtk::Allocation& a)
174 Scroomer::on_size_allocate(a);