Ticket #7922: PATCH_MIDI_RECORD

File PATCH_MIDI_RECORD, 2.7 KB (added by SF/bbrox, 22 years ago)
Line 
1Index: imuse.cpp
2===================================================================
3RCS file: /cvsroot/scummvm/scummvm/imuse.cpp,v
4retrieving revision 1.2
5diff -u -r1.2 imuse.cpp
6--- imuse.cpp 2001/11/19 00:23:52 1.2
7+++ imuse.cpp 2001/11/25 12:26:15
8@@ -26,6 +26,10 @@
9 #include "scumm.h"
10 #include "sound.h"
11
12+#undef USE_TIMIDITY
13+
14+#define RECORD_TO_FILE
15+
16 #ifdef USE_TIMIDITY
17 #include <sys/time.h>
18 #include <unistd.h>
19@@ -42,6 +46,16 @@
20
21 #endif /* USE_TIMIDITY */
22
23+#ifdef RECORD_TO_FILE
24+
25+#define FILE_NAME "output.mid"
26+
27+#include <stdio.h>
28+#include <sys/time.h>
29+#include <unistd.h>
30+
31+#endif
32+
33 #define ARRAYSIZE(x) (sizeof(x)/sizeof(x[0]))
34
35 #define TICKS_PER_BEAT 480
36@@ -2567,6 +2581,82 @@
37 break;
38 }
39 write(s, buf, position);
40+}
41+
42+#elif defined(RECORD_TO_FILE)
43+
44+static void MIDI_OUT(void *a, unsigned int b)
45+{
46+ FILE *f = (FILE *) a;
47+ static struct timeval before;
48+ static int first = 1;
49+ struct timeval now;
50+
51+ gettimeofday(&now, NULL);
52+ if (first) {
53+ first = 0;
54+ fprintf(f, "%c", 0x00);
55+ before = now;
56+ } else {
57+ int time_elapsed;
58+
59+ time_elapsed = (now.tv_sec - before.tv_sec) * 10000 + (now.tv_usec - before.tv_usec) / 100;
60+ if (time_elapsed >= 128 * 128 * 128)
61+ fprintf(f, "%c%c%c%c",
62+ ((time_elapsed >> (3 * 7)) & 0x7F) | 0x80,
63+ ((time_elapsed >> (2 * 7)) & 0x7F) | 0x80,
64+ ((time_elapsed >> (1 * 7)) & 0x7F) | 0x80,
65+ ((time_elapsed >> (0 * 7)) & 0x7F));
66+ else if (time_elapsed >= 128 * 128)
67+ fprintf(f, "%c%c%c",
68+ ((time_elapsed >> (2 * 7)) & 0x7F) | 0x80,
69+ ((time_elapsed >> (1 * 7)) & 0x7F) | 0x80,
70+ ((time_elapsed >> (0 * 7)) & 0x7F));
71+ else if (time_elapsed >= 128)
72+ fprintf(f, "%c%c",
73+ ((time_elapsed >> (1 * 7)) & 0x7F) | 0x80,
74+ ((time_elapsed >> (0 * 7)) & 0x7F));
75+ else
76+ fprintf(f, "%c",
77+ ((time_elapsed >> (0 * 7)) & 0x7F));
78+
79+ if (time_elapsed != 0)
80+ before = now;
81+ }
82+
83+ switch (b & 0xF0) {
84+ case 0x80:
85+ case 0x90:
86+ case 0xA0:
87+ case 0xB0:
88+ case 0xE0:
89+ fprintf(f, "%c%c%c", b & 0xFF, (b >> 8) & 0x7F, (b >> 16) & 0x7F);
90+ break;
91+ case 0xC0:
92+ case 0xD0:
93+ fprintf(f, "%c%c", b & 0xFF, (b >> 8) & 0x7F);
94+ break;
95+ }
96+}
97+
98+void SoundEngine::midiInit()
99+{
100+ FILE *f;
101+ f = fopen(FILE_NAME, "wb");
102+ if (f == NULL) {
103+ warning("Could not open file : %s ", FILE_NAME);
104+ _mo = (void *) f;
105+ return;
106+ }
107+ setbuf(f, NULL);
108+
109+ fprintf(f, "%c%c%c%c%c%c%c%c%c%c%c%c%c%c", 0x4D, 0x54, 0x68, 0x64, 0x00, 0x00, 0x00, 0x06,
110+ 0x00, 0x00,
111+ 0x00, 0x01,
112+ 0x13, 0x88);
113+ fprintf(f, "%c%c%c%c%c%c%c%c", 0x4D, 0x54, 0x72, 0x6B, 0x00, 0x01, 0x00, 0x00);
114+
115+ _mo = (void *) f;
116 }
117
118 #else