NiCMidi 1.1.0
A MIDI library derived from J.D.Koftinoff jdksmidi
Globals

Typedef, functions, enums and preprocessor labels globally defined. More...

Macros

#define DRIVER_USES_MIDIMATRIX   0
 This item only affects AllNotesOff() function. More...
 

Typedefs

typedef unsigned long MIDIClockTime
 The type of a variable which can hold a time in MIDI ticks. More...
 
typedef unsigned long long tMsecs
 The type of a variable which can hold the elapsed time in milliseconds. More...
 
typedef void() MIDITick(tMsecs, void *)
 This is the typedef of the callback functions which are called at every timer tick. More...
 

Enumerations

enum  SMPTE_RATE {
  SMPTE_RATE_24 = 0 , SMPTE_RATE_25 , SMPTE_RATE_2997 , SMPTE_RATE_2997DF ,
  SMPTE_RATE_30 , SMPTE_RATE_30DF
}
 The smpte rates (determine the frames/sec rate) More...
 
enum  SAMPLE_RATE {
  SAMPLE_32000 = 0 , SAMPLE_44056 , SAMPLE_44100 , SAMPLE_47952 ,
  SAMPLE_48000 , SAMPLE_48048
}
 The sample rates (determine the sample/sec rate) More...
 
enum  tPriority {
  PR_FIRST , PR_PRE_SEQ , PR_SEQ , PR_POST_SEQ ,
  PR_LAST
}
 
enum  tInsMode {
  INSMODE_DEFAULT , INSMODE_INSERT , INSMODE_REPLACE , INSMODE_INSERT_OR_REPLACE ,
  INSMODE_INSERT_OR_REPLACE_BUT_NOTE
}
 Defines the default behavior of the methods MIDITrack::InsertEvent() and MIDITrack::InsertNote() when inserting events. More...
 
enum  { COMPMODE_EQUAL , COMPMODE_SAMEKIND , COMPMODE_TIME }
 Defines the behaviour of the method MIDITrack::FindEventNumber() when searching events. More...
 

MIDI Clock related constants

const MIDIClockTime TIME_INFINITE = 0xffffffff
 A constant which represents an infinite time. More...
 
const unsigned int DEFAULT_CLKS_PER_BEAT = 120
 The default clocks per beat parameter when initializing a MIDIMultiTrack. More...
 

Default constants when initializing messages and classes

const int MIDI_DEFAULT_TIMESIG_NUMERATOR = 4
 Timesig numerator. More...
 
const int MIDI_DEFAULT_TIMESIG_DENOMINATOR = 4
 Timesig denominator. More...
 
const double MIDI_DEFAULT_TEMPO = 120.0
 Musical tempo. More...
 
const int MIDI_DEFAULT_KEYSIG_KEY = 0
 Keysig key (C) More...
 
const int MIDI_DEFAULT_KEYSIG_MODE = 0
 Keysig mode (major) More...
 

Helper functions for viewing messages content

void SetChanFrom (unsigned char c=0)
 Sets the numbering of MIDI channels when messages are printed. More...
 
void DumpMIDITimedMessage (MIDITimedMessage *const msg, std::ostream &ost=std::cout)
 Prints a readable string describing the contents of the given MIDIMessage (or MIDITimedMessage). More...
 
void DumpMIDITrack (MIDITrack *const trk, std::ostream &ost=std::cout)
 Prints a list of all the MIDI messages in the given MIDItrack. More...
 
int DumpMIDITrackAttr (MIDITrack *const trk, int num, std::ostream &ost=std::cout)
 Prints the main properties of the given MIDItrack. More...
 
int DumpMIDITrackAttrVerbose (MIDITrack *const trk, int num, std::ostream &ost=std::cout)
 Prints all the properties of the given MIDItrack. More...
 
void DumpAllTracks (MIDIMultiTrack *const mlt, std::ostream &ost=std::cout)
 Prints a list of all MIDI messages in the given MIDIMultiTrack, a track at once. More...
 
void DumpMIDIMultiTrack (MIDIMultiTrack *const mlt, std::ostream &ost=std::cout)
 Prints a list of all MIDI messages in the given MIDIMultiTrack in temporal order. More...
 

