Unconditionally save instant.xml on session-close
[ardour.git] / gtk2_ardour / note_base.cc
index 52ee88a2d6794b4766a96b5fdc10b8b3018cf4f4..3e6bb402dab9a3ea5e423a8d6adb09b18124a1fb 100644 (file)
@@ -1,27 +1,29 @@
 /*
-    Copyright (C) 2007 Paul Davis
-    Author: David Robillard
-
-    This program is free software; you can redistribute it and/or modify
-    it under the terms of the GNU General Public License as published by
-    the Free Software Foundation; either version 2 of the License, or
-    (at your option) any later version.
-
-    This program is distributed in the hope that it will be useful,
-    but WITHOUT ANY WARRANTY; without even the implied warranty of
-    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-    GNU General Public License for more details.
-
-    You should have received a copy of the GNU General Public License
-    along with this program; if not, write to the Free Software
-    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
-*/
+ * Copyright (C) 2013-2018 Paul Davis <paul@linuxaudiosystems.com>
+ * Copyright (C) 2014 David Robillard <d@drobilla.net>
+ * Copyright (C) 2015 Tim Mayberry <mojofunk@gmail.com>
+ * Copyright (C) 2016 Nick Mainsbridge <mainsbridge@gmail.com>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ */
 
 #include <iostream>
 
 #include "gtkmm2ext/keyboard.h"
 
-#include "evoral/Note.hpp"
+#include "evoral/Note.h"
 
 #include "canvas/text.h"
 
@@ -44,23 +46,19 @@ const uint32_t NoteBase::midi_channel_colors[16] = {
          0x832dd3ff,  0xa92dd3ff,  0xd32dbfff,  0xd32d67ff
        };
 
-bool     NoteBase::_color_init = false;
-uint32_t NoteBase::_selected_mod_col = 0;
-uint32_t NoteBase::_selected_outline_col = 0;
-uint32_t NoteBase::_selected_col = 0;
-uint32_t NoteBase::_min_col = 0;
-uint32_t NoteBase::_mid_col = 0;
-uint32_t NoteBase::_max_col = 0;
+bool             NoteBase::_color_init = false;
+Gtkmm2ext::Color NoteBase::_selected_col = 0;
+Gtkmm2ext::SVAModifier NoteBase::color_modifier;
+Gtkmm2ext::Color NoteBase::velocity_color_table[128];
 
 void
 NoteBase::set_colors ()
 {
-       _selected_mod_col = UIConfiguration::instance().color_mod ("midi note selected", "midi note");
-       _selected_outline_col = UIConfiguration::instance().color ("midi note selected outline");
-       _selected_col = UIConfiguration::instance().color ("midi note selected");
-       _min_col = UIConfiguration::instance().color_mod ("midi note min", "midi note");
-       _mid_col = UIConfiguration::instance().color_mod ("midi note mid", "midi note");
-       _max_col = UIConfiguration::instance().color_mod ("midi note max", "midi note");
+       for (uint8_t i = 0; i < 128; ++i) {
+               velocity_color_table[i] = 0; /* out of bounds because zero alpha makes no sense  */
+       }
+       _selected_col = UIConfiguration::instance().color ("midi note selected outline");
+       color_modifier = UIConfiguration::instance().modifier ("midi note");
 }
 
 NoteBase::NoteBase(MidiRegionView& region, bool with_events, const boost::shared_ptr<NoteType> note)
@@ -331,20 +329,38 @@ NoteBase::big_enough_to_trim () const
 }
 
 
-uint32_t
-NoteBase::meter_style_fill_color(uint8_t vel, bool selected)
+Gtkmm2ext::Color
+NoteBase::meter_style_fill_color(uint8_t vel, bool /* selected */)
 {
-       if (vel < 32) {
-               return UINT_INTERPOLATE(UIConfiguration::instance().color ("midi meter color0"), UIConfiguration::instance().color ("midi meter color1"), (vel / 32.0));
-       } else if (vel < 64) {
-               return UINT_INTERPOLATE(UIConfiguration::instance().color ("midi meter color2"), UIConfiguration::instance().color ("midi meter color3"), ((vel-32) / 32.0));
-       } else if (vel < 100) {
-               return UINT_INTERPOLATE(UIConfiguration::instance().color ("midi meter color4"), UIConfiguration::instance().color ("midi meter color5"), ((vel-64) / 32.0));
-       } else if (vel < 112) {
-               return UINT_INTERPOLATE(UIConfiguration::instance().color ("midi meter color6"), UIConfiguration::instance().color ("midi meter color7"), ((vel-100) / 36.0));
-       } else {
-               return  UINT_INTERPOLATE(UIConfiguration::instance().color ("midi meter color8"), UIConfiguration::instance().color ("midi meter color9"), ((vel-112) / 17.0));
+       /* note that because vel is uint8_t, we don't need bounds checking for
+          the color lookup table.
+       */
+
+       if (velocity_color_table[vel] == 0) {
+
+               Gtkmm2ext::Color col;
+
+               if (vel < 32) {
+                       col = UINT_INTERPOLATE(UIConfiguration::instance().color ("midi meter color0"), UIConfiguration::instance().color ("midi meter color1"), (vel / 32.0));
+                       col = Gtkmm2ext::change_alpha (col, color_modifier.a());
+               } else if (vel < 64) {
+                       col = UINT_INTERPOLATE(UIConfiguration::instance().color ("midi meter color2"), UIConfiguration::instance().color ("midi meter color3"), ((vel-32) / 32.0));
+                       col = Gtkmm2ext::change_alpha (col, color_modifier.a());
+               } else if (vel < 100) {
+                       col = UINT_INTERPOLATE(UIConfiguration::instance().color ("midi meter color4"), UIConfiguration::instance().color ("midi meter color5"), ((vel-64) / 36.0));
+                       col = Gtkmm2ext::change_alpha (col, color_modifier.a());
+               } else if (vel < 112) {
+                       col = UINT_INTERPOLATE(UIConfiguration::instance().color ("midi meter color6"), UIConfiguration::instance().color ("midi meter color7"), ((vel-100) / 12.0));
+                       col = Gtkmm2ext::change_alpha (col, color_modifier.a());
+               } else {
+                       col =  UINT_INTERPOLATE(UIConfiguration::instance().color ("midi meter color8"), UIConfiguration::instance().color ("midi meter color9"), ((vel-112) / 17.0));
+                       col = Gtkmm2ext::change_alpha (col, color_modifier.a());
+               }
+
+               velocity_color_table[vel] = col;
+               return col;
        }
-}
 
+       return velocity_color_table[vel];
+}