• R/O
  • HTTP
  • SSH
  • HTTPS

コミット

タグ
未設定

よく使われているワード(クリックで追加)

javac++androidlinuxc#objective-cqtwindows誰得cocoapythonphprubygameguibathyscaphec翻訳omegat計画中(planning stage)frameworktwittertestdomvb.netdirectxbtronarduinopreviewerゲームエンジン

Windows Apps


コミットメタ情報

リビジョン0f4737482dd45943f8dfa251c999adf0c45542b2 (tree)
日時2014-07-02 00:10:28
作者oga <oga@mxg....>
コミッターoga

ログメッセージ

V0.50-14 fix prob of changing tempo.

変更サマリ

差分

Binary files a/wkeyboard/Release/wkeyboard.exe and b/wkeyboard/Release/wkeyboard.exe differ
--- a/wkeyboard/ToDo.txt
+++ b/wkeyboard/ToDo.txt
@@ -26,7 +26,7 @@ ToDo
2626 #ギターのエリア表示機能 V1.04-13 (14/06/19-14/06/21)
2727 #ステップ実行(Rew) 1四分音符の時間分戻す? V0.50-12 (14/06/25)
2828 #キー押下情報が時々残ってしまう。→一時停止解除後にいったんクリア V1.04-14 V0.50-13 (14/06/26)
29- Tempoが途中で遅くなると演奏が一時止まる(tsubame)。早くなると演奏が飛ぶ(dspirit.mid)
29+ #Tempoが途中で遅くなると演奏が一時止まる(tsubame)。早くなると演奏が飛ぶ(dspirit.mid) V0.50-14 (14/06/29-30)
3030 Tempoが効かないことがある件調査(Exメッセージ処理不正対策で解決?)
3131 古い鍵盤押下情報の廃止
3232 音声のないチャンネルのPiano1は消す
--- a/wkeyboard/midilib.c
+++ b/wkeyboard/midilib.c
@@ -72,6 +72,14 @@ typedef struct _mtck_t {
7272 short dtime; /* "MThd" DeltaTime */
7373 } mtck_t;
7474
75+/* V0.50-14-A start */
76+typedef struct _tempotbl_t {
77+ u_int delta; /* total delta */
78+ int tempo; /* tempo */
79+ u_int ms; /* total ms */
80+} tempotbl_t;
81+/* V0.50-14-A end */
82+
7583 #define SIZE_MTHD 14
7684 #define SIZE_MTRK 8
7785
@@ -79,12 +87,15 @@ typedef struct _mtck_t {
7987 #define KEY_MTRK "MTrk"
8088 #define MAX_CHLIST 32 /* max channel list */
8189 #define MAX_TRACK 50 /* max track */
90+#define MAX_TEMPO 1000 /* max tempo tbl V0.50-14-A */
91+#define DEF_TEMPO 500000 /* max tempo tbl V0.50-14-A */
8292 /* V0.14-A end */
8393
8494 #define EOD (0xffffffff)
8595 #define TICK 10 /* ms */
8696
8797 #define MS2DELTA(ms) (((ms) * hd_dtime)/(tempo/1000))
98+#define MS2DELTA2(ms, tmp) (((ms) * hd_dtime)/((tmp)/1000)) /* V0.50-14-A */
8899 #define MS2DELTA_ORG(ms) (((ms) * hd_dtime)/(orgtempo/1000)) /* V0.18-A */
89100
90101 /* Player Control Command V0.50-A */
@@ -96,10 +107,12 @@ typedef struct _mtck_t {
96107 #define CMD_REWIND 6
97108
98109 /* member variable */
99-u_int *playdat[MAX_TRACK]; /* play data 50trk V0.17-A */
100-char errmsg[4096]; /* error message V0.50-A */
110+u_int *playdat[MAX_TRACK]; /* play data 50trk V0.17-A */
111+tempotbl_t tempodat[MAX_TEMPO]; /* tempo data V0.50-14-A */
112+int temponum = 0; /* num of tempo data V0.50-14-A */
113+char errmsg[4096]; /* error message V0.50-A */
101114 int openmode = MIDILIB_MODE_USEOPEN; /* MidiOpen mode V0.50-A */
102-MIDICB cb_func = NULL; /* callback func V0.50-A */
115+MIDICB cb_func = NULL; /* callback func V0.50-A */
103116
104117 /* for PlayData() */
105118 int pos[MAX_TRACK]; /* play position of each track V0.50-M */
@@ -290,9 +303,10 @@ char *prog_name[128] = {
290303 /* for Windows Only start V0.12 */
291304 /*
292305 * playdat
293- * +--+--+--+--+
294- * |XX|D2|D1|ST|
295- * +--+--+--+--+
306+ * +0 +4
307+ * +--+--+--+--+--+--+--+--+
308+ * | DeltaTime |XX|D2|D1|ST|
309+ * +--+--+--+--+--+--+--+--+
296310 *
297311 * XX : 0xff is Meta Event
298312 */
@@ -597,7 +611,7 @@ char *buf;
597611 hd_dtime = (u_int)htons(pmthd->dtime);
598612 /* V0.14-C end */
599613
600- printf("MThd: SMF Format=%d NumOfTrack=%d DeltaTime=%d(=1/4)\n", hd_format, hd_track, hd_dtime);
614+ dlog3("MThd: SMF Format=%d NumOfTrack=%d DeltaTime=%d(=1/4)\n", hd_format, hd_track, hd_dtime);
601615
602616 if (of) {
603617 printf("output to %s\n", ofname);
@@ -669,6 +683,55 @@ int CheckTrkNo(int track)
669683 }
670684 /* V0.14-A end */
671685
686+/* V0.50-14-A start */
687+/*
688+ * Add tempo data (sort)
689+ *
690+ * IN delta_sum : total delta time
691+ * IN tempo : tempo
692+ * OUT dempodat : tempo data list
693+ * OUT demponum : num of tempodat entry
694+ *
695+ * tempodat[]
696+ * +--+--+--+--+--+--+--+--+--+--+--+--+
697+ * [0] | DeltaTime | tempo val | milli sec |
698+ * +--+--+--+--+--+--+--+--+--+--+--+--+
699+ * [1] | DeltaTime | tempo val | milli sec |
700+ * +--+--+--+--+--+--+--+--+--+--+--+--+
701+ */
702+void AddTempoDat(u_int delta_sum, int tempo)
703+{
704+ int i;
705+
706+ dlog2("AddTempoDat: delta=%d, tempo=%d\n", delta_sum, tempo);
707+
708+ if (temponum > 0 && tempodat[temponum-1].delta == delta_sum) {
709+ /* 前回と同時刻にTempo変更があった場合は後が有効 */
710+ tempodat[temponum].tempo = tempo;
711+ } else {
712+ /* 新規エントリ追加 (通常はこちら) */
713+ /* ToDo: 複数トラックにSet Tempoが存在する場合、昇順に挿入が必要 */
714+ tempodat[temponum].delta = delta_sum;
715+ tempodat[temponum].tempo = tempo;
716+ ++temponum;
717+ }
718+
719+ /* millisec 再計算 */
720+ for (i = 0; i < temponum; i++) {
721+ if (i == 0) {
722+ if (tempodat[i].delta) {
723+ tempodat[i].ms = Delta2MilliSec(tempodat[i].delta, DEF_TEMPO);
724+ } else {
725+ tempodat[i].ms = 0;
726+ }
727+ continue;
728+ }
729+ tempodat[i].ms = tempodat[i-1].ms
730+ + Delta2MilliSec(tempodat[i].delta-tempodat[i-1].delta, tempodat[i-1].tempo);
731+ }
732+}
733+/* V0.50-14-A end */
734+
672735 /*
673736 * Analyze MTrk data block
674737 *
@@ -1104,11 +1167,16 @@ int len;
11041167 * IN len : Track data len
11051168 * IN trknm : Track number
11061169 * OUT playdat[trknm][] : play data [DeltaTime][MidiMessage]
1107- *
11081170 * +0 +4
11091171 * +--+--+--+--+--+--+--+--+
11101172 * | DeltaTime |XX|D2|D1|ST|
11111173 * +--+--+--+--+--+--+--+--+
1174+ *
1175+ * OUT tempodat[idx] : tempo data
1176+ * +--+--+--+--+--+--+--+--+--+--+--+--+
1177+ * | DeltaTime | tempo val | milli sec |
1178+ * +--+--+--+--+--+--+--+--+--+--+--+--+
1179+ *
11121180 */
11131181 void ReadTrack(buf, len, trknm)
11141182 unsigned char *buf;
@@ -1142,8 +1210,8 @@ int trknm;
11421210 /* 先頭には必ずデルタタイムがある V0.16-A */
11431211 delta = GetDeltaTime(&buf[pt], codebuf, &size); /* pt 更新 */
11441212 pt += size;
1145- msec = Delta2MilliSec(delta, tempo);
1146- msec_total += msec;
1213+ msec = Delta2MilliSec(delta, tempo); /* 使用しない */
1214+ msec_total += msec; /* 使用しない */
11471215 delta_sum += delta;
11481216 /* dlog4("#ReadTrack(track%d) %d: delta = %d delta_sum = %d\n", trknm, idx, delta, delta_sum); */
11491217
@@ -1177,6 +1245,7 @@ int trknm;
11771245 playdat[trknm][idx*2] = delta_sum; /* Delta Time 累計で格納 */
11781246 playdat[trknm][idx*2+1] = (tempo | 0xff000000); /* FFtttttt */
11791247 ++idx;
1248+ AddTempoDat(delta_sum, tempo); /* V0.15-14-A */
11801249 break;
11811250 default: /* other event */
11821251 break;
@@ -1347,6 +1416,58 @@ char *buf;
13471416 }
13481417
13491418 /* V0.50-A start */
1419+/* V0.50-14-A start */
1420+/* Ms2Delta()
1421+ * milli second to delta time
1422+ *
1423+ * IN ms : milli second
1424+ * OUT ret : delta time
1425+ *
1426+ */
1427+u_int Ms2Delta(u_int ms)
1428+{
1429+ u_int wkdelta = 0;
1430+ int i;
1431+
1432+ if (temponum == 0) {
1433+ return MS2DELTA(ms);
1434+ }
1435+
1436+ for (i = 0; i < temponum; i++) {
1437+ if (ms < tempodat[i].ms) break;
1438+ }
1439+ if (i == 0 || tempodat[i-1].tempo == 0) {
1440+ return MS2DELTA2(ms, DEF_TEMPO);
1441+ }
1442+ return tempodat[i-1].delta + MS2DELTA2(ms-tempodat[i-1].ms, tempodat[i-1].tempo);
1443+}
1444+
1445+/* Delta2Ms()
1446+ * delta to milli second
1447+ *
1448+ * IN delta: delta time
1449+ * OUT ret : milli second
1450+ *
1451+ */
1452+u_int Delta2Ms(u_int delta)
1453+{
1454+ u_int wkdelta = 0;
1455+ int i;
1456+
1457+ if (temponum == 0) {
1458+ return Delta2MilliSec(delta, DEF_TEMPO);
1459+ }
1460+
1461+ for (i = 0; i < temponum; i++) {
1462+ if (delta < tempodat[i].delta) break;
1463+ }
1464+ if (i == 0 || tempodat[i-1].tempo == 0) {
1465+ return Delta2MilliSec(delta, DEF_TEMPO);
1466+ }
1467+ return tempodat[i-1].ms + Delta2MilliSec(delta-tempodat[i-1].delta, tempodat[i-1].tempo);
1468+}
1469+/* V0.50-14-A end */
1470+
13501471 /*
13511472 * FwdPlay()
13521473 * 再生位置を次の再生データの位置まで進める
@@ -1362,7 +1483,7 @@ char *buf;
13621483 * IN playdat[][]
13631484 *
13641485 */
1365-void FwdPlay(int *ptick)
1486+void FwdPlay(u_int *ptick)
13661487 {
13671488 int trk;
13681489 int cur_delta;
@@ -1372,13 +1493,13 @@ void FwdPlay(int *ptick)
13721493 dlog1("FwdPlay() start. tick=%d\n", *ptick);
13731494
13741495 while (1) {
1375- if (gmeasure * hd_dtime * 4 <= MS2DELTA(*ptick)) {
1496+ if (gmeasure * hd_dtime * 4 <= Ms2Delta(*ptick)) { /* V0.50-14-C */
13761497 if (vf && !skipping) printf("--- %4d ---------------------------------------------------------------\n", gmeasure + 1);
13771498 ++gmeasure;
13781499 }
1379- cur_delta = MS2DELTA(*ptick);
1500+ cur_delta = Ms2Delta(*ptick); /* V0.50-14-C */
13801501 for (trk = 0; trk < trkno; trk++) {
1381- while (playdat[trk][pos[trk]*2] <= MS2DELTA(*ptick)) /* delta sum V0.50-11-C */
1502+ while (playdat[trk][pos[trk]*2] <= Ms2Delta(*ptick)) /* delta sum V0.50-11-C V0.50-14-C */
13821503 {
13831504 /* DeltaTime にデータが見つかった */
13841505 /* V0.50-11-A start */
@@ -1428,7 +1549,7 @@ void FwdPlay(int *ptick)
14281549 void RewPlay(int delta_pos)
14291550 {
14301551 dlog3("RewPlay() start. cur_delta=%d/%d delta_pos=%d\n", cur_delta, total_delta, delta_pos);
1431- sttime = Delta2MilliSec(delta_pos, orgtempo); /* convert to msec */
1552+ sttime = Delta2Ms(delta_pos); /* convert to msec V0.50-14-C */
14321553 playctrl = CMD_REWIND;
14331554 dlog1("RewPlay() end. sttime=%d\n", sttime);
14341555 }
@@ -1452,7 +1573,7 @@ void RewTrackPos(int atick)
14521573 dlog1("RewTrackPos(%d)\n", atick);
14531574 memset(pos, 0, sizeof(pos));
14541575 for (trk = 0; trk < trkno; trk++) {
1455- while (playdat[trk][pos[trk]*2] <= MS2DELTA(atick)) {
1576+ while (playdat[trk][pos[trk]*2] <= Ms2Delta(atick)) { /* V0.50-14-C */
14561577 ++pos[trk];
14571578 }
14581579 dlog2("RewTrackPos: trk=%d pos=%d\n", trk, pos[trk]);
@@ -1587,15 +1708,15 @@ rewind:
15871708 }
15881709 /* V0.50-A end */
15891710
1590- if (gmeasure * hd_dtime * 4 <= MS2DELTA(tick)) {
1711+ if (gmeasure * hd_dtime * 4 <= Ms2Delta(tick)) { /* V0.50-14-C */
15911712 if (vf && !skipping) printf("--- %4d ---------------------------------------------------------------\n", gmeasure + 1);
15921713 ++gmeasure;
15931714 }
15941715
15951716 /* V0.50-A start */
1596- cur_delta = MS2DELTA(tick);
1717+ cur_delta = Ms2Delta(tick); /* V0.50-14-C */
15971718 if (cb_func && (tick - last_cb_tick >= 100)) {
1598- /* 100ms以上callbackしていなければダミーcallbackする */
1719+ /* 100ms以上callbackしていなければダミーcallbackする */
15991720 (*cb_func)(0); /* dummy call for update screen */
16001721 last_cb_tick = tick;
16011722 }
@@ -1603,12 +1724,12 @@ rewind:
16031724
16041725 for (trk = 0; trk < trkno; trk++) {
16051726 /* DeltaTime 相当の時間にきたら次のイベントを再生 */
1606- while (playdat[trk][pos[trk]*2] <= MS2DELTA(tick)) /* delta sum */
1727+ while (playdat[trk][pos[trk]*2] <= Ms2Delta(tick)) /* delta sum V0.50-14-C */
16071728 {
16081729 /* V0.18-A start */
16091730 if (sttime) {
16101731 /* printf("XXX dat_delta:%d \n"); */
1611- if (playdat[trk][pos[trk]*2] < MS2DELTA_ORG(sttime)) { /* V0.50-C */
1732+ if (playdat[trk][pos[trk]*2] < Ms2Delta(sttime)) { /* V0.50-C V0.50-14-C */
16121733 /* skipping = 1; */
16131734 } else {
16141735 skipping = 0;
@@ -1854,6 +1975,9 @@ void FreePlaydat()
18541975 playdat[i] = NULL;
18551976 }
18561977 trkno = 0;
1978+
1979+ memset(tempodat, 0, sizeof(tempodat)); /* V0.50-14-A */
1980+ temponum = 0;
18571981 }
18581982
18591983
@@ -1909,6 +2033,7 @@ int MidiRead(char *filename)
19092033 {
19102034 FILE *fp;
19112035 char buf[4096];
2036+ int i;
19122037
19132038 dlog1("MidiRead(%s)\n", (int)filename);
19142039 strcpy(errmsg, "");
@@ -1934,6 +2059,14 @@ int MidiRead(char *filename)
19342059
19352060 if (fp) fclose(fp);
19362061
2062+ /* DEBUG: V0.50-14-A start */
2063+ for (i = 0; i < temponum; i++) {
2064+ dlog4("MidiRead: tempodat[%d]: delta=%d, tempo=%d(mm=%d)",
2065+ i, tempodat[i].delta, tempodat[i].tempo, 60*1000000/tempodat[i].tempo);
2066+ dlog1(", ms=%d\n", tempodat[i].ms);
2067+ }
2068+ /* V0.50-14-A end */
2069+
19372070 return 0;
19382071 }
19392072
@@ -2023,7 +2156,7 @@ int MidiGetStatus(playstat_t *playstat)
20232156 //memset(playstat, 0, sizeof(playstat_t));
20242157 playstat->totaltime = total_delta; /* total time (delta value) */
20252158 playstat->curtime = cur_delta; /* current play position(delta)*/
2026- playstat->curmsec = Delta2MilliSec(cur_delta, orgtempo); /* current play position(msec) */
2159+ playstat->curmsec = Delta2Ms(cur_delta); /* current play position(msec) V0.50-14-C */
20272160 playstat->curtempo = (60 * 1000000)/tempo; /* current tempo(BPM) */
20282161 if (total_delta) {
20292162 playstat->progress = (cur_delta*1000)/total_delta; /* play progress rage (1/1000) */