14 #include "jdkmidi/filewritemultitrack.h"
16 #include "ChannelPressure.h"
21 #include "PitchBend.h"
22 #include "PolyphonicPressure.h"
24 #include "TimeToken.h"
27 #if defined(_WIN32) // if this is Windows
28 #include "jdkmidi/driverwin32.h"
30 #else // this is Linux or Mac
34 #include "MidiRenderer.h"
38 MIDIRenderer::MIDIRenderer(
void) :
43 MIDIRenderer::~MIDIRenderer(
void)
48 void MIDIRenderer::Clear()
52 MIDIEventManager::Clear();
55 bool MIDIRenderer::BeginPlayAsync(
int nMIDIOutPortID,
unsigned int nTimerResolutionMS)
57 m_Sequencer.GoToZero();
58 m_MIDIManager.SetSeq(&m_Sequencer);
59 if(m_pMIDIDriver->OpenMIDIOutPort(nMIDIOutPortID))
61 m_MIDIManager.SeqPlay();
62 m_MIDIManager.SetTimeOffset(MidiTimer::Now());
63 if(!m_pMIDIDriver->StartTimer(nTimerResolutionMS))
65 m_MIDIManager.SeqStop();
73 void MIDIRenderer::EndPlayAsync()
75 m_MIDIManager.SeqStop();
76 m_pMIDIDriver->StopTimer();
77 m_pMIDIDriver->CloseMIDIOutPort();
80 void MIDIRenderer::WaitTillDone()
82 #if defined WIN32 || defined _WIN32
83 while(IsPlaying()) Sleep(500);
85 m_pMIDIDriver->WaitTillDone();
89 bool MIDIRenderer::SaveToFile(
const char* szOutputFilePath)
91 jdkmidi::MIDIFileWriteStreamFileName outFile(szOutputFilePath);
93 if(outFile.IsValid() ==
false)
return false;
95 jdkmidi::MIDIFileWriteMultiTrack WriterObj(&m_Tracks, &outFile);
97 return WriterObj.Write();
105 void MIDIRenderer::OnControllerEvent(
const CParser* pParser,
const ControllerEvent* pConEvent)
107 AddControllerEvent(pConEvent->GetControl(), pConEvent->GetValue());
110 void MIDIRenderer::OnInstrumentEvent(
const CParser* pParser,
const Instrument* pInstrument)
112 AddProgramChangeEvent(pInstrument->GetInstrumentID());
115 void MIDIRenderer::OnKeySignatureEvent(
const CParser* pParser,
const KeySignature* pKeySig)
117 AddKeySignatureEvent(pKeySig->GetKey(), pKeySig->GetMajMin());
120 void MIDIRenderer::OnLayerEvent(
const CParser* pParser,
const Layer* pLayer)
122 SetCurrentLayer(pLayer->GetLayer());
125 void MIDIRenderer::OnPitchBendEvent(
const CParser* pParser,
const PitchBend* pPB)
127 AddPitchBendEvent(pPB->GetLowByte(), pPB->GetHighByte());
130 void MIDIRenderer::OnPolyphonicPressureEvent(
const CParser* pParser,
const PolyphonicPressure* pPressure)
132 AddPolyphonicPressureEvent(pPressure->GetKey(), pPressure->GetPressure());
135 void MIDIRenderer::OnTempoEvent(
const CParser* pParser,
const Tempo* pTempo)
137 AddTempoEvent(pTempo->GetTempo());
140 void MIDIRenderer::OnTimeEvent(
const CParser* pParser,
const Time* pTime)
142 SetTrackTime(pTime->GetTime());
145 void MIDIRenderer::OnVoiceEvent(
const CParser* pParser,
const Voice* pVoice)
147 SetCurrentTrack(pVoice->GetVoice());
150 void MIDIRenderer::OnNoteEvent(
const CParser* pParser,
const Note* pNote)
152 if(pNote->duration == 0)
return;
156 AdvanceTrackTime(pNote->duration);
return;
159 if(pNote->type == pNote->FIRST)
160 m_lFirstNoteTime = GetTrackTime();
162 if(pNote->type == pNote->PARALLEL)
163 SetTrackTime(m_lFirstNoteTime);
165 AddNoteEvent(pNote->noteNumber, pNote->attackVelocity, pNote->decayVelocity, pNote->duration, !pNote->isEndOfTie, !pNote->isStartOfTie);
Declares MIDIDriverAlsa class for CFugue.
Declares MIDI Controller Events used in MusicStrings.
Declares Instrument class.
MIDI Driver for Linux Alsa based machines
Base class that represents a Parser Object.
Declares KeySignature class used in CFugue MusicString.
Declares Tempo class used in Western music.
unsigned char GetPressure() const
Returns the Channel pressure value.