NiCMidi 1.1.0
A MIDI library derived from J.D.Koftinoff jdksmidi
MIDIRecorder Class Reference

A MIDITickComponent which can record MIDI messages incoming from a MIDI in port, putting them into an internal MIDIMultiTrack. More...

#include <recorder.h>

Inheritance diagram for MIDIRecorder:
MIDITickComponent

Public Types

enum  { REC_MERGE , REC_OVER }
 Recording mode: You can choose to merge the new with the old track content, or to overwrite it. More...
 

Public Member Functions

 MIDIRecorder (MIDISequencer *const s)
 The constructor. It binds the recorder to the given MIDISequencer. More...
 
virtual ~MIDIRecorder ()
 The destructor. More...
 
virtual void Reset ()
 It sets all tracks to recording disabled, empties the internal multitrack and sets the start and end recording times to 0 ... TIME_INFINITE. More...
 
MIDIMultiTrackGetMultiTrack () const
 Returns a pointer to the internal MIDIMultiTrack. More...
 
int GetRecMode () const
 Returns the recording mode. More...
 
MIDIClockTime GetStartRecTime () const
 Returns the recording start time in MIDI ticks. More...
 
MIDIClockTime GetEndRecTime () const
 Returns the recording end time in MIDI ticks. More...
 
MIDITrackGetTrack (unsigned int trk_num)
 Returns the pointer to a track of the internal multitrack. More...
 
const MIDITrackGetTrack (unsigned int trk_num) const
 Returns the pointer to a track of the internal multitrack. More...
 
unsigned int GetTrackInPort (unsigned int trk_num) const
 Returns the number of the MIDI in port assigned to the given track. More...
 
int GetTrackRecChannel (unsigned int trk_num)
 Returns the recording channel for the given track, or -1 for any channel. More...
 
bool SetTrackInPort (unsigned int trk_num, unsigned int port)
 Sets the MIDI in port for a track. More...
 
bool SetTrackRecChannel (unsigned int trk_num, int chan)
 Sets the recording channel for the given track. More...
 
bool SetRecMode (int mode)
 Sets the recording mode. More...
 
bool SetStartRecTime (MIDIClockTime t)
 Sets the recording start time. More...
 
bool SetStartRecTime (unsigned int meas, unsigned int beat=0)
 Sets the recording start time, giving the measure and beat. See SetStartRecTime(MIDIClockTime). More...
 
bool SetEndRecTime (MIDIClockTime t)
 Sets the recording end time. More...
 
bool SetEndRecTime (unsigned int meas, unsigned int beat=0)
 Sets the recording end time, giving the measure and beat. See SetEndRecTime(MIDIClockTime). More...
 
bool InsertTrack (int trk_num=-1)
 Inserts into the internal MIDIMultiTrack a new track. More...
 
bool DeleteTrack (int trk_num=-1)
 Deletes a track and all its events from the internal MIDIMultiTrack. More...
 
bool MoveTrack (int from, int to)
 Moves a track from one position to another in the internal MIDIMultiTrack. More...
 
bool EnableTrack (unsigned int trk_num)
 Enables a sequencer track for recording. More...
 
bool DisableTrack (unsigned int trk_num)
 Disables a sequencer track for recording. More...
 
bool UndoRec ()
 Deletes the changes made in the last recording. More...
 
virtual void Start ()
 Starts the recording from the enabled ports and channels. More...
 
virtual void Stop ()
 Stops the recording from the enabled ports and channels. More...
 
- Public Member Functions inherited from MIDITickComponent
 MIDITickComponent (tPriority pr, MIDITick func)
 The constructor. More...
 
virtual ~MIDITickComponent ()
 The destructor. More...
 
MIDITickGetFunc () const
 Returns the address of the StaticTickProc() method, which will be called by the MIDIManager at every clock tick. More...
 
tPriority GetPriority () const
 Returns the priority. More...
 
tMsecs GetDevOffset () const
 Returns the user time offset parameter (see SetDevOffset()). More...
 
bool IsPlaying () const
 Returns true if the callback procedure is active. More...
 
void SetDevOffset (tMsecs dev_offs)
 Sets an user defined time offset, which will be added to every time calculation. More...
 

Protected Member Functions

void ResizeTracks (unsigned int max_num)
 Internal function. More...
 
void SetSeqNotifier ()
 Internal function. More...
 
void ResetSeqNotifier ()
 Internal function. It is used in Stop() to reset the hook in the sequencer notifier. More...
 
void PrepareTrack (unsigned int trk_num)
 Internal function. More...
 
virtual void TickProc (tMsecs sys_time)
 Implements the pure virtual method inherited from MIDITickComponent (you must not call it directly). More...
 

Static Protected Member Functions

static void StaticTickProc (tMsecs sys_time, void *pt)
 Implements the static method inherited by MIDITickComponent and called at every timer tick. More...
 
- Static Protected Member Functions inherited from MIDITickComponent
static void StaticTickProc (tMsecs sys_time, void *pt)
 This is the static callback procedure which the MIDIManager will call at every MIDITimer tick. More...
 

