You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

108 lines
2.8KB

  1. // Copyright 2013 Olivier Gillet.
  2. //
  3. // Author: Olivier Gillet (ol.gillet@gmail.com)
  4. //
  5. // Permission is hereby granted, free of charge, to any person obtaining a copy
  6. // of this software and associated documentation files (the "Software"), to deal
  7. // in the Software without restriction, including without limitation the rights
  8. // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  9. // copies of the Software, and to permit persons to whom the Software is
  10. // furnished to do so, subject to the following conditions:
  11. //
  12. // The above copyright notice and this permission notice shall be included in
  13. // all copies or substantial portions of the Software.
  14. //
  15. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  16. // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  17. // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  18. // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  19. // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  20. // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  21. // THE SOFTWARE.
  22. //
  23. // See http://creativecommons.org/licenses/MIT/ for more information.
  24. //
  25. // -----------------------------------------------------------------------------
  26. //
  27. // Class monitoring a sequence of notes on the MIDI input and automatically
  28. // chosing the best layout
  29. #ifndef YARNS_LAYOUT_CONFIGURATOR_H_
  30. #define YARNS_LAYOUT_CONFIGURATOR_H_
  31. #include "stmlib/stmlib.h"
  32. namespace yarns {
  33. const uint8_t kMaxNumNotes = 8;
  34. class Multi;
  35. class LayoutConfigurator {
  36. public:
  37. LayoutConfigurator() {
  38. learning_ = false;
  39. num_notes_ = 0;
  40. }
  41. ~LayoutConfigurator() { }
  42. void StartLearning() {
  43. num_notes_ = 0;
  44. learning_ = true;
  45. }
  46. void StopLearning(Multi* m);
  47. void RegisterNote(uint8_t channel, uint8_t note) {
  48. if (num_notes_ < kMaxNumNotes) {
  49. NoteEntry n;
  50. n.channel = channel;
  51. n.note = note;
  52. recorded_notes_[num_notes_] = n;
  53. num_notes_++;
  54. }
  55. }
  56. inline bool learning() const {
  57. return learning_ && num_notes_ < kMaxNumNotes;
  58. }
  59. inline uint8_t num_notes() const {
  60. return num_notes_;
  61. }
  62. private:
  63. struct NoteEntry {
  64. uint8_t channel;
  65. uint8_t note;
  66. };
  67. struct Split {
  68. uint8_t channel;
  69. uint8_t split_point;
  70. };
  71. struct SplitLess {
  72. bool operator()(const Split& lhs, const Split& rhs) {
  73. if (lhs.channel == rhs.channel) {
  74. return lhs.split_point < rhs.split_point;
  75. } else {
  76. return lhs.channel < rhs.channel;
  77. }
  78. }
  79. };
  80. bool learning_;
  81. uint8_t num_notes_;
  82. NoteEntry recorded_notes_[kMaxNumNotes];
  83. Split splits_[kMaxNumNotes];
  84. DISALLOW_COPY_AND_ASSIGN(LayoutConfigurator);
  85. };
  86. extern Multi multi;
  87. } // namespace yarns
  88. #endif // YARNS_LAYOUT_CONFIGURATOR_H_