2 Copyright (C) 2016 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.
21 #include "gtkmm2ext/gui_thread.h"
23 #include "canvas/colors.h"
24 #include "canvas/rectangle.h"
25 #include "canvas/text.h"
32 using namespace ARDOUR;
36 using namespace ArdourSurface;
37 using namespace ArdourCanvas;
39 static double unselected_root_alpha = 0.5;
41 ScaleLayout::ScaleLayout (Push2& p, Session& s)
47 Pango::FontDescription fd ("Sans 10");
51 bg = new Rectangle (this);
52 bg->set (Rect (0, 0, display_width(), display_height()));
53 bg->set_fill_color (p2.get_color (Push2::DarkBackground));
55 left_scroll_text = new Text (this);
56 left_scroll_text->set_font_description (fd);
57 left_scroll_text->set_position (Duple (10, 5));
58 left_scroll_text->set_color (p2.get_color (Push2::LightBackground));
60 close_text = new Text (this);
61 close_text->set_font_description (fd);
62 close_text->set_position (Duple (25, 5));
63 close_text->set_color (p2.get_color (Push2::LightBackground));
64 close_text->set (_("Close"));
66 right_scroll_text = new Text (this);
67 right_scroll_text->set_font_description (fd);
68 right_scroll_text->set_position (Duple (10 + (7 * Push2Canvas::inter_button_spacing()), 5));
69 right_scroll_text->set_color (p2.get_color (Push2::LightBackground));
71 Pango::FontDescription fd2 ("Sans 8");
72 inkey_text = new Text (this);
73 inkey_text->set_font_description (fd2);
74 inkey_text->set_position (Duple (10, 140));
75 inkey_text->set_color (p2.get_color (Push2::LightBackground));
76 inkey_text->set (_("InKey"));
78 chromatic_text = new Text (this);
79 chromatic_text->set_font_description (fd2);
80 chromatic_text->set_position (Duple (45, 140));
81 chromatic_text->set_color (p2.get_color (Push2::LightBackground));
82 chromatic_text->set (_("Chromatic"));
84 for (int n = 0; n < 8; ++n) {
86 /* text labels for root notes etc.*/
88 Text* t = new Text (this);
89 t->set_font_description (fd);
90 t->set_color (change_alpha (p2.get_color (Push2::LightBackground), unselected_root_alpha));
91 t->set_position (Duple (10 + (n * Push2Canvas::inter_button_spacing()), 5));
95 /* zeroth element is a dummy */
98 t->set (S_("Note|C"));
101 t->set (S_("Note|G"));
104 t->set (S_("Note|D"));
107 t->set (S_("Note|A"));
110 t->set (S_("Note|E"));
113 t->set (S_("Note|B"));
117 upper_text.push_back (t);
120 t->set_font_description (fd);
121 t->set_color (change_alpha (p2.get_color (Push2::LightBackground), unselected_root_alpha));
122 t->set_position (Duple (10 + (n*Push2Canvas::inter_button_spacing()), 140));
126 /* zeroth element is a dummy */
129 t->set (S_("Note|F"));
132 t->set (S_("Note|B\u266D/A\u266F"));
135 t->set (S_("Note|E\u266D/D\u266F"));
138 t->set (S_("Note|A\u266D/G\u266F"));
141 t->set (S_("Note|D\u266D/C\u266F"));
144 t->set (S_("Note|G\u266D/F\u266F"));
148 lower_text.push_back (t);
153 p2.ScaleChange.connect (p2_connections, invalidator (*this), boost::bind (&ScaleLayout::show_root_state, this), &p2);
156 ScaleLayout::~ScaleLayout ()
161 ScaleLayout::render (Rect const& area, Cairo::RefPtr<Cairo::Context> context) const
163 render_children (area, context);
167 ScaleLayout::button_upper (uint32_t n)
170 if (scale_menu->can_scroll_left()) {
171 scale_menu->scroll (Push2Menu::DirectionLeft, true);
173 p2.use_previous_layout ();
179 scale_menu->scroll (Push2Menu::DirectionRight, true);
215 p2.set_pad_scale (root, p2.root_octave(), p2.mode(), p2.in_key());
219 ScaleLayout::button_lower (uint32_t n)
222 p2.set_pad_scale (p2.scale_root(), p2.root_octave(), p2.mode(), !p2.in_key());
258 p2.set_pad_scale (root, p2.root_octave(), p2.mode(), p2.in_key());
262 ScaleLayout::button_up ()
264 scale_menu->scroll (Push2Menu::DirectionUp);
268 ScaleLayout::button_down ()
270 scale_menu->scroll (Push2Menu::DirectionDown);
274 ScaleLayout::button_left ()
276 scale_menu->scroll (Push2Menu::DirectionLeft);
280 ScaleLayout::button_right ()
282 scale_menu->scroll (Push2Menu::DirectionRight);
292 b = p2.button_by_id (Push2::Upper1);
293 b->set_color (Push2::LED::White);
294 b->set_state (Push2::LED::OneShot24th);
295 p2.write (b->state_msg());
297 b = p2.button_by_id (Push2::Upper8);
298 b->set_color (Push2::LED::White);
299 b->set_state (Push2::LED::OneShot24th);
300 p2.write (b->state_msg());
302 b = p2.button_by_id (Push2::Lower1);
303 b->set_color (Push2::LED::White);
304 b->set_state (Push2::LED::OneShot24th);
305 p2.write (b->state_msg());
307 /* all root buttons should be dimly lit */
309 Push2::ButtonID root_buttons[] = { Push2::Upper2, Push2::Upper3, Push2::Upper4, Push2::Upper5, Push2::Upper6, Push2::Upper7,
310 Push2::Lower2, Push2::Lower3, Push2::Lower4, Push2::Lower5, Push2::Lower6, Push2::Lower7, };
312 for (size_t n = 0; n < sizeof (root_buttons) / sizeof (root_buttons[0]); ++n) {
313 b = p2.button_by_id (root_buttons[n]);
315 b->set_color (Push2::LED::DarkGray);
316 b->set_state (Push2::LED::OneShot24th);
317 p2.write (b->state_msg());
326 ScaleLayout::strip_vpot (int n, int delta)
328 /* menu starts under the 2nd-from-left vpot */
334 if (last_vpot != n) {
335 uint32_t effective_column = n - 1;
336 uint32_t active = scale_menu->active ();
338 if (active / scale_menu->rows() != effective_column) {
339 /* knob turned is different than the current active column.
342 scale_menu->set_active (effective_column * scale_menu->rows()); /* top entry of that column */
346 /* new vpot, reset delta cnt */
351 if ((delta < 0 && vpot_delta_cnt > 0) || (delta > 0 && vpot_delta_cnt < 0)) {
352 /* direction changed, reset */
356 vpot_delta_cnt += delta;
359 /* this thins out vpot delta events so that we don't scroll so fast
363 const int vpot_slowdown_factor = 4;
365 if ((vpot_delta_cnt < 0) && (vpot_delta_cnt % vpot_slowdown_factor == 0)) {
366 scale_menu->scroll (Push2Menu::DirectionUp);
367 } else if (vpot_delta_cnt % vpot_slowdown_factor == 0) {
368 scale_menu->scroll (Push2Menu::DirectionDown);
373 ScaleLayout::build_scale_menu ()
377 /* must match in which enums are declared in push2.h
380 v.push_back ("Dorian");
381 v.push_back ("Ionian (Major)");
382 v.push_back ("Minor");
383 v.push_back ("Harmonic Minor");
384 v.push_back ("MelodicMinor Asc.");
385 v.push_back ("MelodicMinor Desc.");
386 v.push_back ("Phrygian");
387 v.push_back ("Lydian");
388 v.push_back ("Mixolydian");
389 v.push_back ("Aeolian");
390 v.push_back ("Locrian");
391 v.push_back ("Pentatonic Major");
392 v.push_back ("Pentatonic Minor");
393 v.push_back ("Chromatic");
394 v.push_back ("BluesScale");
395 v.push_back ("Neapolitan Minor");
396 v.push_back ("Neapolitan Major");
397 v.push_back ("Oriental");
398 v.push_back ("Double Harmonic");
399 v.push_back ("Enigmatic");
400 v.push_back ("Hirajoshi");
401 v.push_back ("Hungarian Minor");
402 v.push_back ("Hungarian Major");
403 v.push_back ("Kumoi");
404 v.push_back ("Iwato");
405 v.push_back ("Hindu");
406 v.push_back ("Spanish 8 Tone");
407 v.push_back ("Pelog");
408 v.push_back ("Hungarian Gypsy");
409 v.push_back ("Overtone");
410 v.push_back ("Leading Whole Tone");
411 v.push_back ("Arabian");
412 v.push_back ("Balinese");
413 v.push_back ("Gypsy");
414 v.push_back ("Mohammedan");
415 v.push_back ("Javanese");
416 v.push_back ("Persian");
417 v.push_back ("Algeria");
419 scale_menu = new Push2Menu (this, v);
420 scale_menu->Rearranged.connect (menu_connections, invalidator (*this), boost::bind (&ScaleLayout::menu_rearranged, this), &p2);
422 scale_menu->set_layout (6, 6);
423 scale_menu->set_text_color (p2.get_color (Push2::ParameterName));
424 scale_menu->set_active_color (p2.get_color (Push2::LightBackground));
426 Pango::FontDescription fd ("Sans Bold 8");
427 scale_menu->set_font_description (fd);
429 /* move menu into position so that its leftmost column is in the
430 * 2nd-from-left column of the display/button layout.
433 scale_menu->set_position (Duple (10 + Push2Canvas::inter_button_spacing(), 40));
435 /* listen for changes */
437 scale_menu->ActiveChanged.connect (menu_connections, invalidator (*this), boost::bind (&ScaleLayout::mode_changed, this), &p2);
441 ScaleLayout::show_root_state ()
444 /* don't do this stuff if we're not visible */
449 chromatic_text->set_color (change_alpha (chromatic_text->color(), unselected_root_alpha));
450 inkey_text->set_color (change_alpha (inkey_text->color(), 1.0));
452 inkey_text->set_color (change_alpha (chromatic_text->color(), unselected_root_alpha));
453 chromatic_text->set_color (change_alpha (inkey_text->color(), 1.0));
456 Pango::FontDescription fd_bold ("Sans Bold 10");
457 Pango::FontDescription fd ("Sans 10");
459 uint32_t highlight_text = 0;
460 vector<Text*>* none_text_array;
461 vector<Text*>* one_text_array;
464 switch (p2.scale_root()) {
467 none_text_array = &lower_text;
468 one_text_array = &upper_text;
473 none_text_array = &lower_text;
474 one_text_array = &upper_text;
479 none_text_array = &lower_text;
480 one_text_array = &upper_text;
485 none_text_array = &upper_text;
486 one_text_array = &lower_text;
491 none_text_array = &lower_text;
492 one_text_array = &upper_text;
497 none_text_array = &upper_text;
498 one_text_array = &lower_text;
503 none_text_array = &upper_text;
504 one_text_array = &lower_text;
509 none_text_array = &lower_text;
510 one_text_array = &upper_text;
515 none_text_array = &upper_text;
516 one_text_array = &lower_text;
521 none_text_array = &lower_text;
522 one_text_array = &upper_text;
527 none_text_array = &upper_text;
528 one_text_array = &lower_text;
533 none_text_array = &lower_text;
534 one_text_array = &upper_text;
539 if (none_text_array) {
541 for (uint32_t nn = 1; nn < 7; ++nn) {
542 (*none_text_array)[nn]->set_font_description (fd);
543 (*none_text_array)[nn]->set_color (change_alpha ((*none_text_array)[nn]->color(), unselected_root_alpha));
545 if (nn == highlight_text) {
546 (*one_text_array)[nn]->set_font_description (fd_bold);
547 (*one_text_array)[nn]->set_color (change_alpha ((*one_text_array)[nn]->color(), 1.0));
549 (*one_text_array)[nn]->set_font_description (fd);
550 (*one_text_array)[nn]->set_color (change_alpha ((*one_text_array)[nn]->color(), unselected_root_alpha));
556 Push2::Button* b = p2.button_by_id (bid);
558 if (b != root_button) {
560 /* turn the old one off (but not totally) */
561 root_button->set_color (Push2::LED::DarkGray);
562 root_button->set_state (Push2::LED::OneShot24th);
563 p2.write (root_button->state_msg());
569 /* turn the new one on */
570 root_button->set_color (Push2::LED::White);
571 root_button->set_state (Push2::LED::OneShot24th);
572 p2.write (root_button->state_msg());
576 scale_menu->set_active ((uint32_t) p2.mode ());
580 ScaleLayout::mode_changed ()
582 MusicalMode::Type m = (MusicalMode::Type) scale_menu->active();
583 p2.set_pad_scale (p2.scale_root(), p2.root_octave(), m, p2.in_key());
587 ScaleLayout::menu_rearranged ()
589 if (scale_menu->can_scroll_left()) {
590 left_scroll_text->set ("<");
593 left_scroll_text->set (string());
597 if (scale_menu->can_scroll_right()) {
598 right_scroll_text->set (">");
600 right_scroll_text->set (string());
605 ScaleLayout::update_cursor_buttons ()
610 b = p2.button_by_id (Push2::Up);
613 if (scale_menu->active() == 0) {
614 if (b->color_index() != Push2::LED::Black) {
615 b->set_color (Push2::LED::Black);
619 if (b->color_index() != Push2::LED::White) {
620 b->set_color (Push2::LED::White);
626 b->set_state (Push2::LED::OneShot24th);
627 p2.write (b->state_msg());
632 b = p2.button_by_id (Push2::Down);
635 if (scale_menu->active() == scale_menu->items() - 1) {
636 if (b->color_index() != Push2::LED::Black) {
637 b->set_color (Push2::LED::Black);
641 if (b->color_index() != Push2::LED::White) {
642 b->set_color (Push2::LED::White);
648 b->set_color (Push2::LED::OneShot24th);
649 p2.write (b->state_msg());
654 b = p2.button_by_id (Push2::Left);
657 if (scale_menu->active() < scale_menu->rows()) {
658 if (b->color_index() != Push2::LED::Black) {
659 b->set_color (Push2::LED::Black);
663 if (b->color_index() != Push2::LED::White) {
664 b->set_color (Push2::LED::White);
670 b->set_color (Push2::LED::OneShot24th);
671 p2.write (b->state_msg());
676 b = p2.button_by_id (Push2::Right);
679 if (scale_menu->active() > (scale_menu->items() - scale_menu->rows())) {
680 if (b->color_index() != Push2::LED::Black) {
681 b->set_color (Push2::LED::Black);
685 if (b->color_index() != Push2::LED::White) {
686 b->set_color (Push2::LED::White);
693 b->set_color (Push2::LED::OneShot24th);
694 p2.write (b->state_msg());