Additional Inherited Members

- Protected Attributes inherited from MIDITickComponent
const MIDITicktick_proc
 The pointer to the static callback (set by the constructor to StaticTickProc()). More...
 
tMsecs dev_time_offset
 A time offset set by the user and which you can use for your calculations. More...
 
tMsecs sys_time_offset
 The system time of the last call of Start(). More...
 
std::recursive_mutex proc_lock
 A mutex you can use for implementing thread safe methods. More...
 

Detailed Description

A MIDITickComponent which can record MIDI messages incoming from a MIDI in port, putting them into an internal MIDIMultiTrack.

These are its main features:

  • Can enable one or more tracks for recording, selecting the input port and channel for everyone
  • Can select the time interval which will be affected by recording
  • Can choose between merging old and new content on the tracks or overwriting.
  • It plays a metronome click while recording (with a lead in measure before starting)
  • A multilevel undo is provided

The recorder is bounded to a MIDISequencer component (given in the constructor) which plays the tracks content while recording and sets the current time. Recorder and sequencer manage separate MIDIMultiTrack components: when the recording stops the recorder copies the new content into the sequencer MIDIMultiTrack, keeping them synchronized.

Examples
test_recorder.cpp, and test_recorder2.cpp.

Member Enumeration Documentation

◆ anonymous enum

anonymous enum

Recording mode: You can choose to merge the new with the old track content, or to overwrite it.

Enumerator
REC_MERGE 

Merge old and new content.

REC_OVER 

Overwrite the old content.

Constructor & Destructor Documentation

◆ MIDIRecorder()

MIDIRecorder::MIDIRecorder ( MIDISequencer *const  s)

The constructor. It binds the recorder to the given MIDISequencer.

◆ ~MIDIRecorder()

virtual MIDIRecorder::~MIDIRecorder ( )
virtual

The destructor.

Member Function Documentation

◆ Reset()

virtual void MIDIRecorder::Reset ( )
virtual

It sets all tracks to recording disabled, empties the internal multitrack and sets the start and end recording times to 0 ... TIME_INFINITE.

Implements MIDITickComponent.

◆ GetMultiTrack()

MIDIMultiTrack * MIDIRecorder::GetMultiTrack ( ) const
inline

Returns a pointer to the internal MIDIMultiTrack.

◆ GetRecMode()

int MIDIRecorder::GetRecMode ( ) const
inline

Returns the recording mode.

Returns
One of REC_MERGE, REC_OVER.

◆ GetStartRecTime()

MIDIClockTime MIDIRecorder::GetStartRecTime ( ) const
inline

Returns the recording start time in MIDI ticks.

◆ GetEndRecTime()

MIDIClockTime MIDIRecorder::GetEndRecTime ( ) const
inline

Returns the recording end time in MIDI ticks.

◆ GetTrack() [1/2]

MIDITrack * MIDIRecorder::GetTrack ( unsigned int  trk_num)
inline

Returns the pointer to a track of the internal multitrack.

Parameters
trk_numThe track number

◆ GetTrack() [2/2]

const MIDITrack * MIDIRecorder::GetTrack ( unsigned int  trk_num) const
inline

Returns the pointer to a track of the internal multitrack.

Parameters
trk_numThe track number

◆ GetTrackInPort()

unsigned int MIDIRecorder::GetTrackInPort ( unsigned int  trk_num) const
inline

Returns the number of the MIDI in port assigned to the given track.

Parameters
trk_numthe track number

◆ GetTrackRecChannel()

int MIDIRecorder::GetTrackRecChannel ( unsigned int  trk_num)
inline

Returns the recording channel for the given track, or -1 for any channel.

You can force a track to receive only a given channel with SetTrackRecChannel(). See Numbering conventions

◆ SetTrackInPort()

bool MIDIRecorder::SetTrackInPort ( unsigned int  trk_num,
unsigned int  port 
)

Sets the MIDI in port for a track.

This cannot be called during recording.

Parameters
trk_numthe track number
portthe id number of the port (see MIDIManager::GetOutPorts())
Returns
true if parameters are valid (and the port has been changed), false otherwise.

◆ SetTrackRecChannel()

bool MIDIRecorder::SetTrackRecChannel ( unsigned int  trk_num,
int  chan 
)

Sets the recording channel for the given track.

This cannot be called during recording.

Parameters
trk_numthe track number
chanthe channel: you can specify a number between 0 ... 15 or -1 for any channel.
Returns
true if parameters are valid (and the channel has been changed), false otherwise.

◆ SetRecMode()

bool MIDIRecorder::SetRecMode ( int  mode)

Sets the recording mode.

This cannot be called during recording.

Parameters
modeone of REC_MERGE, REC_OVER
Returns
true if the mode has been changed, false otherwise.

◆ SetStartRecTime() [1/2]

bool MIDIRecorder::SetStartRecTime ( MIDIClockTime  t)

Sets the recording start time.

If the recording end time is less than t it sets it to t. You cannot change the time while recording.

