00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020 #include "JackEngineControl.h"
00021 #include "JackFrameTimer.h"
00022 #include "JackGlobals.h"
00023 #include "JackMidiUtil.h"
00024 #include "JackTime.h"
00025
00026 jack_midi_data_t
00027 Jack::ApplyRunningStatus(size_t *size, jack_midi_data_t **buffer,
00028 jack_midi_data_t running_status)
00029 {
00030
00031
00032
00033 jack_midi_data_t status = **buffer;
00034 if ((status >= 0x80) && (status < 0xf0)) {
00035 if (status == running_status) {
00036 (*buffer)++;
00037 (*size)--;
00038 } else {
00039 running_status = status;
00040 }
00041 } else if (status < 0xf8) {
00042 running_status = 0;
00043 }
00044 return running_status;
00045 }
00046
00047 jack_midi_data_t
00048 Jack::ApplyRunningStatus(jack_midi_event_t *event,
00049 jack_midi_data_t running_status)
00050 {
00051 return ApplyRunningStatus(&(event->size), &(event->buffer),
00052 running_status);
00053 }
00054
00055 jack_nframes_t
00056 Jack::GetCurrentFrame()
00057 {
00058 jack_time_t time = GetMicroSeconds();
00059 JackEngineControl *control = GetEngineControl();
00060 JackTimer timer;
00061 control->ReadFrameTime(&timer);
00062 return timer.Time2Frames(time, control->fBufferSize);
00063 }
00064
00065 jack_nframes_t
00066 Jack::GetFramesFromTime(jack_time_t time)
00067 {
00068 JackEngineControl* control = GetEngineControl();
00069 JackTimer timer;
00070 control->ReadFrameTime(&timer);
00071 return timer.Time2Frames(time, control->fBufferSize);
00072 }
00073
00074 jack_nframes_t
00075 Jack::GetLastFrame()
00076 {
00077 return GetEngineControl()->fFrameTimer.ReadCurrentState()->CurFrame();
00078 }
00079
00080 int
00081 Jack::GetMessageLength(jack_midi_data_t status_byte)
00082 {
00083 switch (status_byte & 0xf0) {
00084 case 0x80:
00085 case 0x90:
00086 case 0xa0:
00087 case 0xb0:
00088 case 0xe0:
00089 return 3;
00090 case 0xc0:
00091 case 0xd0:
00092 return 2;
00093 case 0xf0:
00094 switch (status_byte) {
00095 case 0xf0:
00096 return 0;
00097 case 0xf1:
00098 case 0xf3:
00099 return 2;
00100 case 0xf2:
00101 return 3;
00102 case 0xf4:
00103 case 0xf5:
00104 case 0xf7:
00105 case 0xfd:
00106 break;
00107 default:
00108 return 1;
00109 }
00110 }
00111 return -1;
00112 }
00113
00114 jack_time_t
00115 Jack::GetTimeFromFrames(jack_nframes_t frames)
00116 {
00117 JackEngineControl* control = GetEngineControl();
00118 JackTimer timer;
00119 control->ReadFrameTime(&timer);
00120 return timer.Frames2Time(frames, control->fBufferSize);
00121 }