Other helper functions

void CheckMIDIMatrix (const MIDIMatrix &matrix, std::ostream &ost=std::cout)
 Helper function which shows the contents of a MIDIMatrix. More...
 

Functions for Loading MIDI files

MIDIFileHeaderGetMIDIFileHeader (const char *filename)
 Returns the header of the MIDI file specified by filename. More...
 
MIDIFileHeaderGetMIDIFileHeader (const std::string &filename)
 Returns the header of the MIDI file specified by filename. More...
 
bool LoadMIDIFile (const char *filename, MIDIMultiTrack *tracks, MIDIFileHeader *const head=0)
 Loads a MIDI file into a MIDIMultiTrack object. More...
 
bool LoadMIDIFile (const std::string &filename, MIDIMultiTrack *tracks, MIDIFileHeader *const head=0)
 Loads a MIDI file into a MIDIMultiTrack object. More...
 

Functions for saving MIDI files

bool WriteMIDIFile (const char *filename, int format, const MIDIMultiTrack *tracks, bool strip=false)
 Writes the given MIDIMultiTrack object into a MIDI file. More...
 
bool WriteMIDIFile (const std::string &filename, int format, const MIDIMultiTrack *tracks, bool strip=false)
 Writes the given MIDIMultiTrack object into a MIDI file. More...
 

Helper functions for MIDI and music

const char * GetChanMsgName (unsigned char status)
 Returns a readable name for the given channel message status. More...
 
const char * GetChanModeMsgName (unsigned char number)
 Returns a readable name for the given channel mode (Control change with controller number between 0x78 ... 0x7f). More...
 
const char * GetSysMsgName (unsigned char status)
 Returns a readable name for the given sys message status. More...
 
const char * GetMetaMsgName (unsigned char type)
 Returns a readable name for the given meta message status. More...
 
const char * GetGMProgramName (unsigned char number, int format=0)
 Returns a readable name for a GM program number. More...
 
const char * GetGMDrumkitName (unsigned char number, int format=0)
 Returns a readable name for a GM program number on channel 10 (drumkit). More...
 
bool IsNoteWhite (unsigned char note)
 Returns true if the MIDI number of the note denotes a white key. More...
 
bool IsNoteBlack (unsigned char note)
 Returns true if the MIDI number of the note denotes a black key. More...
 
int GetNoteOctave (unsigned char note)
 MIDI note number to standard octave conversion. More...
 
const char * KeyName (signed char sharp_flats, unsigned char major_minor, bool uppercase=true, bool space=false, bool use_Mm=true)
 Converts a MIDI key signature into a readable form. More...
 

Detailed Description

Typedef, functions, enums and preprocessor labels globally defined.

Macro Definition Documentation

◆ DRIVER_USES_MIDIMATRIX

#define DRIVER_USES_MIDIMATRIX   0

#include <driver.h>

This item only affects AllNotesOff() function.

All modern MIDI devices should respond to all notes off messages so usually there is no need to stop notes sending Note off messages. If you set this to 1 the driver will keep track of all sounding notes and, if the AllNotesOff() method is called, will send a Note Off message for each one, plus a damper off message for every channel. This is quite expensive, so turn this on only if you experience notes sounding when you stop a sequencer.

Typedef Documentation

◆ MIDIClockTime

typedef unsigned long MIDIClockTime

#include <midi.h>

The type of a variable which can hold a time in MIDI ticks.

The MIDI tick is the basis for MIDI clocking: a quarter note is assigned a number of MIDI ticks (see DEFAULT_CLKS_PER_BEAT), and a MIDITimedMessage object has its time measured in MIDI ticks.

◆ tMsecs

typedef unsigned long long tMsecs

#include <timer.h>

The type of a variable which can hold the elapsed time in milliseconds.

◆ MIDITick

typedef void() MIDITick(tMsecs, void *)

#include <timer.h>

This is the typedef of the callback functions which are called at every timer tick.

See the MIDITickComponent class. .

Enumeration Type Documentation

◆ SMPTE_RATE

enum SMPTE_RATE

#include <smpte.h>

The smpte rates (determine the frames/sec rate)

Enumerator
SMPTE_RATE_24 

24 frames/sec