Parameters
tthe MIDI clock time to assign
Returns
true if the start time has been changed, false otherwise.

◆ SetStartRecTime() [2/2]

bool MIDIRecorder::SetStartRecTime ( unsigned int  meas,
unsigned int  beat = 0 
)
inline

Sets the recording start time, giving the measure and beat. See SetStartRecTime(MIDIClockTime).

◆ SetEndRecTime() [1/2]

bool MIDIRecorder::SetEndRecTime ( MIDIClockTime  t)

Sets the recording end time.

If the recording start time is greater than t it sets it to t. You cannot change the time while recording.

Parameters
tthe MIDI clock time to assign
Returns
true if the start time has been changed, false otherwise.

◆ SetEndRecTime() [2/2]

bool MIDIRecorder::SetEndRecTime ( unsigned int  meas,
unsigned int  beat = 0 
)
inline

Sets the recording end time, giving the measure and beat. See SetEndRecTime(MIDIClockTime).

◆ InsertTrack()

bool MIDIRecorder::InsertTrack ( int  trk_num = -1)

Inserts into the internal MIDIMultiTrack a new track.

This method is thread-safe and can be called during sequencer playback, but not during recording.

Parameters
trk_numthe track number. If you leave the default value the track will be appended as last.
Returns
true if the track was effectively inserted
Note
The recorder cannot know what you do with the attached MIDISequencer, so it doesn't check anything, always inserts the track and returns true. If you insert a track in the attached MIDISequencer you must call this with the same parameter for synchronizing the recorder with its sequencer. If you change the number of tracks of the sequencer in a more drastic mode (for example loading a MIDI file) you must call MIDIRecorder::Reset() (which disables all tracks for recording).

◆ DeleteTrack()

bool MIDIRecorder::DeleteTrack ( int  trk_num = -1)

Deletes a track and all its events from the internal MIDIMultiTrack.

This method is thread-safe and can be called during sequencer playback, but not while recording.

Parameters
trk_numthe track number (must be in the range 0 ... GetNumTracks() - 1). If you leave he default value the last track wil be deleted.
Returns
true if the track was effectively deleted
See also
note to InsertTrack()

◆ MoveTrack()

bool MIDIRecorder::MoveTrack ( int  from,
int  to 
)

Moves a track from one position to another in the internal MIDIMultiTrack.

This method is thread-safe and can be called during playback.

Parameters
from,tothe start and destination track numbers (both must be in the range 0 ... GetNumTracks() - 1).
Returns
true if the track was effectively moved
See also
note to InsertTrack()

◆ EnableTrack()

bool MIDIRecorder::EnableTrack ( unsigned int  trk_num)

Enables a sequencer track for recording.

If the track was already enabled it does nothing.

Parameters
trk_numthe track number
Returns
true if trk_num is valid (and the track has been enabled), false otherwise.

◆ DisableTrack()

bool MIDIRecorder::DisableTrack ( unsigned int  trk_num)

Disables a sequencer track for recording.

If the track was not enabled it does nothing.

Parameters
trk_numthe track number
Returns
true if trk_num is valid (and the track has been disabled), false otherwise.

◆ UndoRec()

bool MIDIRecorder::UndoRec ( )

Deletes the changes made in the last recording.

You have multiple levels of undo.

Returns
true if undo has been done, false otherwise.

◆ Start()

virtual void MIDIRecorder::Start ( )
virtual

Starts the recording from the enabled ports and channels.

It starts the attached MIDISequencer from its current position, after a lead in measure.

Reimplemented from MIDITickComponent.

◆ Stop()

virtual void MIDIRecorder::Stop ( )
virtual

Stops the recording from the enabled ports and channels.

Reimplemented from MIDITickComponent.

◆ ResizeTracks()

void MIDIRecorder::ResizeTracks ( unsigned int  max_num)
protected

Internal function.

It is used to resize the internal multitrack according to the number of enabled tracks.

◆ SetSeqNotifier()

void MIDIRecorder::SetSeqNotifier ( )
protected

Internal function.

It is used in Start() to put an hook to the metronome in the sequencer notifier.

◆ ResetSeqNotifier()

void MIDIRecorder::ResetSeqNotifier ( )
protected

Internal function. It is used in Stop() to reset the hook in the sequencer notifier.

◆ PrepareTrack()

void MIDIRecorder::PrepareTrack ( unsigned int  trk_num)
protected

Internal function.

It copies an enabled sequencer track in the recorder multitrack, deleting the channel events.

◆ StaticTickProc()

static void MIDIRecorder::StaticTickProc ( tMsecs  sys_time,
void *  pt 
)
staticprotected

Implements the static method inherited by MIDITickComponent and called at every timer tick.

It only calls the member TickProc().

◆ TickProc()

virtual void MIDIRecorder::TickProc ( tMsecs  sys_time)
protectedvirtual

Implements the pure virtual method inherited from MIDITickComponent (you must not call it directly).

Implements MIDITickComponent.


The documentation for this class was generated from the following file: