InstrumentFunctions.h 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215
  1. /*
  2. * InstrumentFunctions.h - models for instrument-functions-tab
  3. *
  4. * Copyright (c) 2004-2014 Tobias Doerffel <tobydox/at/users.sourceforge.net>
  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 INSTRUMENT_FUNCTIONS_H
  25. #define INSTRUMENT_FUNCTIONS_H
  26. #include "JournallingObject.h"
  27. #include "lmms_basics.h"
  28. #include "AutomatableModel.h"
  29. #include "TempoSyncKnobModel.h"
  30. #include "ComboBoxModel.h"
  31. class InstrumentTrack;
  32. class NotePlayHandle;
  33. class InstrumentFunctionNoteStacking : public Model, public JournallingObject
  34. {
  35. Q_OBJECT
  36. public:
  37. static const int MAX_CHORD_POLYPHONY = 13;
  38. private:
  39. typedef int8_t ChordSemiTones [MAX_CHORD_POLYPHONY];
  40. public:
  41. InstrumentFunctionNoteStacking( Model * _parent );
  42. virtual ~InstrumentFunctionNoteStacking();
  43. void processNote( NotePlayHandle* n );
  44. void saveSettings( QDomDocument & _doc, QDomElement & _parent ) override;
  45. void loadSettings( const QDomElement & _this ) override;
  46. inline QString nodeName() const override
  47. {
  48. return "chordcreator";
  49. }
  50. struct Chord
  51. {
  52. private:
  53. QString m_name;
  54. ChordSemiTones m_semiTones;
  55. int m_size;
  56. public:
  57. Chord() : m_size( 0 ) {}
  58. Chord( const char * n, const ChordSemiTones & semi_tones );
  59. int size() const
  60. {
  61. return m_size;
  62. }
  63. bool isScale() const
  64. {
  65. return size() > 6;
  66. }
  67. bool isEmpty() const
  68. {
  69. return size() == 0;
  70. }
  71. bool hasSemiTone( int8_t semiTone ) const;
  72. int8_t last() const
  73. {
  74. return m_semiTones[size() - 1];
  75. }
  76. const QString & getName() const
  77. {
  78. return m_name;
  79. }
  80. int8_t operator [] ( int n ) const
  81. {
  82. return m_semiTones[n];
  83. }
  84. };
  85. struct ChordTable : public QVector<Chord>
  86. {
  87. private:
  88. ChordTable();
  89. struct Init
  90. {
  91. const char * m_name;
  92. ChordSemiTones m_semiTones;
  93. };
  94. static Init s_initTable[];
  95. public:
  96. static const ChordTable & getInstance()
  97. {
  98. static ChordTable inst;
  99. return inst;
  100. }
  101. const Chord & getByName( const QString & name, bool is_scale = false ) const;
  102. const Chord & getScaleByName( const QString & name ) const
  103. {
  104. return getByName( name, true );
  105. }
  106. const Chord & getChordByName( const QString & name ) const
  107. {
  108. return getByName( name, false );
  109. }
  110. };
  111. private:
  112. BoolModel m_chordsEnabledModel;
  113. ComboBoxModel m_chordsModel;
  114. FloatModel m_chordRangeModel;
  115. friend class InstrumentFunctionNoteStackingView;
  116. } ;
  117. class InstrumentFunctionArpeggio : public Model, public JournallingObject
  118. {
  119. Q_OBJECT
  120. public:
  121. enum ArpDirections
  122. {
  123. ArpDirUp,
  124. ArpDirDown,
  125. ArpDirUpAndDown,
  126. ArpDirDownAndUp,
  127. ArpDirRandom,
  128. NumArpDirections
  129. } ;
  130. InstrumentFunctionArpeggio( Model * _parent );
  131. virtual ~InstrumentFunctionArpeggio();
  132. void processNote( NotePlayHandle* n );
  133. void saveSettings( QDomDocument & _doc, QDomElement & _parent ) override;
  134. void loadSettings( const QDomElement & _this ) override;
  135. inline QString nodeName() const override
  136. {
  137. return "arpeggiator";
  138. }
  139. private:
  140. enum ArpModes
  141. {
  142. FreeMode,
  143. SortMode,
  144. SyncMode
  145. } ;
  146. BoolModel m_arpEnabledModel;
  147. ComboBoxModel m_arpModel;
  148. FloatModel m_arpRangeModel;
  149. FloatModel m_arpCycleModel;
  150. FloatModel m_arpSkipModel;
  151. FloatModel m_arpMissModel;
  152. TempoSyncKnobModel m_arpTimeModel;
  153. FloatModel m_arpGateModel;
  154. ComboBoxModel m_arpDirectionModel;
  155. ComboBoxModel m_arpModeModel;
  156. friend class InstrumentTrack;
  157. friend class InstrumentFunctionArpeggioView;
  158. } ;
  159. #endif