SMPTE_RATE_25 

25 frames/sec

SMPTE_RATE_2997 

29.97 frames/sec

SMPTE_RATE_2997DF 

29.97 frames/sec drop

SMPTE_RATE_30 

30 frames/sec

SMPTE_RATE_30DF 

30 frames/sec drop

◆ SAMPLE_RATE

#include <smpte.h>

The sample rates (determine the sample/sec rate)

Enumerator
SAMPLE_32000 

32000 samples/sec

SAMPLE_44056 

44056 samples/sec

SAMPLE_44100 

44100 samples/sec

SAMPLE_47952 

47952 samples/sec

SAMPLE_48000 

48000 samples/sec

SAMPLE_48048 

48048 samples/sec

◆ tPriority

enum tPriority

#include <tick.h>

These are the available priorities for a MIDITickComponent. When you add a component to the MIDIManager queue with the MIDIManager::SetComponent() method the order in the queue reflects the priority of the components.

See also
MIDIManager::AddComponent().
Enumerator
PR_FIRST 

The component is inserted as first element in the queue.

PR_PRE_SEQ 

The component is inserted before the sequencer.

PR_SEQ 

The component is the sequencer (you can insert only one in the queue)

PR_POST_SEQ 

The component is inserted after the sequencer.

PR_LAST 

The component is inserted as last element in the queue.

◆ tInsMode

enum tInsMode

#include <track.h>

Defines the default behavior of the methods MIDITrack::InsertEvent() and MIDITrack::InsertNote() when inserting events.

If they are trying to insert an event into a track and find an equal or similar event at same MIDI time (see MIDITimedMessage::IsSameKind()) they can replace it with the new event or insert it without deleting the older. This is determined by a static attribute of the class MIDITrack and can be changed by the MIDITrack::SetInsertMode() method (the default is INSMODE_INSERT_OR_REPLACE). When the above methods are called with default argument *_ins_mode* they follow the default behavior, this can be overriden giving them one of the other values as last parameter

Enumerator
INSMODE_DEFAULT 

