From 31dd927c43f72e76ecb61ea02a7832698b7a9496 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9=20Nusser?= Date: Sat, 9 Jun 2018 17:37:23 +0200 Subject: Add map to get instrument name from colour. --- plugingui/colour.h | 9 +++++++++ plugingui/drumkittab.cc | 15 +++++++++++---- plugingui/drumkittab.h | 2 ++ 3 files changed, 22 insertions(+), 4 deletions(-) (limited to 'plugingui') diff --git a/plugingui/colour.h b/plugingui/colour.h index 3a135fc..232b0b9 100644 --- a/plugingui/colour.h +++ b/plugingui/colour.h @@ -54,4 +54,13 @@ private: std::array data; }; +struct ColourHasher +{ + // TODO: replace by something reasonable + std::size_t operator()(const Colour& colour) const + { + return 7*colour.red() + 11*colour.green() + 13*colour.blue() + 17*colour.alpha(); + } +}; + } // GUI:: diff --git a/plugingui/drumkittab.cc b/plugingui/drumkittab.cc index 91fc801..1dccb52 100644 --- a/plugingui/drumkittab.cc +++ b/plugingui/drumkittab.cc @@ -88,14 +88,14 @@ void DrumkitTab::triggerAudition(int x, int y) { auto map_colour = map_image->getPixel(x, y); - // TODO: convert color to instrument - if (map_colour != Colour(0)) + auto it = colour_to_instrument.find(map_colour); + if (it == colour_to_instrument.end()) { return; } ++settings.audition_counter; - settings.audition_instrument = "Snare"; + settings.audition_instrument = it->second; settings.audition_velocity = current_velocity; } @@ -106,11 +106,18 @@ void DrumkitTab::updateVelocityLabel() velocity_label.setText("Velocity: " + stream.str()); } -// FIXME: this should actually be done somewhere else maybe? void DrumkitTab::loadImageFiles(std::string const& image_file, std::string const& map_file) { drumkit_image = std::make_unique(image_file); map_image = std::make_unique(map_file); + + // TODO: actually use mapping from drumkit file here + colour_to_instrument = { + {Colour(0), "Snare"}, + {Colour(255./255, 15./255, 55./255), "KdrumL"}, + {Colour(154./255, 153./255, 33./255), "HihatClosed"}, + {Colour(248./255, 221./255, 37./255), "Tom4"} + }; } } // GUI:: diff --git a/plugingui/drumkittab.h b/plugingui/drumkittab.h index c53d3f5..5fe234a 100644 --- a/plugingui/drumkittab.h +++ b/plugingui/drumkittab.h @@ -26,6 +26,7 @@ */ #pragma once +#include #include #include @@ -59,6 +60,7 @@ public: private: float current_velocity = .5; + std::unordered_map colour_to_instrument; std::unique_ptr drumkit_image; std::unique_ptr map_image; -- cgit v1.2.3