Keymap.h 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. /*
  2. * Keymap.h - holds information about a key mapping
  3. *
  4. * Copyright (c) 2020 Martin Pavelek <he29.HS/at/gmail.com>
  5. *
  6. * This file is part of LMMS - https://lmms.io
  7. *
  8. * This program is free software; you can redistribute it and/or
  9. * modify it under the terms of the GNU General Public
  10. * License as published by the Free Software Foundation; either
  11. * version 2 of the License, or (at your option) any later version.
  12. *
  13. * This program is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  16. * General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU General Public
  19. * License along with this program (see COPYING); if not, write to the
  20. * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
  21. * Boston, MA 02110-1301 USA.
  22. *
  23. */
  24. #ifndef KEYMAP_H
  25. #define KEYMAP_H
  26. #include <vector>
  27. #include <QObject>
  28. #include <QString>
  29. #include "Note.h"
  30. #include "SerializingObject.h"
  31. class Keymap : public QObject, public SerializingObject
  32. {
  33. Q_OBJECT
  34. public:
  35. Keymap();
  36. Keymap(
  37. QString description,
  38. std::vector<int> newMap,
  39. int newFirst,
  40. int newLast,
  41. int newMiddle,
  42. int newBaseKey,
  43. float newBaseFreq
  44. );
  45. QString getDescription() const;
  46. void setDescription(QString description);
  47. int getMiddleKey() const {return m_middleKey;}
  48. int getFirstKey() const {return m_firstKey;}
  49. int getLastKey() const {return m_lastKey;}
  50. int getBaseKey() const {return m_baseKey;}
  51. float getBaseFreq() const {return m_baseFreq;}
  52. std::size_t getSize() const {return m_map.size();}
  53. int getDegree(int key) const;
  54. int getOctave(int key) const;
  55. const std::vector<int> &getMap() const {return m_map;}
  56. void saveSettings(QDomDocument &doc, QDomElement &element) override;
  57. void loadSettings(const QDomElement &element) override;
  58. inline QString nodeName() const override {return "keymap";}
  59. private:
  60. QString m_description; //!< name or description of the keymap
  61. std::vector<int> m_map; //!< key to scale degree mapping
  62. int m_firstKey; //!< first key that will be mapped
  63. int m_lastKey; //!< last key that will be mapped
  64. int m_middleKey; //!< first line of the map refers to this key
  65. int m_baseKey; //!< key which is assigned the reference "base note"
  66. float m_baseFreq; //!< frequency of the base note (usually A4 @440 Hz)
  67. };
  68. #endif