summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndré Nusser <andre.nusser@googlemail.com>2018-06-09 17:37:23 +0200
committerBent Bisballe Nyeng <deva@aasimon.org>2018-08-12 11:13:51 +0200
commit31dd927c43f72e76ecb61ea02a7832698b7a9496 (patch)
treec5edd7e3d698a95812e4b752c1a387899d6d1cd5
parent873a12d313541e6c82ec9995473bb6f43e7667e8 (diff)
Add map to get instrument name from colour.
-rw-r--r--plugingui/colour.h9
-rw-r--r--plugingui/drumkittab.cc15
-rw-r--r--plugingui/drumkittab.h2
3 files changed, 22 insertions, 4 deletions
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<float, 4> 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>(image_file);
map_image = std::make_unique<Image>(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 <unordered_map>
#include <memory>
#include <string>
@@ -59,6 +60,7 @@ public:
private:
float current_velocity = .5;
+ std::unordered_map<Colour, std::string, ColourHasher> colour_to_instrument;
std::unique_ptr<Image> drumkit_image;
std::unique_ptr<Image> map_image;