| 1 |
/* |
| 2 |
* Copyright (C) 2018-2022 Rerrah |
| 3 |
* |
| 4 |
* Permission is hereby granted, free of charge, to any person |
| 5 |
* obtaining a copy of this software and associated documentation |
| 6 |
* files (the "Software"), to deal in the Software without |
| 7 |
* restriction, including without limitation the rights to use, |
| 8 |
* copy, modify, merge, publish, distribute, sublicense, and/or sell |
| 9 |
* copies of the Software, and to permit persons to whom the |
| 10 |
* Software is furnished to do so, subject to the following |
| 11 |
* conditions: |
| 12 |
* |
| 13 |
* The above copyright notice and this permission notice shall be |
| 14 |
* included in all copies or substantial portions of the Software. |
| 15 |
* |
| 16 |
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, |
| 17 |
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES |
| 18 |
* OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND |
| 19 |
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT |
| 20 |
* HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, |
| 21 |
* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING |
| 22 |
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR |
| 23 |
* OTHER DEALINGS IN THE SOFTWARE. |
| 24 |
*/ |
| 25 |
|
| 26 |
#pragma once |
| 27 |
|
| 28 |
#include <string> |
| 29 |
#include <stdexcept> |
| 30 |
|
| 31 |
class Step |
| 32 |
{ |
| 33 |
public: |
| 34 |
Step(); |
| 35 |
|
| 36 |
enum NoteValue : int |
| 37 |
{ |
| 38 |
NOTE_NONE = -1, |
| 39 |
// Special notes |
| 40 |
NOTE_KEY_OFF = -2, |
| 41 |
NOTE_ECHO0 = -3, |
| 42 |
NOTE_ECHO1 = -4, |
| 43 |
NOTE_ECHO2 = -5, |
| 44 |
NOTE_ECHO3 = -6, |
| 45 |
NOTE_KEY_CUT = -7, |
| 46 |
}; |
| 47 |
int getNoteNumber() const noexcept { return note_; } |
| 48 |
void setNoteNumber(int num) { note_ = num; } |
| 49 |
void setKeyOff() { note_ = NOTE_KEY_OFF; } |
| 50 |
void setKeyCut() { note_ = NOTE_KEY_CUT; } |
| 51 |
void setEchoBuffer(int n) { note_ = NOTE_ECHO0 - n; } |
| 52 |
void clearNoteNumber() noexcept { note_ = NOTE_NONE; } |
| 53 |
bool hasGeneralNote() const noexcept { return note_ > NOTE_NONE; } |
| 54 |
bool hasKeyOff() const noexcept { return note_ == NOTE_KEY_OFF; } |
| 55 |
bool hasKeyCut() const noexcept { return note_ == NOTE_KEY_CUT; } |
| 56 |
bool hasNoteEchoBuffer(int n) const { return note_ == (NOTE_ECHO0 - n); } |
| 57 |
bool isEmptyNote() const noexcept { return note_ == NOTE_NONE; } |
| 58 |
|
| 59 |
static bool testEmptyNote(int note) { return note == NOTE_NONE; } |
| 60 |
|
| 61 |
static constexpr int INST_NONE = -1; |
| 62 |
int getInstrumentNumber() const noexcept { return inst_; } |
| 63 |
void setInstrumentNumber(int num) { inst_ = num; } |
| 64 |
void clearInstrumentNumber() noexcept { inst_ = INST_NONE; } |
| 65 |
bool hasInstrument() const noexcept { return inst_ != INST_NONE; } |
| 66 |
|
| 67 |
static bool testEmptyInstrument(int inst) { return inst == INST_NONE; } |
| 68 |
|
| 69 |
static constexpr int VOLUME_NONE = -1; |
| 70 |
int getVolume() const noexcept { return vol_; } |
| 71 |
void setVolume(int volume) { vol_ = volume; } |
| 72 |
void clearVolume() noexcept { vol_ = VOLUME_NONE; } |
| 73 |
bool hasVolume() const noexcept { return vol_ != VOLUME_NONE; } |
| 74 |
|
| 75 |
static bool testEmptyVolume(int vol) { return vol == VOLUME_NONE; } |
| 76 |
|
| 77 |
static const std::string EFF_ID_NONE; // "--" |
| 78 |
std::string getEffectId(int n) const { return eff_[n].id; } |
| 79 |
void setEffectId(int n, const std::string& str) { eff_[n].id = str; } |
| 80 |
void clearEffectId(int n) { eff_[n].id = EFF_ID_NONE; } |
| 81 |
bool hasEffectId(int n) const { return eff_[n].id != EFF_ID_NONE; } |
| 82 |
|
| 83 |
static bool testEmptyEffectId(const std::string& id) { return id == EFF_ID_NONE; } |
| 84 |
|
| 85 |
static constexpr int EFF_VAL_NONE = -1; |
| 86 |
int getEffectValue(int n) const { return eff_[n].value; } |
| 87 |
void setEffectValue(int n, int v) { eff_[n].value = v; } |
| 88 |
void clearEffectValue(int n) { eff_[n].value = EFF_VAL_NONE; } |
| 89 |
bool hasEffectValue(int n) const { return eff_[n].value != EFF_VAL_NONE; } |
| 90 |
|
| 91 |
static bool testEmptyEffectValue(int v) { return v == EFF_VAL_NONE; } |
| 92 |
|
| 93 |
struct PlainEffect |
| 94 |
{ |
| 95 |
std::string id; |
| 96 |
int value; |
| 97 |
}; |
| 98 |
|
| 99 |
static constexpr int N_EFFECT = 4; |
| 100 |
|
| 101 |
PlainEffect getEffect(int n) const { return eff_[n]; } |
| 102 |
void setEffect(int n, const PlainEffect& effect) { eff_[n] = effect; } |
| 103 |
void setEffect(int n, const std::string& id, int value) |
| 104 |
{ |
| 105 |
setEffectId(n, id); |
| 106 |
setEffectValue(n, value); |
| 107 |
} |
| 108 |
void clearEffect(int n) |
| 109 |
{ |
| 110 |
clearEffectId(n); |
| 111 |
clearEffectValue(n); |
| 112 |
} |
| 113 |
|
| 114 |
static constexpr int N_COLUMN = 3 + N_EFFECT * 2; |
| 115 |
|
| 116 |
void clear(); |
| 117 |
|
| 118 |
bool hasEvent() const; |
| 119 |
|
| 120 |
private: |
| 121 |
/// noteNum_ |
| 122 |
/// 0<=: note number (key on) |
| 123 |
/// -1: none |
| 124 |
/// -2: key off |
| 125 |
/// -3: echo previous note |
| 126 |
/// -4: echo 2 notes before |
| 127 |
/// -5: echo 3 notes before |
| 128 |
/// -6: echo 4 notes before |
| 129 |
/// -7: key cut |
| 130 |
int note_; |
| 131 |
/// instNum_ |
| 132 |
/// 0<=: instrument number |
| 133 |
/// -1: none |
| 134 |
int inst_; |
| 135 |
/// vol_ |
| 136 |
/// 0<=: volume level |
| 137 |
/// -1: none |
| 138 |
int vol_; |
| 139 |
/// eff |
| 140 |
/// [id] |
| 141 |
/// "--": none |
| 142 |
/// other: effect ID |
| 143 |
/// [value] |
| 144 |
/// 0<=: effect value |
| 145 |
/// -1: none |
| 146 |
PlainEffect eff_[N_EFFECT]; |
| 147 |
}; |