NiCMidi 1.1.0
A MIDI library derived from J.D.Koftinoff jdksmidi
processor.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
30
31
32#ifndef _NICMIDI_PROCESSOR_H
33#define _NICMIDI_PROCESSOR_H
34
35#include "msg.h"
36
37#include <iostream>
38#include <vector>
39
40
48 public:
52 virtual ~MIDIProcessor() {}
55 virtual void Reset() = 0;
59 virtual bool Process(MIDITimedMessage *msg) = 0;
60};
61
62
67 public:
68
70 MIDIMultiProcessor() : process_mode(MODE_CONTINUE) {}
72 virtual void Reset();
74 MIDIProcessor* GetProcessor(unsigned int pos) { return processors[pos]; }
76 const MIDIProcessor* GetProcessor(unsigned int pos) const { return processors[pos]; }
78 int GetProcessMode() const { return process_mode; }
84 void SetProcessor(MIDIProcessor* proc, int pos = -1);
87 void RemoveProcessor(unsigned int pos);
90 void RemoveProcessor(const MIDIProcessor* proc);
98 void SetProcessMode(int mode) { process_mode = mode; }
102 virtual bool Process(MIDITimedMessage *msg);
104 enum { MODE_IGNORE, MODE_CONTINUE, MODE_STOP };
105
106 protected:
108 std::vector<MIDIProcessor*> processors; // The array of processor pointers
109 int process_mode; // The process mode parameter
111};
112
113
119 public:
123 virtual void Reset();
126 int GetChannelTranspose (int chan) const { return trans_amount[chan]; }
130 void SetChannelTranspose (int chan, int trans) { trans_amount[chan] = trans; }
132 void SetAllTranspose (int trans);
137 virtual bool Process (MIDITimedMessage *msg);
138
139 protected:
141 int trans_amount[16]; // The transposing amount
143};
144
151 public:
154
156 void Reset();
159 int GetRechanMap (int src_chan) const { return rechan_map[src_chan]; }
162 void SetRechanMap (int src_chan, int dest_chan) { rechan_map[src_chan] = dest_chan; }
164 void SetAllRechan (int dest_chan);
170 virtual bool Process(MIDITimedMessage *msg);
171
172 protected:
174 int rechan_map[16]; // The rechannel map
176};
177
178
185 public:
187 MIDIProcessorPrinter(std::ostream& stream = std::cout, unsigned char from_1 = 0) :
188 print_on(true), chan_from_1(from_1 != 0), ost(stream) {}
190 virtual void Reset() { print_on = true; }
193 int GetChanFrom() const { return chan_from_1; }
195 bool GetPrint() const { return print_on; }
198 void SetChanFrom(unsigned char c) { chan_from_1 = (c != 0); }
200 void SetPrint(bool on_off) { print_on = on_off; }
203 virtual bool Process(MIDITimedMessage *msg);
204
205 protected:
207 bool print_on; // The on/off printing flag
208 unsigned char chan_from_1; // Starting number for MIDI channels (0 or 1)
209 std::ostream& ost; // The out stream
211};
212
213
214#endif
Allows the user to queue many MIDIProcessor objects, passing the result of each one to the next.
Definition: processor.h:66
virtual bool Process(MIDITimedMessage *msg)
The Process method.
void SetProcessMode(int mode)
Determines the behaviour of the MIDIMultiProcessor if any of the processors return false.
Definition: processor.h:98
MIDIProcessor * GetProcessor(unsigned int pos)
Returns a pointer to the MIDIProcessor at the given position.
Definition: processor.h:74
MIDIMultiProcessor()
The constructor creates an object with empty queue.
Definition: processor.h:70
virtual void Reset()
Empties the processors queue, removing all their pointers from it.
const MIDIProcessor * GetProcessor(unsigned int pos) const
Returns a pointer to the MIDIProcessor at the given position.
Definition: processor.h:76
void SetProcessor(MIDIProcessor *proc, int pos=-1)
Inserts a MIDIProcessor object into the queue.
void RemoveProcessor(unsigned int pos)
Removes the MIDIProcessor at the given position.
int GetProcessMode() const
Returns the processing mode (see SetProcessMode()).
Definition: processor.h:78
void RemoveProcessor(const MIDIProcessor *proc)
Searches the given MIDIProcessor in the queue and removes it (it does nothing if the processor is not...
A pure virtual class implementing an object that can manipulate a MIDI message, inspecting or changin...
Definition: processor.h:47
virtual bool Process(MIDITimedMessage *msg)=0
The Process() pure virtual method.
MIDIProcessor()
The constructor.
Definition: processor.h:50
virtual ~MIDIProcessor()
The destructor.
Definition: processor.h:52
virtual void Reset()=0
You should implement this pure virtual method in order to return the MIDIProcessor to its initial sta...
A MIDIProcessor which prints a human-readable description of the processed messages to a std::ostream...
Definition: processor.h:184
virtual void Reset()
Same of SetPrint(true)
Definition: processor.h:190
void SetChanFrom(unsigned char c)
Sets the numbering of MIDI channels in message printing.
Definition: processor.h:198
int GetChanFrom() const
Returns the numbering of the first MIDI channel in message printing (0 or 1).
Definition: processor.h:193
virtual bool Process(MIDITimedMessage *msg)
The Process method.
bool GetPrint() const
Returns the printing status.
Definition: processor.h:195
void SetPrint(bool on_off)
Sets the printing on and off (default is on).
Definition: processor.h:200
MIDIProcessorPrinter(std::ostream &stream=std::cout, unsigned char from_1=0)
The constructor sets the std::ostream that will print the messages (default: std::cout).
Definition: processor.h:187
A MIDIProcessor which changes the channel of all processed MIDI channel messages.
Definition: processor.h:150
virtual bool Process(MIDITimedMessage *msg)
The Process() method.
void SetAllRechan(int dest_chan)
Sends all channel messages to channel dest_chan.
MIDIProcessorRechannelizer()
The constructor.
int GetRechanMap(int src_chan) const
Gets the corresponding channel for the (source) src_chan.
Definition: processor.h:159
void Reset()
Resets the default status (no rechannelizing).
void SetRechanMap(int src_chan, int dest_chan)
Set the correspondence between two channels (will transform src_chan into dest_chan).
Definition: processor.h:162
A MIDIProcessor which shifts the pitch of MIDI note and polyphonic pressure messages by a given amoun...
Definition: processor.h:118
void SetChannelTranspose(int chan, int trans)
Sets the transposing amount.
Definition: processor.h:130
MIDIProcessorTransposer()
The constructor.
virtual void Reset()
Resets to the default status (no transposing on all channels).
int GetChannelTranspose(int chan) const
Gets the transposing amount (in semitones) for the given channel.
Definition: processor.h:126
void SetAllTranspose(int trans)
Sets the same transposing amount (in semitones) for all the channels.
virtual bool Process(MIDITimedMessage *msg)
The process() method.
The MIDITimedMessage class inherits from the MIDIMessage and represents a message associated with a s...
Definition: msg.h:382
Contains the definition of the classes MIDIMessage and MIDITimedMessage.