/// <summary> /// 指定したタイムコードにおける,曲頭から測った時間を調べる /// </summary> private double msec_from_clock(int timeCode) { double ret = 0.0; int index = -1; int c = g_tempoList.size(); for (int i = 0; i < c; i++) { if (timeCode <= g_tempoList.get(i).Clock) { break; } index = i; } if (index >= 0) { TempoInfo item = g_tempoList.get(index); ret = item.TotalSec + (timeCode - item.Clock) * (double)item.Tempo / (1000.0 * TIME_FORMAT); } else { ret = timeCode * (double)DEF_TEMPO / (1000.0 * TIME_FORMAT); } return(ret); }
public int sendEvent(byte[] src, int[] deltaFrames /*, int numEvents*/, int targetTrack) { lock ( locker ) { int count; int numEvents = deltaFrames.Length; if (targetTrack == 0) { if (g_tempoList == null) { g_tempoList = new Vector <TempoInfo>(); } else { g_tempoList.clear(); } if (numEvents <= 0) { g_numTempoList = 1; TempoInfo ti = new TempoInfo(); ti.Clock = 0; ti.Tempo = DEF_TEMPO; ti.TotalSec = 0.0; g_tempoList.add(ti); } else { if (deltaFrames[0] == 0) { g_numTempoList = numEvents; } else { g_numTempoList = numEvents + 1; TempoInfo ti = new TempoInfo(); ti.Clock = 0; ti.Tempo = DEF_TEMPO; ti.TotalSec = 0.0; g_tempoList.add(ti); } int prev_tempo = DEF_TEMPO; int prev_clock = 0; double total = 0.0; count = -3; for (int i = 0; i < numEvents; i++) { count += 3; int tempo = (int)(src[count + 2] | (src[count + 1] << 8) | (src[count] << 16)); total += (deltaFrames[i] - prev_clock) * (double)prev_tempo / (1000.0 * TIME_FORMAT); TempoInfo ti = new TempoInfo(); ti.Clock = deltaFrames[i]; ti.Tempo = tempo; ti.TotalSec = total; g_tempoList.add(ti); prev_tempo = tempo; prev_clock = deltaFrames[i]; } } } // 与えられたイベント情報をs_track_eventsに収納 count = -3; int pPrev = 0; s_track_events.get(targetTrack).clear(); #if VOCALO_DRIVER_PRINT_EVENTS sout.println("VocaloidDriver#SendEvent"); byte msb = 0x0; byte lsb = 0x0; #endif for (int i = 0; i < numEvents; i++) { count += 3; MidiEvent pEvent = new MidiEvent(); //pEvent = &(new MIDI_EVENT()); //pEvent->pNext = NULL; pEvent.clock = (uint)deltaFrames[i]; //pEvent.dwOffset = 0; if (targetTrack == 0) { pEvent.firstByte = 0xff; pEvent.data = new int[5]; pEvent.data[0] = 0x51; pEvent.data[1] = 0x03; pEvent.data[2] = src[count]; pEvent.data[3] = src[count + 1]; pEvent.data[4] = src[count + 2]; } else { #if VOCALO_DRIVER_PRINT_EVENTS if (src[count + 1] == 0x63) { msb = src[count + 2]; } else if (src[count + 1] == 0x62) { lsb = src[count + 2]; } else { String str = (src[count + 1] == 0x06) ? ("0x" + PortUtil.toHexString(src[count + 2], 2)) : " "; str += (src[count + 1] == 0x26) ? (" 0x" + PortUtil.toHexString(src[count + 2], 2)) : ""; int nrpn = msb << 8 | lsb; sout.println("VocaloidDriver#SendEvent; NRPN: 0x" + PortUtil.toHexString(nrpn, 4) + " " + str); } #endif pEvent.firstByte = src[count]; pEvent.data = new int[3]; pEvent.data[0] = src[count + 1]; pEvent.data[1] = src[count + 2]; pEvent.data[2] = 0x00; } s_track_events.get(targetTrack).add(pEvent); } } return(TRUE); }
public int sendEvent( byte[] src, int[] deltaFrames/*, int numEvents*/, int targetTrack ) { lock ( locker ) { int count; int numEvents = deltaFrames.Length; if ( targetTrack == 0 ) { if ( g_tempoList == null ) { g_tempoList = new Vector<TempoInfo>(); } else { g_tempoList.clear(); } if ( numEvents <= 0 ) { g_numTempoList = 1; TempoInfo ti = new TempoInfo(); ti.Clock = 0; ti.Tempo = DEF_TEMPO; ti.TotalSec = 0.0; g_tempoList.add( ti ); } else { if ( deltaFrames[0] == 0 ) { g_numTempoList = numEvents; } else { g_numTempoList = numEvents + 1; TempoInfo ti = new TempoInfo(); ti.Clock = 0; ti.Tempo = DEF_TEMPO; ti.TotalSec = 0.0; g_tempoList.add( ti ); } int prev_tempo = DEF_TEMPO; int prev_clock = 0; double total = 0.0; count = -3; for ( int i = 0; i < numEvents; i++ ) { count += 3; int tempo = (int)(src[count + 2] | (src[count + 1] << 8) | (src[count] << 16)); total += (deltaFrames[i] - prev_clock) * (double)prev_tempo / (1000.0 * TIME_FORMAT); TempoInfo ti = new TempoInfo(); ti.Clock = deltaFrames[i]; ti.Tempo = tempo; ti.TotalSec = total; g_tempoList.add( ti ); prev_tempo = tempo; prev_clock = deltaFrames[i]; } } } // 与えられたイベント情報をs_track_eventsに収納 count = -3; int pPrev = 0; s_track_events.get( targetTrack ).clear(); #if VOCALO_DRIVER_PRINT_EVENTS sout.println( "VocaloidDriver#SendEvent" ); byte msb = 0x0; byte lsb = 0x0; #endif for ( int i = 0; i < numEvents; i++ ) { count += 3; MidiEvent pEvent = new MidiEvent(); //pEvent = &(new MIDI_EVENT()); //pEvent->pNext = NULL; pEvent.clock = (uint)deltaFrames[i]; //pEvent.dwOffset = 0; if ( targetTrack == 0 ) { pEvent.firstByte = 0xff; pEvent.data = new int[5]; pEvent.data[0] = 0x51; pEvent.data[1] = 0x03; pEvent.data[2] = src[count]; pEvent.data[3] = src[count + 1]; pEvent.data[4] = src[count + 2]; } else { #if VOCALO_DRIVER_PRINT_EVENTS if ( src[count + 1] == 0x63 ) { msb = src[count + 2]; } else if ( src[count + 1] == 0x62 ) { lsb = src[count + 2]; } else { String str = (src[count + 1] == 0x06) ? ("0x" + PortUtil.toHexString( src[count + 2], 2 )) : " "; str += (src[count + 1] == 0x26) ? (" 0x" + PortUtil.toHexString( src[count + 2], 2 )) : ""; int nrpn = msb << 8 | lsb; sout.println( "VocaloidDriver#SendEvent; NRPN: 0x" + PortUtil.toHexString( nrpn, 4 ) + " " + str ); } #endif pEvent.firstByte = src[count]; pEvent.data = new int[3]; pEvent.data[0] = src[count + 1]; pEvent.data[1] = src[count + 2]; pEvent.data[2] = 0x00; } s_track_events.get( targetTrack ).add( pEvent ); } } return TRUE; }