NiCMidi 1.1.0
A MIDI library derived from J.D.Koftinoff jdksmidi
matrix.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_MATRIX_H
31#define _NICMIDI_MATRIX_H
32
33#include "msg.h"
34#include "processor.h"
35
36
43class MIDIMatrix : public MIDIProcessor {
44 public:
48 virtual ~MIDIMatrix() {}
49
51 virtual void Reset();
54 virtual bool Process(MIDITimedMessage* msg);
56 int GetTotalCount() const { return total_count; }
59 int GetChannelCount(int chan) const { return channel_count[chan]; }
62 int GetNoteCount(int chan, int note) const { return note_on_count[chan * 128 + note]; }
65 bool GetHoldPedal(int chan) const { return hold_pedal[chan]; }
68 int GetMinNoteOn(int chan) const
69 { return channel_count[chan] ? min_note[chan] : -1; }
72 int GetMaxNoteOn(int chan) const
73 { return channel_count[chan] ? max_note[chan] : -1; }
74
75 protected:
76
79 virtual void DecNoteCount(unsigned char chan, unsigned char note);
82 virtual void IncNoteCount (unsigned char chan, unsigned char note);
85 virtual void ClearChannel(unsigned char chan);
88 virtual void OtherMessage(const MIDIMessage* msg) {}
91 void SetNoteCount(unsigned char chan, unsigned char note, unsigned char val)
92 { note_on_count[chan * 128 + note] = val; }
95 void SetChannelCount(unsigned char chan, int val) { channel_count[chan] = val; }
96
97 private:
98 unsigned char note_on_count[2048]; // The note matrix (16 channels x 128 notes)
99 unsigned char min_note[16]; // The minimum sounding note number for every channel
100 unsigned char max_note[16]; // The maximum sounding note number for every channel
101 int16_t channel_count[16]; // The number of notes sounding for every channel
102 bool hold_pedal[16]; // The pedal status for every channel
103 int total_count; // The total number of sounding notes
104};
105
106
107#endif
108
109
This MIDIProcessor subclass implements a matrix which keeps track of notes on and hold pedal for ever...
Definition: matrix.h:43
virtual void DecNoteCount(unsigned char chan, unsigned char note)
Decrements the note count for the given channel and note.
void SetChannelCount(unsigned char chan, int val)
Sets the channel note count.
Definition: matrix.h:95
void SetNoteCount(unsigned char chan, unsigned char note, unsigned char val)
Sets the note count.
Definition: matrix.h:91
virtual bool Process(MIDITimedMessage *msg)
Processes the given MIDI message updating the matrix.
int GetChannelCount(int chan) const
Returns the number of notes on for given channel.
Definition: matrix.h:59
int GetMaxNoteOn(int chan) const
Returns the maximum note on MIDI value sounding for the given channel (-1 if no note on).
Definition: matrix.h:72
bool GetHoldPedal(int chan) const
Returns true if pedal is holding on given channel.
Definition: matrix.h:65
virtual void ClearChannel(unsigned char chan)
Clear the note count and the pedal on the given channel.
MIDIMatrix()
The constructor creates an empty matrix.
virtual void OtherMessage(const MIDIMessage *msg)
Called by Process() for non note and non pedal messages.
Definition: matrix.h:88
int GetMinNoteOn(int chan) const
Returns the minimum note on MIDI value sounding for the given channel (-1 if no note on).
Definition: matrix.h:68
virtual ~MIDIMatrix()
The destructor.
Definition: matrix.h:48
int GetNoteCount(int chan, int note) const
Returns the number of sounding notes given the channel and the note MIDI value.
Definition: matrix.h:62
virtual void IncNoteCount(unsigned char chan, unsigned char note)
Increments the note count for the given channel and note.
int GetTotalCount() const
Returns the total number of notes on.
Definition: matrix.h:56
virtual void Reset()
Resets the matrix (no notes on, no pedal hold)
Stores data representing a MIDI event message.
Definition: msg.h:49
A pure virtual class implementing an object that can manipulate a MIDI message, inspecting or changin...
Definition: processor.h:47
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.
Contains the definition of the pure virtual MIDIProcessor class and its specializations MIDIMultiProc...