follow the default behaviour (only used as default argument in methods MIDITrack::InsertEvent() and MIDITrack::InsertNote()

INSMODE_INSERT 

always insert events, if a same kind event was found keep both.

INSMODE_REPLACE 

replace if a same kind event was found, otherwise do nothing.

INSMODE_INSERT_OR_REPLACE 

replace if a same kind event was found, otherwise insert.

INSMODE_INSERT_OR_REPLACE_BUT_NOTE 

as above, but allow two same note events at same time (don't replace, insert a new note).

◆ anonymous enum

anonymous enum

#include <track.h>

Defines the behaviour of the method MIDITrack::FindEventNumber() when searching events.

Enumerator
COMPMODE_EQUAL 

the method searches for an event matching equal operator.

COMPMODE_SAMEKIND 

the method searches for an event matching the MIDITimedMessage::IsSameKind() method.

COMPMODE_TIME 

the method searches for the first event with time equal to the event time.

Function Documentation

◆ SetChanFrom()

void SetChanFrom ( unsigned char  c = 0)

#include <dump_tracks.h>

Sets the numbering of MIDI channels when messages are printed.

If c == 0 channels will be numbered 0 ... 15, else 1 ... 16. This will affect all the functions of this file. See Numbering conventions.

◆ DumpMIDITimedMessage()

void DumpMIDITimedMessage ( MIDITimedMessage *const  msg,
std::ostream &  ost = std::cout 
)

#include <dump_tracks.h>

Prints a readable string describing the contents of the given MIDIMessage (or MIDITimedMessage).

◆ DumpMIDITrack()

void DumpMIDITrack ( MIDITrack *const  trk,
std::ostream &  ost = std::cout 
)

#include <dump_tracks.h>

Prints a list of all the MIDI messages in the given MIDItrack.

◆ DumpMIDITrackAttr()

int DumpMIDITrackAttr ( MIDITrack *const  trk,
int  num,
std::ostream &  ost = std::cout 
)

#include <dump_tracks.h>

Prints the main properties of the given MIDItrack.

It prints the track name, its type (see MIDITrack::GetType()), the number of events and the end time. Use DumpMIDITrack() for printing the track messages.

Parameters
trka pointer to the track
numwill be printed in the first line as track number.
ostthe output stream
Returns
Actually this always returns 3, the number of written text lines

◆ DumpMIDITrackAttrVerbose()

int DumpMIDITrackAttrVerbose ( MIDITrack *const  trk,
int  num,
std::ostream &  ost = std::cout 
)

#include <dump_tracks.h>

Prints all the properties of the given MIDItrack.

It prints the track name, its type (see MIDITrack::GetType()) with a detailed description, the in and out ports, the recording channel, the time shift amount, the number of events and the end time. Use DumpMIDITrack() for printing the track messages.

Parameters
trka pointer to the track
numwill be printed in the first line as track number.
ostthe output stream
Returns
The number of text lines written, which depends from the track attributes.

◆ DumpAllTracks()

void DumpAllTracks ( MIDIMultiTrack *const  mlt,
std::ostream &  ost = std::cout 
)

#include <dump_tracks.h>

Prints a list of all MIDI messages in the given MIDIMultiTrack, a track at once.

◆ DumpMIDIMultiTrack()

void DumpMIDIMultiTrack ( MIDIMultiTrack *const  mlt,
std::ostream &  ost = std::cout 
)

#include <dump_tracks.h>

Prints a list of all MIDI messages in the given MIDIMultiTrack in temporal order.

◆ CheckMIDIMatrix()

void CheckMIDIMatrix ( const MIDIMatrix matrix,
std::ostream &  ost = std::cout 
)

#include <dump_tracks.h>

Helper function which shows the contents of a MIDIMatrix.

◆ GetMIDIFileHeader() [1/2]

MIDIFileHeader & GetMIDIFileHeader ( const char *  filename)

#include <filereadmultitrack.h>

Returns the header of the MIDI file specified by filename.

You can then inspect the format, (0, 1 or 2), the number of tracks and the division (MIDI ticks per quarter note) of the file. If the header cannot be read these are all 0.

◆ GetMIDIFileHeader() [2/2]

MIDIFileHeader & GetMIDIFileHeader ( const std::string &  filename)

#include <filereadmultitrack.h>

Returns the header of the MIDI file specified by filename.

You can then inspect the format, (0, 1 or 2), the number of tracks and the division (MIDI ticks per quarter note) of the file. If the header cannot be read these are all 0.

◆ LoadMIDIFile() [1/2]

bool LoadMIDIFile ( const char *  filename,
MIDIMultiTrack tracks,
MIDIFileHeader *const  head = 0 
)

#include <filereadmultitrack.h>

Loads a MIDI file into a MIDIMultiTrack object.

If the file is in SMF 0 (with only a track) splits it into a master track with only system messages and 16 channel tracks (if you want to remember the original file format you can set the default parameter head). This is the fastest way to put a file into a multitrack, without worrying with intermediate reader objects.

Parameters
[in]filenamethe name of the file
[out]tracksthe MIDIMultiTrack to be loaded
[out]headif you give the address of a MIDIFileHeader object this will be filled with the original file parameters (format, number of tracks, division, name) which you could reuse if you want to save the file.
Returns
true if the loading is successful, otherwise false.
Examples
test_sequencer.cpp.

◆ LoadMIDIFile() [2/2]

bool LoadMIDIFile ( const std::string &  filename,
MIDIMultiTrack tracks,
MIDIFileHeader *const  head = 0 
)

◆ WriteMIDIFile() [1/2]

bool WriteMIDIFile ( const char *  filename,
int  format,
const MIDIMultiTrack tracks,
bool  strip = false 
)

#include <filewritemultitrack.h>

Writes the given MIDIMultiTrack object into a MIDI file.

Parameters
filenamethe file name
formatthe MIDI file format (only 0 and 1 are supported)
tracksthe MIDIMultiTrack to be written
stripif the format is 1 (many tracks) and this is true, empty tracks are skipped
Returns
true if the writing was successful.
Examples
test_recorder.cpp, test_stepsequencer.cpp, and test_writefile.cpp.

◆ WriteMIDIFile() [2/2]

bool WriteMIDIFile ( const std::string &  filename,
int  format,
const MIDIMultiTrack tracks,
bool  strip = false 
)

#include <filewritemultitrack.h>

Writes the given MIDIMultiTrack object into a MIDI file.

See also
WriteMIDIFile(const char*, int, const MIDIMultiTrack*, bool)

◆ GetChanMsgName()

const char * GetChanMsgName ( unsigned char  status)

#include <midi.h>

Returns a readable name for the given channel message status.

◆ GetChanModeMsgName()

const char * GetChanModeMsgName ( unsigned char  number)

#include <midi.h>

Returns a readable name for the given channel mode (Control change with controller number between 0x78 ... 0x7f).

◆ GetSysMsgName()

const char * GetSysMsgName ( unsigned char  status)

#include <midi.h>

Returns a readable name for the given sys message status.

◆ GetMetaMsgName()

const char * GetMetaMsgName ( unsigned char  type)

#include <midi.h>

Returns a readable name for the given meta message status.

◆ GetGMProgramName()

const char * GetGMProgramName ( unsigned char  number,
int  format = 0 
)

#include <midi.h>

Returns a readable name for a GM program number.

Parameters
numberthe program number
formatif it is 1 prints the program number before its name.
Examples
test_win32_player.cpp.

◆ GetGMDrumkitName()

const char * GetGMDrumkitName ( unsigned char  number,
int  format = 0 
)

#include <midi.h>

Returns a readable name for a GM program number on channel 10 (drumkit).

Parameters
numberthe program number
formatif it is 1 prints the program number before its name.
Examples
test_win32_player.cpp.

◆ IsNoteWhite()

bool IsNoteWhite ( unsigned char  note)

#include <midi.h>

Returns true if the MIDI number of the note denotes a white key.

◆ IsNoteBlack()

bool IsNoteBlack ( unsigned char  note)

#include <midi.h>

Returns true if the MIDI number of the note denotes a black key.

◆ GetNoteOctave()

int GetNoteOctave ( unsigned char  note)
inline

#include <midi.h>

MIDI note number to standard octave conversion.

◆ KeyName()

const char * KeyName ( signed char  sharp_flats,
unsigned char  major_minor,
bool  uppercase = true,
bool  space = false,
bool  use_Mm = true 
)

#include <midi.h>

Converts a MIDI key signature into a readable form.

Parameters
sharp_flatsthe number of accidents as coded in a MIDI keysig mera messge
major_minorthe mode as coded in a MIDI keysig messages
uppercaseif true the key name (A, B, C, ...) is uppercase
spaceif true puts a space between the key and the mode (es. A m)
use_Mmif true the mode is M or m, otherwise maj or min
Examples
test_win32_player.cpp.

Variable Documentation

◆ TIME_INFINITE

const MIDIClockTime TIME_INFINITE = 0xffffffff

#include <midi.h>

A constant which represents an infinite time.

Used by some functions which search for specific events in a time interval.

Examples
test_recorder.cpp.

◆ DEFAULT_CLKS_PER_BEAT

const unsigned int DEFAULT_CLKS_PER_BEAT = 120

#include <midi.h>

The default clocks per beat parameter when initializing a MIDIMultiTrack.

This is the number of MIDI ticks for a quarter note in all the tracks of the multitrack when it is constructed. You can change it with the MIDIMultiTrack::SetClksPerBeat() method.

◆ MIDI_DEFAULT_TIMESIG_NUMERATOR

const int MIDI_DEFAULT_TIMESIG_NUMERATOR = 4

#include <midi.h>

Timesig numerator.

◆ MIDI_DEFAULT_TIMESIG_DENOMINATOR

const int MIDI_DEFAULT_TIMESIG_DENOMINATOR = 4

#include <midi.h>

Timesig denominator.

◆ MIDI_DEFAULT_TEMPO

const double MIDI_DEFAULT_TEMPO = 120.0

#include <midi.h>

Musical tempo.

◆ MIDI_DEFAULT_KEYSIG_KEY

const int MIDI_DEFAULT_KEYSIG_KEY = 0

#include <midi.h>

Keysig key (C)

◆ MIDI_DEFAULT_KEYSIG_MODE

const int MIDI_DEFAULT_KEYSIG_MODE = 0

#include <midi.h>

Keysig mode (major)