hydrogen 1.2.6
MidiSenseWidget.cpp
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
23#include "core/MidiMap.h"
24#include "MidiSenseWidget.h"
25#include "../HydrogenApp.h"
26#include "../CommonStrings.h"
27
28#include <core/Hydrogen.h>
29#include <core/EventQueue.h>
30
31MidiSenseWidget::MidiSenseWidget(QWidget* pParent, bool bDirectWrite, std::shared_ptr<Action> pAction)
32 : QDialog( pParent )
33 , m_lastMidiEvent( H2Core::MidiMessage::Event::Null )
35{
36 auto pCommonStrings = HydrogenApp::get_instance()->getCommonStrings();
37 m_bDirectWrite = bDirectWrite;
38 m_pAction = pAction;
39
40 setWindowTitle( pCommonStrings->getMidiSenseWindowTitle() );
41 setFixedSize( 280, 100 );
42
43 bool midiOperable = false;
44
45 m_pURLLabel = new QLabel( this );
46 m_pURLLabel->setAlignment( Qt::AlignCenter );
47
48 if(m_pAction != nullptr){
49 m_pURLLabel->setText( pCommonStrings->getMidiSenseInput() );
50 midiOperable = true;
51 } else {
52
53 /*
54 * Check if this widget got called from the midiTable in the preferences
55 * window(directWrite=false) or by clicking on a midiLearn-capable gui item(directWrite=true)
56 */
57
59 m_pURLLabel->setText( pCommonStrings->getMidiSenseUnavailable() );
60 midiOperable = false;
61 } else {
62 m_pURLLabel->setText( pCommonStrings->getMidiSenseInput() );
63 midiOperable = true;
64 }
65 }
66
67 QVBoxLayout* pVBox = new QVBoxLayout( this );
68 pVBox->addWidget( m_pURLLabel );
69 setLayout( pVBox );
70
73 pHydrogen->setLastMidiEventParameter( 0 );
74
75 m_pUpdateTimer = new QTimer( this );
76
77 if(midiOperable)
78 {
79 /*
80 * If the widget is not midi operable, we can omit
81 * starting the timer which listens to midi input..
82 */
83
84 connect( m_pUpdateTimer, SIGNAL( timeout() ), this, SLOT( updateMidi() ) );
85 m_pUpdateTimer->start( 100 );
86 }
87};
88
92
96
97 m_lastMidiEvent = pHydrogen->getLastMidiEvent();
99
100 if ( m_bDirectWrite ) {
101 // write the action / parameter combination to the midiMap
102 MidiMap *pMidiMap = MidiMap::get_instance();
103
104 assert(m_pAction);
105
106 std::shared_ptr<Action> pAction = std::make_shared<Action>( m_pAction );
107 pAction->setValue( "0" );
108
109 switch( m_lastMidiEvent ) {
111 pMidiMap->registerCCEvent( m_nLastMidiEventParameter, pAction );
112 break;
113
115 pMidiMap->registerNoteEvent( m_nLastMidiEventParameter, pAction );
116 break;
117
119 pMidiMap->registerPCEvent( pAction );
120 break;
121
123 return;
124
125 default:
126 // MMC event
127 pMidiMap->registerMMCEvent(
129 pAction );
130 }
131
133 }
134
135 close();
136 }
137}
138
static EventQueue * get_instance()
Returns a pointer to the current EventQueue singleton stored in __instance.
Definition EventQueue.h:224
void push_event(const EventType type, const int nValue)
Queues the next event into the EventQueue.
Hydrogen Audio Engine.
Definition Hydrogen.h:54
void setLastMidiEventParameter(int nParam)
Definition Hydrogen.h:704
static Hydrogen * get_instance()
Returns the current Hydrogen instance __instance.
Definition Hydrogen.h:84
void setLastMidiEvent(MidiMessage::Event event)
Definition Hydrogen.h:698
int getLastMidiEventParameter() const
Definition Hydrogen.h:701
MidiMessage::Event getLastMidiEvent() const
Last received midi message.
Definition Hydrogen.h:695
static QString EventToQString(Event event)
static HydrogenApp * get_instance()
Returns the instance of HydrogenApp class.
std::shared_ptr< CommonStrings > getCommonStrings()
The MidiMap maps MidiActions to MidiEvents.
Definition MidiMap.h:38
void registerMMCEvent(QString, std::shared_ptr< Action >)
Sets up the relation between a mmc event and an action.
Definition MidiMap.cpp:96
void registerNoteEvent(int, std::shared_ptr< Action >)
Sets up the relation between a note event and an action.
Definition MidiMap.cpp:130
void registerPCEvent(std::shared_ptr< Action >)
Sets up the relation between a program change and an action.
Definition MidiMap.cpp:190
static MidiMap * get_instance()
Returns a pointer to the current MidiMap singleton stored in __instance.
Definition MidiMap.h:65
void registerCCEvent(int, std::shared_ptr< Action >)
Sets up the relation between a cc event and an action.
Definition MidiMap.cpp:161
MidiSenseWidget(QWidget *, bool bDirectWrite=false, std::shared_ptr< Action > pAction=nullptr)
QTimer * m_pUpdateTimer
std::shared_ptr< Action > m_pAction
H2Core::MidiMessage::Event m_lastMidiEvent
@ EVENT_MIDI_MAP_CHANGED
Definition EventQueue.h:178