NiCMidi 1.1.0
A MIDI library derived from J.D.Koftinoff jdksmidi
manager.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
25
28
29
30#ifndef _NICMIDI_MANAGER_H
31#define _NICMIDI_MANAGER_H
32
33#include "msg.h"
34#include "driver.h"
35#include "notifier.h"
36#include "timer.h"
37#include "tick.h"
38
39
40#include <vector>
41#include <thread>
42#include <mutex>
43
44
57public:
59 MIDIManager() = delete;
60
63 static void Reset();
64
66 static unsigned int GetNumMIDIIns();
68 static const std::string& GetMIDIInName(unsigned int n);
70 static MIDIInDriver* GetInDriver(unsigned int n);
73 static bool IsValidInPortNumber(unsigned int n);
75 static unsigned int GetNumMIDIOuts();
77 static const std::string& GetMIDIOutName(unsigned int n);
79 static MIDIOutDriver* GetOutDriver(unsigned int n);
82 static bool IsValidOutPortNumber(unsigned int n);
86
87/* TODO: are these useful?
91 static bool StartTimer();
94 static void StopTimer();
95*/
98 static void OpenInPorts();
101 static void CloseInPorts();
104 static void OpenOutPorts();
107 static void CloseOutPorts();
109 static void AllNotesOff();
115 static void AddMIDITick(MIDITickComponent *tick);
120
121protected:
122
125 static void TickProc(tMsecs sys_time_, void* p);
126
133 static void Init();
134
136 static void Exit(); // called at exit
137
138 // WARNING! We MUST use pointers to avoid the "static inizialization order fiasco"
139 static std::vector<MIDIOutDriver*>* MIDI_outs; // A vector of MIDIOutDriver objects (one for each
140 // hardware port)
141 static std::vector<std::string>* MIDI_out_names; // The system names of hardware out ports
142 static std::vector<MIDIInDriver*>* MIDI_ins; // A vector of MIDIInDriver objects (one for each
143 // hardware port)
144 static std::vector<std::string>* MIDI_in_names; // The system names of hardware in ports
145
146 static std::vector<MIDITickComponent*>*
147 MIDITicks; // The array of MIDITickCompnent objects, everyone
148 // of them has his StaticTickProc() callback
149
150 static std::mutex* proc_lock; // A mutex for thread safe processing
151 static bool init;
153};
154
155
156
157#endif // _JDKMIDI_MANAGER_H
Receives MIDI messages from an hardware MIDI in port.
Definition: driver.h:224
A static class that manages computer hardware resources (in and out MIDI ports) and timing.
Definition: manager.h:56
static bool IsValidOutPortNumber(unsigned int n)
Returns true if n is a valid MIDI out port number.
static void OpenOutPorts()
Opens all the system MIDI Out ports.
static MIDISequencer * GetSequencer()
Returns the pointer to the (unique) MIDITickComponent in the queue with tPriority PR_SEQ (0 if not fo...
static unsigned int GetNumMIDIOuts()
Returns the number of MIDI out ports in the system.
static bool RemoveMIDITick(MIDITickComponent *tick)
Removes the given MIDITickComponent pointer from the queue.
static void TickProc(tMsecs sys_time_, void *p)
This is the main callback, called at every tick of the MIDITimer.
static MIDIOutDriver * GetOutDriver(unsigned int n)
Returns a pointer to the MIDIOutDriver with given port id.
static void Init()
This is the initialization function, called the first time a class method is accessed.
static void CloseInPorts()
Closes all the system MIDI In ports.
static void AllNotesOff()
Sends a MIDI AllNotesOff message to all open out ports.
MIDIManager()=delete
The constructor is deleted.
static const std::string & GetMIDIInName(unsigned int n)
Returns the system name of the given MIDI in port.
static MIDIInDriver * GetInDriver(unsigned int n)
Returns a pointer to the MIDIInDriver with given port id.
static void OpenInPorts()
Opens all the system MIDI In ports.
static bool IsValidInPortNumber(unsigned int n)
Returns true if n is a valid MIDI in port number.
static void AddMIDITick(MIDITickComponent *tick)
Inserts a MIDITickComponent object into the queue.
static void Reset()
Stops the timer if it is running, resets all the MIDI in and out ports and flushes the MIDITickCompon...
static unsigned int GetNumMIDIIns()
Returns the number of MIDI in ports in the system.
static void CloseOutPorts()
Closes all the system MIDI Out ports.
static const std::string & GetMIDIOutName(unsigned int n)
Returns the system name of the given MIDI out port.
Sends MIDI messages to an hardware MIDI out port.
Definition: driver.h:130
A MIDITickComponent which implements a basic sequencer, able to play the MIDI events contained in a M...
Definition: sequencer.h:193
A pure virtual class implementing an object which has a callback procedure to be called at every tick...
Definition: tick.h:65
Contains the definition of the classes MIDIOutDriver and MIDIInDriver, used by the library to communi...
unsigned long long tMsecs
The type of a variable which can hold the elapsed time in milliseconds.
Definition: timer.h:44
Contains the definition of the classes MIDIMessage and MIDITimedMessage.
Contains the definition of the classes MIDISequencerGUIEvent, MIDISequencerGUINotifier (abstract),...
Contains the definition of the pure virtual class MIDITickComponent.
Contains the definition of the MIDITimer class and some other typedef related to MIDI timing.