NiCMidi 1.1.0
A MIDI library derived from J.D.Koftinoff jdksmidi
advancedsequencer.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_ADVANCEDSEQUENCER_H
31#define _NICMIDI_ADVANCEDSEQUENCER_H
32
33#include <vector>
34#include <string>
35
36#include "thru.h"
37#include "multitrack.h"
38#include "filereadmultitrack.h"
39#include "sequencer.h"
40#include "smpte.h"
41
42
52 public:
57
58 // Copy constructor and assignment operator generated by the compiler
59
61 virtual void Reset();
66 { extra_proc = proc; }
68 virtual bool Process ( MIDITimedMessage *msg );
69
70 bool mute;
71 int solo;
72 unsigned int velocity_scale;
76
77 enum { NO_SOLO, SOLOED, NOT_SOLOED };
78};
79
80
94 public:
119
123 virtual void Reset();
129 virtual bool Load(const char *fname);
135 virtual bool Load(const MIDIMultiTrack* tracks);
138 virtual void UnLoad();
139
141 bool IsLoaded() const { return file_loaded; }
143 std::string GetFileName() { return header.filename; }
145 const MIDIFileHeader& GetFileHeader() { return header; }
148 MIDIThru* GetMIDIThru() { return thru; }
151 const MIDIThru* GetMIDIThru() const { return thru; }
153 bool GetMIDIThruEnable() const { return thru ? thru->IsPlaying() : false; }
156 int GetMIDIThruChannel() const { return thru ? thru->GetOutChannel() : -1; }
158 int GetMIDIThruTranspose() const { return thru ? thru_transposer->GetChannelTranspose(0) : 0; }
160 bool GetSoloMode() const;
163 bool GetTrackSolo(unsigned int trk_num) const
164 { return (((MIDISequencerTrackProcessor *)track_processors[trk_num])->solo ==
165 MIDISequencerTrackProcessor::SOLOED); }
168 bool GetTrackMute (unsigned int trk_num) const
169 { return ((MIDISequencerTrackProcessor *)track_processors[trk_num])->mute; }
171 int GetNumMeasures() const { return num_measures; }
173 unsigned int GetCurrentMeasure() const;
175 unsigned int GetCurrentBeat() const;
187 int GetKeySigMode() const;
189 std::string GetCurrentMarker() const;
191 std::string GetTrackName(unsigned int trk_num) const;
193 int GetTrackVolume(unsigned int trk_num) const; // MIDI value or -1
195 int GetTrackProgram (unsigned int trk_num) const; // MIDI value or -1
197 int GetTrackNoteCount(unsigned int trk_num) const;
199 unsigned int GetTrackVelocityScale(unsigned int trk_num) const;
202 int GetTrackRechannelize(unsigned int trk_num) const;
206 int GetTrackChannel(unsigned int trk_num); // NOT const!!!
208 int GetTrackTranspose(unsigned int trk_num) const;
210 int GetTrackTimeShift(unsigned int trk_num) const;
213 { return (MIDISequencerTrackProcessor *)track_processors[trk_num]; }
215 const MIDISequencerTrackProcessor* GetTrackProcessor(unsigned int trk_num) const
216 { return (const MIDISequencerTrackProcessor *)track_processors[trk_num]; }
218 void SetFileName(std::string& fname) { header.filename = fname; }
221 bool SetMIDIThruEnable(bool on_off);
226 bool SetMIDIThruChannel(int chan);
230 bool SetMIDIThruTranspose (int amt);
233 bool SetTrackSolo(unsigned int trk_num);
238 bool SetTrackMute(unsigned int trk_num, bool f);
243 bool SetTrackVelocityScale(unsigned int trk_num, unsigned int scale);
248 bool SetTrackRechannelize(unsigned int trk_num, int chan);
252 bool SetTrackTranspose(unsigned int trk_num, int amt);
255 virtual void GoToZero() { GoToTime(0); }
259 virtual bool GoToTime(MIDIClockTime time_clk);
261 virtual bool GoToTimeMs(float time_ms);
266 virtual bool GoToMeasure(int measure, int beat = 0);
267
268
270 virtual void Start();
272 virtual void Stop();
276 void OutputMessage(MIDITimedMessage& msg, unsigned int port);
282 bool SetSMPTE(SMPTE* s);
286 virtual void UpdateStatus();
287
288 protected:
289
300 void CatchEventsBefore(int trk_num);
301
303 // The interval between measures in ExtractWarpPositions()
304 static const int MEASURES_PER_WARP = 4;
305 MIDIThru* thru; // The embedded MIDI thru
306 MIDIProcessorTransposer* thru_transposer; // Transposes thru note messages while playing
307 int num_measures; // Number of measures
308 MIDIFileHeader header; // Stores the loaded file parameters
309 int file_loaded; // True if the multitrack is not empty
310
311 std::vector<MIDISequencerState> warp_positions; // Vector of MIDISequencerState objects for fast time moving
313
314 private:
315 bool owns_tracks; // true if the multitrack is owned by the AdvancedSequencer
316};
317
318
319#endif // JDKSMIDI_ADVANCEDSEQUENCER_H
320
An enhanced MIDISequencer, able to directly load and play MIDI files and many more.
Definition: advancedsequencer.h:93
AdvancedSequencer(MIDISequencerGUINotifier *n=0)
Creates an AdvancedSequencer with 17 tracks (one for each channel plus the master track).
virtual bool GoToTimeMs(float time_ms)
Same as GoToTime(), but the time is given in milliseconds.
bool SetTrackMute(unsigned int trk_num, bool f)
Mutes/unmutes the given track (it has no effect on others).
std::string GetTrackName(unsigned int trk_num) const
Returns the name of the given track.
virtual void Stop()
Stops the sequencer playing.
virtual void GoToZero()
Sets the current time to the beginning of the song.
Definition: advancedsequencer.h:255
bool SetTrackSolo(unsigned int trk_num)
Soloes the given track muting all others.
void CatchEventsBefore(int trk_num)
Internal use.
MIDISequencerTrackProcessor * GetTrackProcessor(unsigned int trk_num)
Returns a pointer to the MIDISequencerTrackProcessor for the given track.
Definition: advancedsequencer.h:212
MIDIClockTime GetCurrentBeatOffset() const
Returns the current MIDI time offset respect current beat.
const MIDIFileHeader & GetFileHeader()
Returns the header of the loaded file.
Definition: advancedsequencer.h:145
virtual void Reset()
Resets the status of the sequencer (does not empty the MIDIMultiTrack).
int GetKeySigSharpsFlats() const
Return the number of sharps or flats of the current key signature.
void CatchEventsBefore()
Internal use.
int GetTrackTranspose(unsigned int trk_num) const
Returns the transposing amount in semitones for the given track.
unsigned int GetTrackVelocityScale(unsigned int trk_num) const
Returns the velocity scale percentage for the given track.
void ExtractWarpPositions()
Internal use.
virtual bool Load(const char *fname)
Loads a MIDIFile into the internal MIDIMultiTrack.
bool SetTrackVelocityScale(unsigned int trk_num, unsigned int scale)
Sets a track velocity scale in percentage for the given track.
unsigned int GetCurrentBeat() const
Returns the number of current beat (first is 0). See Numbering conventions.
bool SetMIDIThruEnable(bool on_off)
Enables or disables the embedded MIDIthru.
virtual bool Load(const MIDIMultiTrack *tracks)
Copies the content of an external MIDIMultiTrack into the sequencer.
virtual void Start()
Starts the sequencer playing from the current time.
int GetTrackProgram(unsigned int trk_num) const
Returns the current MIDI program (patch) for the given track (-1 if the program wasn't set at time 0)...
bool IsLoaded() const
Returns true if the internal MIDIMultiTrack is not empty.
Definition: advancedsequencer.h:141
bool SetMIDIThruChannel(int chan)
Sets the out channel for MIDIthru.
int GetTrackRechannelize(unsigned int trk_num) const
Returns the rechannelized channel for the given track (-1 if the track is not rechannelized).
bool GetTrackMute(unsigned int trk_num) const
Returns true if a specific track is muted.
Definition: advancedsequencer.h:168
int GetNumMeasures() const
Returns the number of measures of the loaded song.
Definition: advancedsequencer.h:171
virtual bool GoToMeasure(int measure, int beat=0)
Sets the current time to the given measure and beat.
std::string GetCurrentMarker() const
Returns the current marker text.
int GetTimeSigDenominator() const
Returns the denominator of current time signature.
int GetMIDIThruTranspose() const
Returns the transpose amount of the MIDIThru, 0 if the thru is not present.
Definition: advancedsequencer.h:158
virtual void UnLoad()
Clears the contents of the internal MIDIMultiTrack.
bool SetTrackTranspose(unsigned int trk_num, int amt)
Sets a transpose amount in semitones for the given track.
void OutputMessage(MIDITimedMessage &msg, unsigned int port)
Sends a given MIDI message to an hardware port.
int GetTrackTimeShift(unsigned int trk_num) const
Returns the time offset (in MIDI ticks) assigned to the given track.
int GetTimeSigNumerator() const
Returns the numerator of current time signature.
unsigned int GetCurrentMeasure() const
Returns the current measure number (first is 0). See Numbering conventions.
void SetFileName(std::string &fname)
Sets a name for the content of sequencer.
Definition: advancedsequencer.h:218
int GetKeySigMode() const
Returns the mode (major/minor) of the he current key signature.
virtual void UpdateStatus()
This should be used to update the sequencer internal parameters after editing the multitrack.
virtual bool GoToTime(MIDIClockTime time_clk)
Sets the current time to the given MIDI time.
AdvancedSequencer(MIDIMultiTrack *mlt, MIDISequencerGUINotifier *n=0)
Creates an AdvancedSequencer from a given MIDIMultiTrack.
int GetTrackVolume(unsigned int trk_num) const
Returns the current MIDI volume for the given track (-1 if volume wasn't set at time 0).
int GetTrackNoteCount(unsigned int trk_num) const
Returns the number of notes currently sounding on the given track (0 if the sequencer is not playing)...
bool GetTrackSolo(unsigned int trk_num) const
Returns true if a specific track is soloed.
Definition: advancedsequencer.h:163
bool SetMIDIThruTranspose(int amt)
Sets a transpose amount in semitones for the messages coming from the MIDIThru.
int GetMIDIThruChannel() const
Returns the output channel of the MIDIThru, -1 if the thru is not present.
Definition: advancedsequencer.h:156
bool GetSoloMode() const
Returns true if any track is soloed.
void UnmuteAllTracks()
Unmutes all muted tracks (this has no effect on tracks muted by SoloTrack()).
std::string GetFileName()
Returns the name of the loaded file (or an empty string if it is not yet defined).
Definition: advancedsequencer.h:143
const MIDIThru * GetMIDIThru() const
Returns a pointer to the MIDIThru tick component.
Definition: advancedsequencer.h:151
const MIDISequencerTrackProcessor * GetTrackProcessor(unsigned int trk_num) const
Returns a pointer to the MIDISequencerTrackProcessor for the given track.
Definition: advancedsequencer.h:215
int GetTrackChannel(unsigned int trk_num)
If the track has channel messages all with same channel returns the channel, otherwise -1.
bool SetSMPTE(SMPTE *s)
Sets the parameters of the given SMPTE according to the loaded content.
virtual ~AdvancedSequencer()
The destructor.
void UnSoloTrack()
Unsoloes the soloed track unmuting all others.
bool SetTrackRechannelize(unsigned int trk_num, int chan)
Redirects all channel messages in the track on the given channel.
MIDIThru * GetMIDIThru()
Returns the address of the MIDIThru tick component.
Definition: advancedsequencer.h:148
bool GetMIDIThruEnable() const
Returns true if MIDIThru is enabled (always false if the thru is not present).
Definition: advancedsequencer.h:153
Holds an array of pointers to MIDITrack objects to be played simultaneously.
Definition: multitrack.h:50
A pure virtual class implementing an object that can manipulate a MIDI message, inspecting or changin...
Definition: processor.h:47
A MIDIProcessor which shifts the pitch of MIDI note and polyphonic pressure messages by a given amoun...
Definition: processor.h:118
A pure virtual class implementing a device that can send MIDISequencerGUIEvent messages to a GUI.
Definition: notifier.h:162
A MIDITickComponent which implements a basic sequencer, able to play the MIDI events contained in a M...
Definition: sequencer.h:193
A multipurpose MIDIProcessor implementing muting, soloing, rechannelizing, velocity scaling and trans...
Definition: advancedsequencer.h:51
MIDIProcessor * extra_proc
extra midi processing for this track
Definition: advancedsequencer.h:75
virtual bool Process(MIDITimedMessage *msg)
Processes message msg, changing its parameters according to the state of the processor.
unsigned int velocity_scale
current velocity scale value for note ons, 100=normal
Definition: advancedsequencer.h:72
int transpose
amount to transpose note values
Definition: advancedsequencer.h:74
bool mute
track is muted
Definition: advancedsequencer.h:70
virtual ~MIDISequencerTrackProcessor()
The destructor does nothing.
Definition: advancedsequencer.h:56
void SetExternalProcessor(MIDIProcessor *proc)
Sets the extra processor for the track.
Definition: advancedsequencer.h:65
MIDISequencerTrackProcessor()
The constructor. Default is no processing (MIDI messages leave the processor unchanged).
virtual void Reset()
Resets all values to default state (no processing at all).
int rechannel
rechannelization value, or -1 for none
Definition: advancedsequencer.h:73
int solo
NO_SOLO, SOLOED, NOT_SOLOED.
Definition: advancedsequencer.h:71
A MIDITickComponent which immediately echoes to an out MIDI port all messages incoming from an in MID...
Definition: thru.h:44
The MIDITimedMessage class inherits from the MIDIMessage and represents a message associated with a s...
Definition: msg.h:382
Performs conversions between number of samples, milliseconds and smpte format (hours::minutes::second...
Definition: smpte.h:69
Contains the definition of the class MIDIFileReadMultiTrack, used for loading MIDI files,...
unsigned long MIDIClockTime
The type of a variable which can hold a time in MIDI ticks.
Definition: midi.h:40
Contains the definition of the classes MIDIMultiTrack, MIDIMultiTrackIteratorState,...
Contains the definitions of the classes MIDISequencerTrackState, MIDISequencerState and MIDISequencer...
Contains the definition of the class SMPTE, plus some related enum.
A structure holding data which represent the header of a MIDI file.
Definition: fileread.h:100
Contains the definition of the class MIDIThru.