Operations.h 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  1. #ifndef PADSELECTIONCONFIGURATION_H
  2. #define PADSELECTIONCONFIGURATION_H
  3. class MidiMessage;
  4. #include <json/json.h>
  5. class PadSelection;
  6. class InputOperation
  7. {
  8. public:
  9. enum OperationType {TRANSLATION, DROP, RANGE, REORDER};
  10. InputOperation(OperationType t) : m_type(t){}
  11. virtual ~InputOperation(){}
  12. virtual MidiMessage* execute(PadSelection*, MidiMessage* in, int i) const=0;
  13. OperationType get_type() const {return m_type;}
  14. static InputOperation* from_json(Json::Value&);
  15. protected:
  16. OperationType m_type;
  17. };
  18. class TranslationOperation : public InputOperation
  19. {
  20. public:
  21. enum Mode {FIXED, RELATIVE, UNCHANGED};
  22. TranslationOperation() : InputOperation(TRANSLATION){
  23. m_channel=m_key=m_velocity=0;
  24. m_channel_mode=m_key_mode=m_velocity_mode=RELATIVE;
  25. }
  26. TranslationOperation(Json::Value& v);
  27. virtual ~TranslationOperation(){}
  28. void set(int ch, int k, int vel){
  29. m_channel=ch;
  30. m_key=k;
  31. m_velocity=vel;
  32. }
  33. void set_mode(Mode ch, Mode k, Mode vel){
  34. if(ch!=UNCHANGED) m_channel_mode=ch;
  35. if(k!=UNCHANGED) m_key_mode=k;
  36. if(vel!=UNCHANGED) m_velocity_mode=vel;
  37. }
  38. virtual MidiMessage* execute(PadSelection*, MidiMessage* m, int i) const;
  39. static Mode parse_mode(const std::string& v);
  40. protected:
  41. Mode m_channel_mode;
  42. int m_channel;
  43. Mode m_key_mode;
  44. int m_key;
  45. Mode m_velocity_mode;
  46. int m_velocity;
  47. };
  48. class DropOperation : public InputOperation
  49. {
  50. public:
  51. enum Mode {FIXED, RELATIVE, UNCHANGED};
  52. DropOperation() : InputOperation(DROP){
  53. }
  54. virtual ~DropOperation(){}
  55. virtual MidiMessage* execute(PadSelection*, MidiMessage* m, int i) const {return NULL;}
  56. protected:
  57. };
  58. class ReorderOperation : public InputOperation
  59. {
  60. public:
  61. ReorderOperation() : InputOperation(REORDER){
  62. m_offset=0;
  63. }
  64. ReorderOperation(Json::Value& v);
  65. virtual ~ReorderOperation(){}
  66. virtual MidiMessage* execute(PadSelection*, MidiMessage* m, int i) const ;
  67. protected:
  68. int m_offset;
  69. };
  70. class RangeOperation : public InputOperation
  71. {
  72. public:
  73. RangeOperation() : InputOperation(RANGE){
  74. }
  75. RangeOperation(Json::Value& v) : InputOperation(RANGE)
  76. {
  77. m_key = v["key"].asInt();
  78. m_length = v["length"].asInt();
  79. Json::Value a = v["range"];
  80. int s = a.size();
  81. for(int i=0; i<s; i++) m_range.push_back(a[i].asInt());
  82. }
  83. virtual ~RangeOperation(){}
  84. virtual MidiMessage* execute(PadSelection*, MidiMessage* m, int i) const;
  85. protected:
  86. std::vector<int> m_range;
  87. int m_key;
  88. int m_length;
  89. };
  90. #endif // PADSELECTIONCONFIGURATION_H