hydrogen 1.2.6
MidiMap.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 MIDIMAP_H
23#define MIDIMAP_H
24
25#include <memory>
26#include <vector>
27#include <map>
28#include <cassert>
29#include <core/Object.h>
30#include <core/IO/MidiCommon.h>
31
32#include <QtCore/QMutex>
33
34class Action;
35
37class MidiMap : public H2Core::Object<MidiMap>
38{
40public:
47 ~MidiMap();
48
55 static void create_instance();
60 static void reset_instance();
65 static MidiMap* get_instance() { assert(__instance); return __instance; }
66
67 void reset();
68
70 void registerMMCEvent( QString, std::shared_ptr<Action> );
72 void registerNoteEvent( int , std::shared_ptr<Action> );
74 void registerCCEvent( int , std::shared_ptr<Action> );
76 void registerPCEvent( std::shared_ptr<Action> );
77
78 std::multimap<QString, std::shared_ptr<Action>> getMMCActionMap() const;
79 std::multimap<int, std::shared_ptr<Action>> getNoteActionMap() const;
80 std::multimap<int, std::shared_ptr<Action>> getCCActionMap() const;
81
83 std::vector<std::shared_ptr<Action>> getMMCActions( QString sEventString );
85 std::vector<std::shared_ptr<Action>> getNoteActions( int nNote );
87 std::vector<std::shared_ptr<Action>> getCCActions( int nParameter );
89 std::vector<std::shared_ptr<Action>> getPCActions() const;
90
91 std::vector<int> findCCValuesByActionParam1( QString sActionType, QString sParam1 );
92 std::vector<int> findCCValuesByActionType( QString sActionType );
93
99 std::vector<std::pair<H2Core::MidiMessage::Event,int>> getRegisteredMidiEvents( std::shared_ptr<Action> pAction ) const;
100
109 QString toQString( const QString& sPrefix = "", bool bShort = true ) const override;
110private:
111 MidiMap();
112
113 std::multimap<int, std::shared_ptr<Action>> m_noteActionMap;
114 std::multimap<int, std::shared_ptr<Action>> m_ccActionMap;
115 std::multimap<QString, std::shared_ptr<Action>> m_mmcActionMap;
116 std::vector<std::shared_ptr<Action>> m_pcActionVector;
117
118
119 QMutex __mutex;
120};
121
122inline std::multimap<QString, std::shared_ptr<Action>> MidiMap::getMMCActionMap() const {
123 return m_mmcActionMap;
124}
125inline std::multimap<int, std::shared_ptr<Action>> MidiMap::getNoteActionMap() const {
126 return m_noteActionMap;
127}
128inline std::multimap<int, std::shared_ptr<Action>> MidiMap::getCCActionMap() const {
129 return m_ccActionMap;
130}
131inline std::vector<std::shared_ptr<Action>> MidiMap::getPCActions() const {
132 return m_pcActionVector;
133}
134
135#endif
#define H2_OBJECT(name)
Definition Object.h:227
void registerMMCEvent(QString, std::shared_ptr< Action >)
Sets up the relation between a mmc event and an action.
Definition MidiMap.cpp:96
std::vector< std::shared_ptr< Action > > getCCActions(int nParameter)
Returns the cc action which was linked to the given event.
Definition MidiMap.cpp:246
std::multimap< int, std::shared_ptr< Action > > m_noteActionMap
Definition MidiMap.h:113
static MidiMap * __instance
Object holding the current MidiMap singleton.
Definition MidiMap.h:46
void registerNoteEvent(int, std::shared_ptr< Action >)
Sets up the relation between a note event and an action.
Definition MidiMap.cpp:130
std::multimap< int, std::shared_ptr< Action > > getCCActionMap() const
Definition MidiMap.h:128
void registerPCEvent(std::shared_ptr< Action >)
Sets up the relation between a program change and an action.
Definition MidiMap.cpp:190
std::vector< std::shared_ptr< Action > > getPCActions() const
Returns the pc action which was linked to the given event.
Definition MidiMap.h:131
std::multimap< QString, std::shared_ptr< Action > > getMMCActionMap() const
Definition MidiMap.h:122
static void create_instance()
If __instance equals 0, a new MidiMap singleton will be created and stored in it.
Definition MidiMap.cpp:64
std::vector< int > findCCValuesByActionParam1(QString sActionType, QString sParam1)
Definition MidiMap.cpp:262
QMutex __mutex
Definition MidiMap.h:119
std::multimap< int, std::shared_ptr< Action > > getNoteActionMap() const
Definition MidiMap.h:125
static MidiMap * get_instance()
Returns a pointer to the current MidiMap singleton stored in __instance.
Definition MidiMap.h:65
std::vector< std::pair< H2Core::MidiMessage::Event, int > > getRegisteredMidiEvents(std::shared_ptr< Action > pAction) const
Definition MidiMap.cpp:289
std::vector< std::shared_ptr< Action > > getNoteActions(int nNote)
Returns all note actions which are linked to the given event.
Definition MidiMap.cpp:229
std::vector< std::shared_ptr< Action > > getMMCActions(QString sEventString)
Returns all MMC actions which are linked to the given event.
Definition MidiMap.cpp:212
std::vector< std::shared_ptr< Action > > m_pcActionVector
Definition MidiMap.h:116
MidiMap()
Definition MidiMap.cpp:46
std::vector< int > findCCValuesByActionType(QString sActionType)
Definition MidiMap.cpp:276
QString toQString(const QString &sPrefix="", bool bShort=true) const override
Formatted string version for debugging purposes.
Definition MidiMap.cpp:334
std::multimap< QString, std::shared_ptr< Action > > m_mmcActionMap
Definition MidiMap.h:115
std::multimap< int, std::shared_ptr< Action > > m_ccActionMap
Definition MidiMap.h:114
~MidiMap()
Definition MidiMap.cpp:57
void reset()
Reinitializes the object.
Definition MidiMap.cpp:82
static void reset_instance()
Convenience function calling reset() on the current MidiMap __instance.
Definition MidiMap.cpp:71
void registerCCEvent(int, std::shared_ptr< Action >)
Sets up the relation between a cc event and an action.
Definition MidiMap.cpp:161