From 7f88c71bd3cac463a4077bd0d457ec612a4639fa Mon Sep 17 00:00:00 2001 From: Paul Davis Date: Mon, 8 Nov 2021 12:39:15 -0700 Subject: [PATCH] implement MusicalKey::in_key() Limited to 12 tones per octave for now --- libs/ardour/key.cc | 28 +++++++++++++++++++++++++--- 1 file changed, 25 insertions(+), 3 deletions(-) diff --git a/libs/ardour/key.cc b/libs/ardour/key.cc index 10cdbbdff2..e955eba231 100644 --- a/libs/ardour/key.cc +++ b/libs/ardour/key.cc @@ -18,15 +18,37 @@ #include "ardour/key.h" +MusicalKey::~MusicalKey () +{ +} + void MusicalKey::set_root (int r) { - _root = r; + /* force root into lowest octave. Yes, 12 tone for now */ + _root = (r % 12); } bool MusicalKey::in_key (int note) const { - return true; -} + /* currently 12 tone based */ + note = note % 12; + + /* we should speed this us. Probably a bitset */ + + if (note == _root) { + return true; + } + + for (std::vector::const_iterator i = steps.begin(); i != steps.end(); ++i) { + int ii = (int) ((*i) * 2.0); + + if (note == _root + ii) { + return true; + } + } + + return false; +}