NiCMidi 1.1.0
A MIDI library derived from J.D.Koftinoff jdksmidi
notifier.h
Go to the documentation of this file.
1/*
2 * NiCMidi - A C++ Class Library for MIDI
3 *
4 * Copyright (C) 2004 J.D. Koftinoff Software, Ltd.
5 * www.jdkoftinoff.com jeffk@jdkoftinoff.com
6 * Copyright (C) 2021, 2022 Nicola Cassetta
7 * https://github.com/ncassetta/NiCMidi
8 *
9 * This file is part of NiCMidi.
10 *
11 * NiCMidi is free software: you can redistribute it and/or modify
12 * it under the terms of the GNU Lesser General Public License as
13 * published by the Free Software Foundation, either version 3 of
14 * the License, or (at your option) any later version.
15 *
16 * NiCMidi is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU Lesser General Public License for more details.
20 *
21 * You should have received a copy of the GNU Lesser General Public
22 * License along with NiCMidi. If not, see <http://www.gnu.org/licenses/>.
23 */
24
28
29
30#ifndef _NICMIDI_NOTIFIER_H
31#define _NICMIDI_NOTIFIER_H
32
33
34#include <iostream>
35#include "processor.h"
36
37
38
39class MIDISequencer;
40
41
54 public:
56 MIDISequencerGUIEvent() : bits(0) {}
58 MIDISequencerGUIEvent(unsigned long bits_) : bits(bits_) {}
60 MIDISequencerGUIEvent(int group, int subgroup, int item) {
61 bits = ((group&0xff)<<24) | ((subgroup&0xfff)<<12) | (item&0xfff); }
62 // leave unchanged! overloading trouble, too many ctors
63 // copy constructor and operator= provided by the compiler
64
66 operator unsigned long () const { return bits; }
68 int GetGroup() const { return (int)((bits>>24)&0xff); }
71 int GetSubGroup() const { return (int)((bits>>12)&0xfff); }
73 int GetItem() const { return (int)((bits>>0)&0xfff); }
75 void SetEvent( int group, int subgroup = 0, int item = 0 ) {
76 bits = ((group&0xff)<<24) | ((subgroup&0xfff)<<12) | (item&0xfff); }
77
79 enum {
86 };
87
89 enum {
95 };
96
98 enum {
105 }; // TODO: add a GROUP_TRANSPORT_ENDOFSONG for midi type 3 files?
106
108 enum {
117 };
118
120 enum {
125 };
126
128 enum {
129 GROUP_USER_USER = 0
130 };
131
133 static const char group_names[][10];
135 static const char conductor_items_names[][10];
137 static const char transport_items_names[][10];
139 static const char track_items_names[][10];
141 static const char recording_items_names[][10];
143 static const char user_items_names[][10];
144
145 protected:
147 unsigned long bits; // Storage for group, subgroup and item
149};
150
151
163 public:
167 sequencer(seq), en(true) {}
168 // destructor needed for virtual methods
169 virtual ~MIDISequencerGUINotifier() {}
173 virtual void SetSequencer(const MIDISequencer* seq) { sequencer = seq; }
175 virtual void Notify(const MIDISequencerGUIEvent &ev) = 0;
177 virtual bool GetEnable() const { return en;};
179 virtual void SetEnable(bool f) { en = f; }
180 protected:
182 const MIDISequencer* sequencer;
183 bool en;
185};
186
187
192 public:
196 MIDISequencerGUINotifierText(const MIDISequencer* seq = 0, std::ostream& os = std::cout) :
197 MIDISequencerGUINotifier(seq), start_from(0), ost(os) {}
198
201 unsigned char GetStartFrom() const { return start_from; }
205 bool SetStartFrom(unsigned char c);
206
208 virtual void Notify(const MIDISequencerGUIEvent &ev);
209
210 protected:
212 unsigned char start_from;
213 std::ostream& ost;
215};
216
217
218#ifdef _WIN32
219#include "windows.h"
220#include "mmsystem.h"
221
222
227 public:
232 MIDISequencerGUINotifierWin32 (HWND w, DWORD msg, WPARAM param_value = 0);
233
239
241 DWORD GetMsgId() const { return window_msg; }
242
244 virtual void Notify (const MIDISequencerGUIEvent &ev);
245
246 protected:
248 // Returns a safe Windows message id, so we can create the notifier without worrying about this
249 static UINT GetSafeSystemMsgId() { static UINT base = WM_APP; return base++; }
250
251 HWND dest_window;
252 DWORD window_msg;
253 WPARAM wparam_value;
255};
256
257#endif // _WIN32
258
259#endif // _JDKMIDI_NOTIFIER_H
Holds data for a message that the sequencer can send to the GUI to warn it when something happens.
Definition: notifier.h:53
@ GROUP_TRACK_VOLUME
Volume change.
Definition: notifier.h:112
@ GROUP_TRACK_NAME
Track got its name.
Definition: notifier.h:109
@ GROUP_TRACK_CHR
Chorus change.
Definition: notifier.h:114
@ GROUP_TRACK_USER
User defined item.
Definition: notifier.h:116
@ GROUP_TRACK_PAN
Pan change.
Definition: notifier.h:113
@ GROUP_TRACK_REV
Reverb change.
Definition: notifier.h:115
@ GROUP_TRACK_NOTE
Note.
Definition: notifier.h:111
@ GROUP_TRACK_PROGRAM
Program change.
Definition: notifier.h:110
MIDISequencerGUIEvent()
Default constructor: creates a generic event with all attributes set to 0.
Definition: notifier.h:56
int GetGroup() const
Returns the event group.
Definition: notifier.h:68
int GetItem() const
Returns the event item (i.e. the kind of the event).
Definition: notifier.h:73
@ GROUP_TRANSPORT_START
Sequencer start.
Definition: notifier.h:99
@ GROUP_TRANSPORT_STOP
Sequencer stop.
Definition: notifier.h:100
@ GROUP_TRANSPORT_MEASURE
Start of a measure.
Definition: notifier.h:101
@ GROUP_TRANSPORT_COUNTIN
Countin start.
Definition: notifier.h:103
@ GROUP_TRANSPORT_BEAT
Beat marker.
Definition: notifier.h:102
@ GROUP_TRANSPORT_USER
User defined item.
Definition: notifier.h:104
static const char transport_items_names[][10]
An array of strings with readable transport group items names.
Definition: notifier.h:137
@ GROUP_RECORDER_USER
User defined item.
Definition: notifier.h:124
@ GROUP_RECORDER_START
Recording start.
Definition: notifier.h:122
@ GROUP_RECORDER_RESET
Recorder reset.
Definition: notifier.h:121
@ GROUP_RECORDER_STOP
Recording stop.
Definition: notifier.h:123
int GetSubGroup() const
Returns the event subgroup (only effective for GROUP_TRACK events, where it is the track of the event...
Definition: notifier.h:71
@ GROUP_CONDUCTOR_TEMPO
Tempo change.
Definition: notifier.h:90
@ GROUP_CONDUCTOR_KEYSIG
Keysig change.
Definition: notifier.h:92
@ GROUP_CONDUCTOR_TIMESIG
Timesig change.
Definition: notifier.h:91
@ GROUP_CONDUCTOR_USER
User defined item.
Definition: notifier.h:94
@ GROUP_CONDUCTOR_MARKER
Marker.
Definition: notifier.h:93
static const char group_names[][10]
An array of strings with readable group names.
Definition: notifier.h:133
void SetEvent(int group, int subgroup=0, int item=0)
Sets the event group, subgroup and item.
Definition: notifier.h:75
MIDISequencerGUIEvent(int group, int subgroup, int item)
This constructor creates the object starting from its group, subgroup, item.
Definition: notifier.h:60
@ GROUP_RECORDER
Recorder events.
Definition: notifier.h:84
@ GROUP_USER
User defined group.
Definition: notifier.h:85
@ GROUP_TRANSPORT
Transport events (start, stop, etc)
Definition: notifier.h:82
@ GROUP_ALL
Generic group: used by the MIDISequencer to request a full GUI reset.
Definition: notifier.h:80
@ GROUP_TRACK
Track events (the subgroup is the track of the event)
Definition: notifier.h:83
@ GROUP_CONDUCTOR
Conductor events (time, tempo, etc)
Definition: notifier.h:81
static const char user_items_names[][10]
An array of strings with readable user group item names.
Definition: notifier.h:143
@ GROUP_USER_USER
User defined item.
Definition: notifier.h:129
MIDISequencerGUIEvent(unsigned long bits_)
This constructor creates the object directly from its parameters, packed into an unsigned long.
Definition: notifier.h:58
static const char conductor_items_names[][10]
An array of strings with readable conductor group items names.
Definition: notifier.h:135
static const char recording_items_names[][10]
An array of strings with readable recording group items names.
Definition: notifier.h:141
static const char track_items_names[][10]
An array of strings with readable track group items names.
Definition: notifier.h:139
A pure virtual class implementing a device that can send MIDISequencerGUIEvent messages to a GUI.
Definition: notifier.h:162
virtual void SetEnable(bool f)
Sets message sending on/off.
Definition: notifier.h:179
virtual void Notify(const MIDISequencerGUIEvent &ev)=0
Notifies the MIDISequencerGUIEvent ev.
MIDISequencerGUINotifier(const MIDISequencer *seq=0)
The constructor.
Definition: notifier.h:166
virtual void SetSequencer(const MIDISequencer *seq)
This sets the sequencer which generates messages sent to the GUI.
Definition: notifier.h:173
virtual bool GetEnable() const
Returns the enable/disable status.
Definition: notifier.h:177
A MIDISequencerGUINotifier which sends text messages to a std::ostream (std::cout as default).
Definition: notifier.h:191
virtual void Notify(const MIDISequencerGUIEvent &ev)
Notifies the event ev, printing to it a readable event description.
bool SetStartFrom(unsigned char c)
Sets the numbering of measures and beats (starting from 0 or from 1)
MIDISequencerGUINotifierText(const MIDISequencer *seq=0, std::ostream &os=std::cout)
The constructor.
Definition: notifier.h:196
unsigned char GetStartFrom() const
Gets the numbering of measures and beats.
Definition: notifier.h:201
A MIDISequencerGUINotifier which sends messages to a Win32 window using the Windows PostMessage() fun...
Definition: notifier.h:226
virtual ~MIDISequencerGUINotifierWin32()
The destructor.
Definition: notifier.h:238
DWORD GetMsgId() const
Returns the Window message id.
Definition: notifier.h:241
MIDISequencerGUINotifierWin32(HWND w, DWORD msg, WPARAM param_value=0)
In this form of the constructor you must give the Windows parameters to the notifier.
MIDISequencerGUINotifierWin32(HWND w)
This form auto sets the Windows message id and wparam_value, so you don't have to worry about them.
virtual void Notify(const MIDISequencerGUIEvent &ev)
Sends the MIDISequencerGUIEvent ev to the window.
A MIDITickComponent which implements a basic sequencer, able to play the MIDI events contained in a M...
Definition: sequencer.h:193
Contains the definition of the pure virtual MIDIProcessor class and its specializations MIDIMultiProc...