Files
Work/guitar/backup/20030501/Timing.cpp
2024-08-07 09:16:27 -04:00

138 lines
4.3 KiB
C++

#include <guitar/Timing.hpp>
#include <guitar/GlobalDefs.hpp>
#include <guitar/registry.hpp>
int Timing::mMicrosecondsPerQuarterNote=Timing::microsecondsPerQuarterNote(Registry().getMicrosecondsPerQuarterNote());
int Timing::mMillisecondsPerWholeNote;
int Timing::mMillisecondsPerHalfNote;
int Timing::mMillisecondsPerQuarterNote;
int Timing::mMillisecondsPerEigthNote;
int Timing::mMillisecondsPerSixteenthNote;
int Timing::mMillisecondsPerThirtySecondNote;
int Timing::mMillisecondsPerSixtyFourthNote;
int Timing::microsecondsPerQuarterNote(int microsecondsPerQuarterNote)
{
mMicrosecondsPerQuarterNote=microsecondsPerQuarterNote;
mMillisecondsPerQuarterNote=(double)microsecondsPerQuarterNote*.001;
mMillisecondsPerHalfNote=mMillisecondsPerQuarterNote*2;
mMillisecondsPerWholeNote=mMillisecondsPerQuarterNote*4;
mMillisecondsPerEigthNote=mMillisecondsPerQuarterNote/2;
mMillisecondsPerSixteenthNote=mMillisecondsPerQuarterNote/4;
mMillisecondsPerThirtySecondNote=mMillisecondsPerQuarterNote/8;
mMillisecondsPerSixtyFourthNote=mMillisecondsPerQuarterNote/16;
return mMicrosecondsPerQuarterNote;
}
int Timing::microsecondsPerQuarterNote(void)
{
return mMicrosecondsPerQuarterNote;
}
void Timing::secondsPerQuarterNote(float secondsPerQuarterNote)
{
mMicrosecondsPerQuarterNote=secondsPerQuarterNote*1000000.00;;
mMillisecondsPerQuarterNote=(double)mMicrosecondsPerQuarterNote*.001;
mMillisecondsPerHalfNote=mMillisecondsPerQuarterNote*2;
mMillisecondsPerWholeNote=mMillisecondsPerQuarterNote*4;
mMillisecondsPerEigthNote=mMillisecondsPerQuarterNote/2;
mMillisecondsPerSixteenthNote=mMillisecondsPerQuarterNote/4;
mMillisecondsPerThirtySecondNote=mMillisecondsPerQuarterNote/8;
mMillisecondsPerSixtyFourthNote=mMillisecondsPerQuarterNote/16;
}
int Timing::millisecondsPerWholeNote(void)
{
return mMillisecondsPerWholeNote;
}
int Timing::millisecondsPerHalfNote(void)
{
return mMillisecondsPerHalfNote;
}
int Timing::millisecondsPerQuarterNote(void)
{
return mMillisecondsPerQuarterNote;
}
int Timing::millisecondsPerEightNote(void)
{
return mMillisecondsPerEigthNote;
}
int Timing::millisecondsPerSixteenthNote(void)
{
return mMillisecondsPerSixteenthNote;
}
int Timing::millisecondsPerThirtySecondNote(void)
{
return mMillisecondsPerThirtySecondNote;
}
int Timing::millisecondsPerSixtyFourthNote(void)
{
return mMillisecondsPerSixtyFourthNote;
}
int Timing::getDelay(const NoteType &noteType)
{
switch(noteType.getNoteType())
{
case NoteType::WholeNote :
return millisecondsPerWholeNote();
case NoteType::HalfNote :
return millisecondsPerHalfNote();
case NoteType::QuarterNote :
return millisecondsPerQuarterNote();
case NoteType::EighthNote :
return millisecondsPerEightNote();
case NoteType::SixteenthNote :
return millisecondsPerSixteenthNote();
case NoteType::ThirtySecondNote :
return millisecondsPerThirtySecondNote();
case NoteType::SixtyFourthNote :
return millisecondsPerSixtyFourthNote();
default :
return millisecondsPerSixtyFourthNote();
}
}
String Timing::toString(void)
{
String strTiming;
strTiming+=String("1/1=")+String().fromInt(millisecondsPerWholeNote())+String("ms, ");
strTiming+=String("1/2=")+String().fromInt(millisecondsPerHalfNote())+String("ms, ");
strTiming+=String("1/4=")+String().fromInt(millisecondsPerQuarterNote())+String("ms, ");
strTiming+=String("1/8=")+String().fromInt(millisecondsPerEightNote())+String("ms, ");
strTiming+=String("1/16=")+String().fromInt(millisecondsPerSixteenthNote())+String("ms, ");
strTiming+=String("1/32=")+String().fromInt(millisecondsPerThirtySecondNote())+String("ms, ");
strTiming+=String("1/64=")+String().fromInt(millisecondsPerSixtyFourthNote())+String("ms, ");
return strTiming;
}
/*
microseconds per quarter note = 631578
milliseconds per quarter note = 631578/1000 = 631
631578*.001 = 631
msecs per qtr note=usecs per qtr note *.001
quarter note = msecs per 4th note
eigth note = msecs/2
sixteenth note = msecs/4
thirty second note = msecs/8
sixty fourth note = msecs/16
(ie)
microsecs millisecs 4th note 8th note 16th note 32nd note 64th note
--------- --------- -------- -------- --------- --------- ---------
631578 631 631 315 157 78 39
options
seconds per qtr note: .5
msecs per qtr note=(seconds_per_qtr_note*1000)
*/