Entropy Piano Tuner  1.1.3 (documentation not yet complete)
An open-source experimental software for piano tuning by entropy minimization
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
Go to the documentation of this file.
1 /*****************************************************************************
2  * Copyright 2015 Haye Hinrichsen, Christoph Wick
3  *
4  * This file is part of Entropy Piano Tuner.
5  *
6  * Entropy Piano Tuner is free software: you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by the
8  * Free Software Foundation, either version 3 of the License, or (at your
9  * option) any later version.
10  *
11  * Entropy Piano Tuner is distributed in the hope that it will be useful, but
12  * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
13  * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
14  * more details.
15  *
16  * You should have received a copy of the GNU General Public License along with
17  * Entropy Piano Tuner. If not, see http://www.gnu.org/licenses/.
18  *****************************************************************************/
20 //=============================================================================
21 // Class describing the piano keyboard, holding a collection of keys
22 //=============================================================================
24 #ifndef KEYBOARD_H
25 #define KEYBOARD_H
27 #include "key.h"
28 #include "pianodefines.h"
39 class Keyboard
40 {
41 public:
42  using Keys = std::vector<Key>;
44 public:
45  Keyboard(size_t initialSize);
48  size_t size() const {return mKeys.size();}
49  void resize(size_t newSize) { mKeys.resize(newSize); };
51  void changeKeyboardConfiguration (int numberOfKeys, int keyNumberOfA);
53  void clearAllKeys();
54  void clearComputedPitches();
55  void clearTunedPitches();
56  void clearOverpulls();
58  // Access operators:
59  const Key &operator[](size_t i) const {return mKeys[i];}
60  Key &operator[](size_t i) {return mKeys[i];}
61  const Key &at(size_t i) const {return mKeys[i];}
62  Key &at(size_t i) {return mKeys[i];}
64  // get pointer to a particular key
65  const Key *getKeyPtr(int i) const;
66  Key *getKeyPtr(int i);
68  // get a reference to the key vector
69  Keys &getKeys() {return mKeys;}
71  // access functions
72  int getNumberOfKeys() const {return static_cast<int>(size());}
73  int getKeyNumberOfA4() const {return mKeyNumberOfA4;}
75  int getNumberOfBassKeys() const {return mNumberOfBassKeys;}
77  void setNumberOfBassKeys(int keys) {mNumberOfBassKeys = keys;}
80  // compute note name and color
81  std::string getNoteName (int keynumber) const;
82  piano::KeyColor getKeyColor (int keynumber) const;
84 private:
88 };
90 #endif // KEYBOARD_H
Keys mKeys
Vector holding the keys.
Definition: keyboard.h:85
Key & operator[](size_t i)
Definition: keyboard.h:60
Class describing the piano keyboard, holding a collection of keys.
Definition: keyboard.h:39
void clearOverpulls()
Set all overpull markers to zero.
Definition: keyboard.cpp:54
void changeKeyboardConfiguration(int numberOfKeys, int keyNumberOfA)
Change keyboard configuration.
Definition: keyboard.cpp:73
const Key & at(size_t i) const
Definition: keyboard.h:61
void resize(size_t newSize)
Definition: keyboard.h:49
Class describing a single piano key.
Definition: key.h:45
const Key * getKeyPtr(int i) const
Get pointer to a key with a given number, returning nullptr if the number is out of range (read-only ...
Definition: keyboard.cpp:104
int & getKeyNumberOfA4()
Definition: keyboard.h:74
int getNumberOfBassKeys() const
Definition: keyboard.h:75
Definition: keyboard.h:46
The KeyColor enum.
Definition: pianodefines.h:51
void clearComputedPitches()
Set all computed pitches to zero.
Definition: keyboard.cpp:48
Keys & getKeys()
Definition: keyboard.h:69
void clearTunedPitches()
Set all tuned pitches to zero.
Definition: keyboard.cpp:51
std::string getNoteName(int keynumber) const
Get the name of the key as a string.
Definition: keyboard.cpp:135
size_t size() const
Definition: keyboard.h:48
void clearAllKeys()
Clear all keys completely.
Definition: keyboard.cpp:45
Key & at(size_t i)
Definition: keyboard.h:62
Keyboard(size_t initialSize)
Keyboard constructor.
Definition: keyboard.cpp:33
int getKeyNumberOfA4() const
Definition: keyboard.h:73
const Key & operator[](size_t i) const
Definition: keyboard.h:59
void setNumberOfBassKeys(int keys)
Definition: keyboard.h:77
int & getNumberOfBassKeys()
Definition: keyboard.h:76
std::vector< Key > Keys
Definition: keyboard.h:42
int getNumberOfKeys() const
Definition: keyboard.h:72
piano::KeyColor getKeyColor(int keynumber) const
Get the color of the key (black / white)
Definition: keyboard.cpp:160
int mKeyNumberOfA4
Index of the key A4 (440Hz)
Definition: keyboard.h:86
int mNumberOfBassKeys
Number of keys on bass bridge.
Definition: keyboard.h:87