1 /* PianoWidget.cpp
2 * Copyright (C) 2019 Sven Jähnichen
3 *
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 3 of the License, or
7 * (at your option) any later version.
8 *
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.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program. If not, see <https://www.gnu.org/licenses/>.
16 */
17
18 #include "PianoWidget.hpp"
19
20 namespace BWidgets
21 {
22
PianoWidget()23 PianoWidget::PianoWidget () : PianoWidget (0, 0, 0, 0, "piano", 0, 0) {}
24
PianoWidget(const double x,const double y,const double width,const double height,const std::string & name)25 PianoWidget::PianoWidget (const double x, const double y, const double width, const double height, const std::string& name) :
26 PianoWidget (x, y, width, height, name, 0, 119) {}
27
PianoWidget(const double x,const double y,const double width,const double height,const std::string & name,const int startMidiKey,const int endMidiKey)28 PianoWidget::PianoWidget (const double x, const double y, const double width, const double height, const std::string& name,
29 const int startMidiKey, const int endMidiKey) :
30 Widget (x, y, width, height, name),
31 startMidiKey (startMidiKey), endMidiKey (endMidiKey),
32 activeKeys (endMidiKey - startMidiKey + 1, true), pressedKeys (endMidiKey - startMidiKey + 1, false) {}
33
clone() const34 Widget* PianoWidget::clone () const {return new PianoWidget (*this);}
35
pressKeys(std::vector<bool> & keys)36 void PianoWidget::pressKeys (std::vector<bool>& keys)
37 {
38 if (((int) keys.size()) == endMidiKey - startMidiKey + 1) pressedKeys = keys;
39 // TODO else throw exception
40 update ();
41 }
42
getPressedKeys() const43 std::vector<bool> PianoWidget::getPressedKeys () const {return pressedKeys;}
44
activateKeys(std::vector<bool> & keys)45 void PianoWidget::activateKeys (std::vector<bool>& keys)
46 {
47 if (((int) keys.size()) == endMidiKey - startMidiKey + 1) activeKeys = keys;
48 // TODO else throw exception
49 update ();
50 }
51
getActiveKeys() const52 std::vector<bool> PianoWidget::getActiveKeys () const {return activeKeys;}
53
54 }
55