hydrogen 1.2.6
MidiAction.h
Go to the documentation of this file.
1/*
2 * Hydrogen
3 * Copyright(c) 2002-2008 by Alex >Comix< Cominu [comix@users.sourceforge.net]
4 * Copyright(c) 2008-2025 The hydrogen development team [hydrogen-devel@lists.sourceforge.net]
5 *
6 * http://www.hydrogen-music.org
7 *
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (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
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with this program. If not, see https://www.gnu.org/licenses
20 *
21 */
22#ifndef ACTION_H
23#define ACTION_H
24#include <core/Object.h>
25#include <map>
26#include <memory>
27#include <string>
28#include <cassert>
29
31class Action : public H2Core::Object<Action> {
33 public:
34 static QString getNullActionType() {
35 return "NOTHING";
36 }
37
38 Action( QString sType = getNullActionType() );
39 Action( std::shared_ptr<Action> pOther );
40
42 bool isNull() const;
43
44 void setParameter1( QString text ){
45 m_sParameter1 = text;
46 }
47
48 void setParameter2( QString text ){
49 m_sParameter2 = text;
50 }
51
52 void setParameter3( QString text ){
53 m_sParameter3 = text;
54 }
55
56 void setValue( QString text ){
57 m_sValue = text;
58 }
59
60 QString getParameter1() const {
61 return m_sParameter1;
62 }
63
64 QString getParameter2() const {
65 return m_sParameter2;
66 }
67
68 QString getParameter3() const {
69 return m_sParameter3;
70 }
71
72 QString getValue() const {
73 return m_sValue;
74 }
75
76 QString getType() const {
77 return m_sType;
78 }
79
86 bool isEquivalentTo( std::shared_ptr<Action> pOther );
87
88 friend bool operator ==(const Action& lhs, const Action& rhs ) {
89 return ( lhs.m_sType == rhs.m_sType &&
90 lhs.m_sParameter1 == rhs.m_sParameter1 &&
91 lhs.m_sParameter2 == rhs.m_sParameter2 &&
92 lhs.m_sParameter3 == rhs.m_sParameter3 &&
93 lhs.m_sValue == rhs.m_sValue );
94 }
95 friend bool operator !=(const Action& lhs, const Action& rhs ) {
96 return ( lhs.m_sType != rhs.m_sType ||
97 lhs.m_sParameter1 != rhs.m_sParameter1 ||
98 lhs.m_sParameter2 != rhs.m_sParameter2 ||
99 lhs.m_sParameter3 != rhs.m_sParameter3 ||
100 lhs.m_sValue != rhs.m_sValue );
101 }
102 friend bool operator ==(std::shared_ptr<Action> lhs, std::shared_ptr<Action> rhs ) {
103 return ( lhs->m_sType == rhs->m_sType &&
104 lhs->m_sParameter1 == rhs->m_sParameter1 &&
105 lhs->m_sParameter2 == rhs->m_sParameter2 &&
106 lhs->m_sParameter3 == rhs->m_sParameter3 &&
107 lhs->m_sValue == rhs->m_sValue );
108 }
109 friend bool operator !=(std::shared_ptr<Action> lhs, std::shared_ptr<Action> rhs ) {
110 return ( lhs->m_sType != rhs->m_sType ||
111 lhs->m_sParameter1 != rhs->m_sParameter1 ||
112 lhs->m_sParameter2 != rhs->m_sParameter2 ||
113 lhs->m_sParameter3 != rhs->m_sParameter3 ||
114 lhs->m_sValue != rhs->m_sValue );
115 }
116
125 QString toQString( const QString& sPrefix = "", bool bShort = true ) const override;
126
127 private:
128 QString m_sType;
132 QString m_sValue;
133};
134
135namespace H2Core
136{
137 class Hydrogen;
138}
139
141class MidiActionManager : public H2Core::Object<MidiActionManager>
142{
144 private:
152
157 QStringList m_actionList;
158
159 typedef bool (MidiActionManager::*action_f)(std::shared_ptr<Action> , H2Core::Hydrogen * );
168 std::map<QString, std::pair<action_f,int>> m_actionMap;
169 bool play(std::shared_ptr<Action> , H2Core::Hydrogen * );
170 bool play_stop_pause_toggle(std::shared_ptr<Action> , H2Core::Hydrogen * );
171 bool stop(std::shared_ptr<Action> , H2Core::Hydrogen * );
172 bool pause(std::shared_ptr<Action> , H2Core::Hydrogen * );
173 bool record_ready(std::shared_ptr<Action> , H2Core::Hydrogen * );
174 bool record_strobe_toggle(std::shared_ptr<Action> , H2Core::Hydrogen * );
175 bool record_strobe(std::shared_ptr<Action> , H2Core::Hydrogen * );
176 bool record_exit(std::shared_ptr<Action> , H2Core::Hydrogen * );
177 bool mute(std::shared_ptr<Action> , H2Core::Hydrogen * );
178 bool unmute(std::shared_ptr<Action> , H2Core::Hydrogen * );
179 bool mute_toggle(std::shared_ptr<Action> , H2Core::Hydrogen * );
180 bool strip_mute_toggle(std::shared_ptr<Action> , H2Core::Hydrogen * );
181 bool strip_solo_toggle(std::shared_ptr<Action> , H2Core::Hydrogen * );
182 bool next_bar(std::shared_ptr<Action> , H2Core::Hydrogen * );
183 bool previous_bar(std::shared_ptr<Action> , H2Core::Hydrogen * );
184 bool bpm_increase(std::shared_ptr<Action> , H2Core::Hydrogen * );
185 bool bpm_decrease(std::shared_ptr<Action> , H2Core::Hydrogen * );
186 bool bpm_cc_relative(std::shared_ptr<Action> , H2Core::Hydrogen * );
187 bool bpm_fine_cc_relative(std::shared_ptr<Action> , H2Core::Hydrogen * );
188 bool master_volume_relative(std::shared_ptr<Action> , H2Core::Hydrogen *);
189 bool master_volume_absolute(std::shared_ptr<Action> , H2Core::Hydrogen * );
190 bool strip_volume_relative(std::shared_ptr<Action> , H2Core::Hydrogen * );
191 bool strip_volume_absolute(std::shared_ptr<Action> , H2Core::Hydrogen * );
192 bool effect_level_relative(std::shared_ptr<Action> , H2Core::Hydrogen * );
193 bool effect_level_absolute(std::shared_ptr<Action> , H2Core::Hydrogen * );
194 bool select_next_pattern(std::shared_ptr<Action> , H2Core::Hydrogen * );
195 bool select_only_next_pattern(std::shared_ptr<Action> , H2Core::Hydrogen * );
196 bool select_only_next_pattern_cc_absolute(std::shared_ptr<Action> , H2Core::Hydrogen * );
197 bool select_next_pattern_cc_absolute(std::shared_ptr<Action> , H2Core::Hydrogen * );
198 bool select_next_pattern_relative(std::shared_ptr<Action> , H2Core::Hydrogen * );
199 bool select_and_play_pattern(std::shared_ptr<Action> , H2Core::Hydrogen * );
200 bool pan_relative(std::shared_ptr<Action> , H2Core::Hydrogen * );
201 bool pan_absolute(std::shared_ptr<Action> , H2Core::Hydrogen * );
202 bool pan_absolute_sym(std::shared_ptr<Action> , H2Core::Hydrogen * );
203 bool instrument_pitch(std::shared_ptr<Action> , H2Core::Hydrogen * );
204 bool filter_cutoff_level_absolute(std::shared_ptr<Action> , H2Core::Hydrogen * );
205 bool beatcounter(std::shared_ptr<Action> , H2Core::Hydrogen * );
206 bool tap_tempo(std::shared_ptr<Action> , H2Core::Hydrogen * );
207 bool playlist_song(std::shared_ptr<Action> , H2Core::Hydrogen * );
208 bool playlist_next_song(std::shared_ptr<Action> , H2Core::Hydrogen * );
209 bool playlist_previous_song(std::shared_ptr<Action> , H2Core::Hydrogen * );
210 bool toggle_metronome(std::shared_ptr<Action> , H2Core::Hydrogen * );
211 bool select_instrument(std::shared_ptr<Action> , H2Core::Hydrogen * );
212 bool undo_action(std::shared_ptr<Action> , H2Core::Hydrogen * );
213 bool redo_action(std::shared_ptr<Action> , H2Core::Hydrogen * );
214 bool gain_level_absolute(std::shared_ptr<Action> , H2Core::Hydrogen * );
215 bool pitch_level_absolute(std::shared_ptr<Action> , H2Core::Hydrogen * );
216 bool clear_selected_instrument(std::shared_ptr<Action> , H2Core::Hydrogen * );
217 bool clear_pattern(std::shared_ptr<Action> , H2Core::Hydrogen * );
218
220
221 bool setSong( int nSongNumber, H2Core::Hydrogen* pHydrogen );
222 bool nextPatternSelection( int nPatternNumber );
223 bool onlyNextPatternSelection( int nPatternNumber );
224
225 public:
226
235 bool handleActions( std::vector<std::shared_ptr<Action>> actions );
243 bool handleAction( std::shared_ptr<Action> action );
250 static void create_instance();
256
257 QStringList getActionList(){
258 return m_actionList;
259 }
260
263 int getParameterNumber( const QString& sActionType ) const;
264
267};
268#endif
#define H2_OBJECT(name)
Definition Object.h:227
void setParameter3(QString text)
Definition MidiAction.h:52
void setParameter2(QString text)
Definition MidiAction.h:48
static QString getNullActionType()
Definition MidiAction.h:34
void setParameter1(QString text)
Definition MidiAction.h:44
QString m_sValue
Definition MidiAction.h:132
QString m_sParameter1
Definition MidiAction.h:129
QString m_sParameter2
Definition MidiAction.h:130
QString getType() const
Definition MidiAction.h:76
QString m_sType
Definition MidiAction.h:128
bool isEquivalentTo(std::shared_ptr< Action > pOther)
void setValue(QString text)
Definition MidiAction.h:56
bool isNull() const
Checks whether m_sType is of getNullActionType()
friend bool operator==(const Action &lhs, const Action &rhs)
Definition MidiAction.h:88
QString toQString(const QString &sPrefix="", bool bShort=true) const override
Formatted string version for debugging purposes.
friend bool operator!=(const Action &lhs, const Action &rhs)
Definition MidiAction.h:95
Action(QString sType=getNullActionType())
QString m_sParameter3
Definition MidiAction.h:131
QString getValue() const
Definition MidiAction.h:72
QString getParameter1() const
Definition MidiAction.h:60
QString getParameter2() const
Definition MidiAction.h:64
QString getParameter3() const
Definition MidiAction.h:68
Hydrogen Audio Engine.
Definition Hydrogen.h:54
bool previous_bar(std::shared_ptr< Action >, H2Core::Hydrogen *)
static MidiActionManager * __instance
Object holding the current MidiActionManager singleton.
Definition MidiAction.h:151
bool bpm_decrease(std::shared_ptr< Action >, H2Core::Hydrogen *)
bool record_strobe(std::shared_ptr< Action >, H2Core::Hydrogen *)
bool playlist_next_song(std::shared_ptr< Action >, H2Core::Hydrogen *)
bool setSong(int nSongNumber, H2Core::Hydrogen *pHydrogen)
bool playlist_song(std::shared_ptr< Action >, H2Core::Hydrogen *)
bool unmute(std::shared_ptr< Action >, H2Core::Hydrogen *)
bool strip_volume_absolute(std::shared_ptr< Action >, H2Core::Hydrogen *)
bool play(std::shared_ptr< Action >, H2Core::Hydrogen *)
bool playlist_previous_song(std::shared_ptr< Action >, H2Core::Hydrogen *)
bool select_instrument(std::shared_ptr< Action >, H2Core::Hydrogen *)
int m_nLastBpmChangeCCParameter
Definition MidiAction.h:219
bool mute(std::shared_ptr< Action >, H2Core::Hydrogen *)
bool record_exit(std::shared_ptr< Action >, H2Core::Hydrogen *)
bool master_volume_absolute(std::shared_ptr< Action >, H2Core::Hydrogen *)
bool pitch_level_absolute(std::shared_ptr< Action >, H2Core::Hydrogen *)
bool tap_tempo(std::shared_ptr< Action >, H2Core::Hydrogen *)
bool select_next_pattern_relative(std::shared_ptr< Action >, H2Core::Hydrogen *)
bool handleAction(std::shared_ptr< Action > action)
The handleAction method is the heart of the MidiActionManager class.
bool strip_solo_toggle(std::shared_ptr< Action >, H2Core::Hydrogen *)
bool beatcounter(std::shared_ptr< Action >, H2Core::Hydrogen *)
static MidiActionManager * get_instance()
Returns a pointer to the current MidiActionManager singleton stored in __instance.
Definition MidiAction.h:255
bool clear_pattern(std::shared_ptr< Action >, H2Core::Hydrogen *)
bool pan_absolute(std::shared_ptr< Action >, H2Core::Hydrogen *)
bool instrument_pitch(std::shared_ptr< Action >, H2Core::Hydrogen *)
bool onlyNextPatternSelection(int nPatternNumber)
static void create_instance()
If __instance equals 0, a new MidiActionManager singleton will be created and stored in it.
bool pan_relative(std::shared_ptr< Action >, H2Core::Hydrogen *)
bool pan_absolute_sym(std::shared_ptr< Action >, H2Core::Hydrogen *)
bool select_next_pattern(std::shared_ptr< Action >, H2Core::Hydrogen *)
bool bpm_fine_cc_relative(std::shared_ptr< Action >, H2Core::Hydrogen *)
bool select_and_play_pattern(std::shared_ptr< Action >, H2Core::Hydrogen *)
bool effect_level_absolute(std::shared_ptr< Action >, H2Core::Hydrogen *)
bool redo_action(std::shared_ptr< Action >, H2Core::Hydrogen *)
bool handleActions(std::vector< std::shared_ptr< Action > > actions)
Handles multiple actions at once and calls handleAction() on them.
bool filter_cutoff_level_absolute(std::shared_ptr< Action >, H2Core::Hydrogen *)
bool strip_volume_relative(std::shared_ptr< Action >, H2Core::Hydrogen *)
bool clear_selected_instrument(std::shared_ptr< Action >, H2Core::Hydrogen *)
bool pause(std::shared_ptr< Action >, H2Core::Hydrogen *)
bool next_bar(std::shared_ptr< Action >, H2Core::Hydrogen *)
bool toggle_metronome(std::shared_ptr< Action >, H2Core::Hydrogen *)
bool play_stop_pause_toggle(std::shared_ptr< Action >, H2Core::Hydrogen *)
bool record_strobe_toggle(std::shared_ptr< Action >, H2Core::Hydrogen *)
QStringList getActionList()
Definition MidiAction.h:257
bool select_only_next_pattern_cc_absolute(std::shared_ptr< Action >, H2Core::Hydrogen *)
bool bpm_cc_relative(std::shared_ptr< Action >, H2Core::Hydrogen *)
bool stop(std::shared_ptr< Action >, H2Core::Hydrogen *)
bool record_ready(std::shared_ptr< Action >, H2Core::Hydrogen *)
bool undo_action(std::shared_ptr< Action >, H2Core::Hydrogen *)
bool select_only_next_pattern(std::shared_ptr< Action >, H2Core::Hydrogen *)
QStringList m_actionList
Holds the names of all Action identifiers which Hydrogen is able to interpret.
Definition MidiAction.h:157
bool mute_toggle(std::shared_ptr< Action >, H2Core::Hydrogen *)
bool nextPatternSelection(int nPatternNumber)
bool master_volume_relative(std::shared_ptr< Action >, H2Core::Hydrogen *)
int getParameterNumber(const QString &sActionType) const
bool select_next_pattern_cc_absolute(std::shared_ptr< Action >, H2Core::Hydrogen *)
bool(MidiActionManager::* action_f)(std::shared_ptr< Action >, H2Core::Hydrogen *)
Definition MidiAction.h:159
std::map< QString, std::pair< action_f, int > > m_actionMap
Holds all Action identifiers which Hydrogen is able to interpret.
Definition MidiAction.h:168
bool bpm_increase(std::shared_ptr< Action >, H2Core::Hydrogen *)
bool strip_mute_toggle(std::shared_ptr< Action >, H2Core::Hydrogen *)
bool effect_level_relative(std::shared_ptr< Action >, H2Core::Hydrogen *)
bool gain_level_absolute(std::shared_ptr< Action >, H2Core::Hydrogen *)