Mercurial > audlegacy
annotate Plugins/Input/timidity/libtimidity/readmidi.c @ 285:d1762728ea4b trunk
[svn] Timidity support, via external contractor dai+audacious@cdr.jp.
author | nenolod |
---|---|
date | Wed, 14 Dec 2005 08:51:51 -0800 |
parents | |
children | 0235eaed75fe |
rev | line source |
---|---|
285
d1762728ea4b
[svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff
changeset
|
1 /* |
d1762728ea4b
[svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff
changeset
|
2 |
d1762728ea4b
[svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff
changeset
|
3 TiMidity -- Experimental MIDI to WAVE converter |
d1762728ea4b
[svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff
changeset
|
4 Copyright (C) 1995 Tuukka Toivonen <toivonen@clinet.fi> |
d1762728ea4b
[svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff
changeset
|
5 |
d1762728ea4b
[svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff
changeset
|
6 This program is free software; you can redistribute it and/or modify |
d1762728ea4b
[svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff
changeset
|
7 it under the terms of the GNU General Public License as published by |
d1762728ea4b
[svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff
changeset
|
8 the Free Software Foundation; either version 2 of the License, or |
d1762728ea4b
[svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff
changeset
|
9 (at your option) any later version. |
d1762728ea4b
[svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff
changeset
|
10 |
d1762728ea4b
[svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff
changeset
|
11 This program is distributed in the hope that it will be useful, |
d1762728ea4b
[svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff
changeset
|
12 but WITHOUT ANY WARRANTY; without even the implied warranty of |
d1762728ea4b
[svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff
changeset
|
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
d1762728ea4b
[svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff
changeset
|
14 GNU General Public License for more details. |
d1762728ea4b
[svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff
changeset
|
15 |
d1762728ea4b
[svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff
changeset
|
16 You should have received a copy of the GNU General Public License |
d1762728ea4b
[svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff
changeset
|
17 along with this program; if not, write to the Free Software |
d1762728ea4b
[svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff
changeset
|
18 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. |
d1762728ea4b
[svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff
changeset
|
19 |
d1762728ea4b
[svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff
changeset
|
20 */ |
d1762728ea4b
[svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff
changeset
|
21 |
d1762728ea4b
[svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff
changeset
|
22 #if HAVE_CONFIG_H |
d1762728ea4b
[svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff
changeset
|
23 # include <config.h> |
d1762728ea4b
[svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff
changeset
|
24 #endif |
d1762728ea4b
[svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff
changeset
|
25 |
d1762728ea4b
[svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff
changeset
|
26 #include <stdio.h> |
d1762728ea4b
[svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff
changeset
|
27 #include <stdlib.h> |
d1762728ea4b
[svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff
changeset
|
28 #include <string.h> |
d1762728ea4b
[svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff
changeset
|
29 |
d1762728ea4b
[svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff
changeset
|
30 #include "timidity.h" |
d1762728ea4b
[svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff
changeset
|
31 #include "timidity_internal.h" |
d1762728ea4b
[svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff
changeset
|
32 #include "options.h" |
d1762728ea4b
[svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff
changeset
|
33 #include "common.h" |
d1762728ea4b
[svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff
changeset
|
34 #include "instrum.h" |
d1762728ea4b
[svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff
changeset
|
35 #include "playmidi.h" |
d1762728ea4b
[svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff
changeset
|
36 |
d1762728ea4b
[svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff
changeset
|
37 /* Computes how many (fractional) samples one MIDI delta-time unit contains */ |
d1762728ea4b
[svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff
changeset
|
38 static void compute_sample_increment(MidSong *song, sint32 tempo, |
d1762728ea4b
[svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff
changeset
|
39 sint32 divisions) |
d1762728ea4b
[svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff
changeset
|
40 { |
d1762728ea4b
[svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff
changeset
|
41 double a; |
d1762728ea4b
[svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff
changeset
|
42 a = (double) (tempo) * (double) (song->rate) * (65536.0/1000000.0) / |
d1762728ea4b
[svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff
changeset
|
43 (double)(divisions); |
d1762728ea4b
[svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff
changeset
|
44 |
d1762728ea4b
[svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff
changeset
|
45 song->sample_correction = (sint32)(a) & 0xFFFF; |
d1762728ea4b
[svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff
changeset
|
46 song->sample_increment = (sint32)(a) >> 16; |
d1762728ea4b
[svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff
changeset
|
47 |
d1762728ea4b
[svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff
changeset
|
48 DEBUG_MSG("Samples per delta-t: %d (correction %d)\n", |
d1762728ea4b
[svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff
changeset
|
49 song->sample_increment, song->sample_correction); |
d1762728ea4b
[svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff
changeset
|
50 } |
d1762728ea4b
[svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff
changeset
|
51 |
d1762728ea4b
[svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff
changeset
|
52 /* Read variable-length number (7 bits per byte, MSB first) */ |
d1762728ea4b
[svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff
changeset
|
53 static sint32 getvl(MidIStream *stream) |
d1762728ea4b
[svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff
changeset
|
54 { |
d1762728ea4b
[svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff
changeset
|
55 sint32 l=0; |
d1762728ea4b
[svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff
changeset
|
56 uint8 c; |
d1762728ea4b
[svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff
changeset
|
57 for (;;) |
d1762728ea4b
[svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff
changeset
|
58 { |
d1762728ea4b
[svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff
changeset
|
59 mid_istream_read(stream, &c, 1, 1); |
d1762728ea4b
[svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff
changeset
|
60 l += (c & 0x7f); |
d1762728ea4b
[svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff
changeset
|
61 if (!(c & 0x80)) return l; |
d1762728ea4b
[svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff
changeset
|
62 l<<=7; |
d1762728ea4b
[svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff
changeset
|
63 } |
d1762728ea4b
[svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff
changeset
|
64 } |
d1762728ea4b
[svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff
changeset
|
65 |
d1762728ea4b
[svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff
changeset
|
66 /* Print a string from the file, followed by a newline. Any non-ASCII |
d1762728ea4b
[svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff
changeset
|
67 or unprintable characters will be converted to periods. */ |
d1762728ea4b
[svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff
changeset
|
68 static int read_meta_data(MidIStream *stream, sint32 len, uint8 type, MidSong *song) |
d1762728ea4b
[svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff
changeset
|
69 { |
d1762728ea4b
[svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff
changeset
|
70 char *s=safe_malloc(len+1); |
d1762728ea4b
[svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff
changeset
|
71 MidSongMetaId id; |
d1762728ea4b
[svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff
changeset
|
72 static char *label[] = { |
d1762728ea4b
[svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff
changeset
|
73 "Text event: ", "Text: ", "Copyright: ", "Track name: ", |
d1762728ea4b
[svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff
changeset
|
74 "Instrument: ", "Lyric: ", "Marker: ", "Cue point: "}; |
d1762728ea4b
[svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff
changeset
|
75 |
d1762728ea4b
[svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff
changeset
|
76 if (len != (sint32) mid_istream_read(stream, s, 1, len)) |
d1762728ea4b
[svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff
changeset
|
77 { |
d1762728ea4b
[svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff
changeset
|
78 free(s); |
d1762728ea4b
[svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff
changeset
|
79 return -1; |
d1762728ea4b
[svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff
changeset
|
80 } |
d1762728ea4b
[svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff
changeset
|
81 s[len]='\0'; |
d1762728ea4b
[svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff
changeset
|
82 while (len--) |
d1762728ea4b
[svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff
changeset
|
83 { |
d1762728ea4b
[svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff
changeset
|
84 if (((unsigned char)s[len])<32) |
d1762728ea4b
[svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff
changeset
|
85 s[len]='.'; |
d1762728ea4b
[svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff
changeset
|
86 } |
d1762728ea4b
[svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff
changeset
|
87 DEBUG_MSG("%s%s\n", label[(type > 7) ? 0 : type], s); |
d1762728ea4b
[svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff
changeset
|
88 |
d1762728ea4b
[svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff
changeset
|
89 switch (type) |
d1762728ea4b
[svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff
changeset
|
90 { |
d1762728ea4b
[svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff
changeset
|
91 case 1: id = MID_SONG_TEXT; break; |
d1762728ea4b
[svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff
changeset
|
92 case 2: id = MID_SONG_COPYRIGHT; break; |
d1762728ea4b
[svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff
changeset
|
93 default: free(s); s = NULL; |
d1762728ea4b
[svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff
changeset
|
94 } |
d1762728ea4b
[svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff
changeset
|
95 if (s) |
d1762728ea4b
[svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff
changeset
|
96 { |
d1762728ea4b
[svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff
changeset
|
97 if (song->meta_data[id]) |
d1762728ea4b
[svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff
changeset
|
98 free(song->meta_data[id]); |
d1762728ea4b
[svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff
changeset
|
99 song->meta_data[id] = s; |
d1762728ea4b
[svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff
changeset
|
100 } |
d1762728ea4b
[svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff
changeset
|
101 |
d1762728ea4b
[svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff
changeset
|
102 return 0; |
d1762728ea4b
[svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff
changeset
|
103 } |
d1762728ea4b
[svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff
changeset
|
104 |
d1762728ea4b
[svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff
changeset
|
105 #define MIDIEVENT(at,t,ch,pa,pb) \ |
d1762728ea4b
[svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff
changeset
|
106 new=safe_malloc(sizeof(MidEventList)); \ |
d1762728ea4b
[svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff
changeset
|
107 new->event.time=at; new->event.type=t; new->event.channel=ch; \ |
d1762728ea4b
[svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff
changeset
|
108 new->event.a=pa; new->event.b=pb; new->next=0;\ |
d1762728ea4b
[svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff
changeset
|
109 return new; |
d1762728ea4b
[svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff
changeset
|
110 |
d1762728ea4b
[svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff
changeset
|
111 #define MAGIC_EOT ((MidEventList *)(-1)) |
d1762728ea4b
[svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff
changeset
|
112 |
d1762728ea4b
[svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff
changeset
|
113 /* Read a MIDI event, returning a freshly allocated element that can |
d1762728ea4b
[svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff
changeset
|
114 be linked to the event list */ |
d1762728ea4b
[svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff
changeset
|
115 static MidEventList *read_midi_event(MidIStream *stream, MidSong *song) |
d1762728ea4b
[svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff
changeset
|
116 { |
d1762728ea4b
[svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff
changeset
|
117 static uint8 laststatus, lastchan; |
d1762728ea4b
[svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff
changeset
|
118 static uint8 nrpn=0, rpn_msb[16], rpn_lsb[16]; /* one per channel */ |
d1762728ea4b
[svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff
changeset
|
119 uint8 me, type, a,b,c; |
d1762728ea4b
[svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff
changeset
|
120 sint32 len; |
d1762728ea4b
[svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff
changeset
|
121 MidEventList *new; |
d1762728ea4b
[svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff
changeset
|
122 |
d1762728ea4b
[svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff
changeset
|
123 for (;;) |
d1762728ea4b
[svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff
changeset
|
124 { |
d1762728ea4b
[svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff
changeset
|
125 song->at += getvl(stream); |
d1762728ea4b
[svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff
changeset
|
126 if (mid_istream_read(stream, &me, 1, 1) != 1) |
d1762728ea4b
[svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff
changeset
|
127 { |
d1762728ea4b
[svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff
changeset
|
128 DEBUG_MSG("read_midi_event: mid_istream_read() failure\n"); |
d1762728ea4b
[svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff
changeset
|
129 return 0; |
d1762728ea4b
[svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff
changeset
|
130 } |
d1762728ea4b
[svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff
changeset
|
131 |
d1762728ea4b
[svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff
changeset
|
132 if(me==0xF0 || me == 0xF7) /* SysEx event */ |
d1762728ea4b
[svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff
changeset
|
133 { |
d1762728ea4b
[svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff
changeset
|
134 len=getvl(stream); |
d1762728ea4b
[svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff
changeset
|
135 mid_istream_skip(stream, len); |
d1762728ea4b
[svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff
changeset
|
136 } |
d1762728ea4b
[svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff
changeset
|
137 else if(me==0xFF) /* Meta event */ |
d1762728ea4b
[svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff
changeset
|
138 { |
d1762728ea4b
[svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff
changeset
|
139 mid_istream_read(stream, &type, 1, 1); |
d1762728ea4b
[svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff
changeset
|
140 len=getvl(stream); |
d1762728ea4b
[svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff
changeset
|
141 if (type>0 && type<16) |
d1762728ea4b
[svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff
changeset
|
142 { |
d1762728ea4b
[svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff
changeset
|
143 read_meta_data(stream, len, type, song); |
d1762728ea4b
[svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff
changeset
|
144 } |
d1762728ea4b
[svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff
changeset
|
145 else |
d1762728ea4b
[svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff
changeset
|
146 switch(type) |
d1762728ea4b
[svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff
changeset
|
147 { |
d1762728ea4b
[svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff
changeset
|
148 case 0x2F: /* End of Track */ |
d1762728ea4b
[svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff
changeset
|
149 return MAGIC_EOT; |
d1762728ea4b
[svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff
changeset
|
150 |
d1762728ea4b
[svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff
changeset
|
151 case 0x51: /* Tempo */ |
d1762728ea4b
[svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff
changeset
|
152 mid_istream_read(stream, &a, 1, 1); |
d1762728ea4b
[svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff
changeset
|
153 mid_istream_read(stream, &b, 1, 1); |
d1762728ea4b
[svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff
changeset
|
154 mid_istream_read(stream, &c, 1, 1); |
d1762728ea4b
[svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff
changeset
|
155 MIDIEVENT(song->at, ME_TEMPO, c, a, b); |
d1762728ea4b
[svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff
changeset
|
156 |
d1762728ea4b
[svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff
changeset
|
157 default: |
d1762728ea4b
[svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff
changeset
|
158 DEBUG_MSG("(Meta event type 0x%02x, length %d)\n", type, len); |
d1762728ea4b
[svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff
changeset
|
159 mid_istream_skip(stream, len); |
d1762728ea4b
[svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff
changeset
|
160 break; |
d1762728ea4b
[svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff
changeset
|
161 } |
d1762728ea4b
[svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff
changeset
|
162 } |
d1762728ea4b
[svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff
changeset
|
163 else |
d1762728ea4b
[svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff
changeset
|
164 { |
d1762728ea4b
[svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff
changeset
|
165 a=me; |
d1762728ea4b
[svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff
changeset
|
166 if (a & 0x80) /* status byte */ |
d1762728ea4b
[svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff
changeset
|
167 { |
d1762728ea4b
[svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff
changeset
|
168 lastchan=a & 0x0F; |
d1762728ea4b
[svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff
changeset
|
169 laststatus=(a>>4) & 0x07; |
d1762728ea4b
[svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff
changeset
|
170 mid_istream_read(stream, &a, 1, 1); |
d1762728ea4b
[svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff
changeset
|
171 a &= 0x7F; |
d1762728ea4b
[svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff
changeset
|
172 } |
d1762728ea4b
[svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff
changeset
|
173 switch(laststatus) |
d1762728ea4b
[svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff
changeset
|
174 { |
d1762728ea4b
[svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff
changeset
|
175 case 0: /* Note off */ |
d1762728ea4b
[svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff
changeset
|
176 mid_istream_read(stream, &b, 1, 1); |
d1762728ea4b
[svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff
changeset
|
177 b &= 0x7F; |
d1762728ea4b
[svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff
changeset
|
178 MIDIEVENT(song->at, ME_NOTEOFF, lastchan, a,b); |
d1762728ea4b
[svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff
changeset
|
179 |
d1762728ea4b
[svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff
changeset
|
180 case 1: /* Note on */ |
d1762728ea4b
[svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff
changeset
|
181 mid_istream_read(stream, &b, 1, 1); |
d1762728ea4b
[svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff
changeset
|
182 b &= 0x7F; |
d1762728ea4b
[svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff
changeset
|
183 MIDIEVENT(song->at, ME_NOTEON, lastchan, a,b); |
d1762728ea4b
[svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff
changeset
|
184 |
d1762728ea4b
[svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff
changeset
|
185 case 2: /* Key Pressure */ |
d1762728ea4b
[svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff
changeset
|
186 mid_istream_read(stream, &b, 1, 1); |
d1762728ea4b
[svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff
changeset
|
187 b &= 0x7F; |
d1762728ea4b
[svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff
changeset
|
188 MIDIEVENT(song->at, ME_KEYPRESSURE, lastchan, a, b); |
d1762728ea4b
[svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff
changeset
|
189 |
d1762728ea4b
[svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff
changeset
|
190 case 3: /* Control change */ |
d1762728ea4b
[svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff
changeset
|
191 mid_istream_read(stream, &b, 1, 1); |
d1762728ea4b
[svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff
changeset
|
192 b &= 0x7F; |
d1762728ea4b
[svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff
changeset
|
193 { |
d1762728ea4b
[svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff
changeset
|
194 int control=255; |
d1762728ea4b
[svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff
changeset
|
195 switch(a) |
d1762728ea4b
[svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff
changeset
|
196 { |
d1762728ea4b
[svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff
changeset
|
197 case 7: control=ME_MAINVOLUME; break; |
d1762728ea4b
[svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff
changeset
|
198 case 10: control=ME_PAN; break; |
d1762728ea4b
[svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff
changeset
|
199 case 11: control=ME_EXPRESSION; break; |
d1762728ea4b
[svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff
changeset
|
200 case 64: control=ME_SUSTAIN; break; |
d1762728ea4b
[svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff
changeset
|
201 case 120: control=ME_ALL_SOUNDS_OFF; break; |
d1762728ea4b
[svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff
changeset
|
202 case 121: control=ME_RESET_CONTROLLERS; break; |
d1762728ea4b
[svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff
changeset
|
203 case 123: control=ME_ALL_NOTES_OFF; break; |
d1762728ea4b
[svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff
changeset
|
204 |
d1762728ea4b
[svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff
changeset
|
205 /* These should be the SCC-1 tone bank switch |
d1762728ea4b
[svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff
changeset
|
206 commands. I don't know why there are two, or |
d1762728ea4b
[svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff
changeset
|
207 why the latter only allows switching to bank 0. |
d1762728ea4b
[svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff
changeset
|
208 Also, some MIDI files use 0 as some sort of |
d1762728ea4b
[svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff
changeset
|
209 continuous controller. This will cause lots of |
d1762728ea4b
[svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff
changeset
|
210 warnings about undefined tone banks. */ |
d1762728ea4b
[svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff
changeset
|
211 case 0: control=ME_TONE_BANK; break; |
d1762728ea4b
[svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff
changeset
|
212 case 32: |
d1762728ea4b
[svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff
changeset
|
213 if (b!=0) |
d1762728ea4b
[svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff
changeset
|
214 DEBUG_MSG("(Strange: tone bank change 0x20%02x)\n", b); |
d1762728ea4b
[svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff
changeset
|
215 else |
d1762728ea4b
[svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff
changeset
|
216 control=ME_TONE_BANK; |
d1762728ea4b
[svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff
changeset
|
217 break; |
d1762728ea4b
[svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff
changeset
|
218 |
d1762728ea4b
[svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff
changeset
|
219 case 100: nrpn=0; rpn_msb[lastchan]=b; break; |
d1762728ea4b
[svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff
changeset
|
220 case 101: nrpn=0; rpn_lsb[lastchan]=b; break; |
d1762728ea4b
[svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff
changeset
|
221 case 99: nrpn=1; rpn_msb[lastchan]=b; break; |
d1762728ea4b
[svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff
changeset
|
222 case 98: nrpn=1; rpn_lsb[lastchan]=b; break; |
d1762728ea4b
[svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff
changeset
|
223 |
d1762728ea4b
[svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff
changeset
|
224 case 6: |
d1762728ea4b
[svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff
changeset
|
225 if (nrpn) |
d1762728ea4b
[svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff
changeset
|
226 { |
d1762728ea4b
[svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff
changeset
|
227 DEBUG_MSG("(Data entry (MSB) for NRPN %02x,%02x: %d)\n", |
d1762728ea4b
[svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff
changeset
|
228 rpn_msb[lastchan], rpn_lsb[lastchan], b); |
d1762728ea4b
[svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff
changeset
|
229 break; |
d1762728ea4b
[svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff
changeset
|
230 } |
d1762728ea4b
[svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff
changeset
|
231 |
d1762728ea4b
[svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff
changeset
|
232 switch((rpn_msb[lastchan]<<8) | rpn_lsb[lastchan]) |
d1762728ea4b
[svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff
changeset
|
233 { |
d1762728ea4b
[svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff
changeset
|
234 case 0x0000: /* Pitch bend sensitivity */ |
d1762728ea4b
[svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff
changeset
|
235 control=ME_PITCH_SENS; |
d1762728ea4b
[svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff
changeset
|
236 break; |
d1762728ea4b
[svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff
changeset
|
237 |
d1762728ea4b
[svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff
changeset
|
238 case 0x7F7F: /* RPN reset */ |
d1762728ea4b
[svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff
changeset
|
239 /* reset pitch bend sensitivity to 2 */ |
d1762728ea4b
[svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff
changeset
|
240 MIDIEVENT(song->at, ME_PITCH_SENS, lastchan, 2, 0); |
d1762728ea4b
[svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff
changeset
|
241 |
d1762728ea4b
[svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff
changeset
|
242 default: |
d1762728ea4b
[svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff
changeset
|
243 DEBUG_MSG("(Data entry (MSB) for RPN %02x,%02x: %d)\n", |
d1762728ea4b
[svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff
changeset
|
244 rpn_msb[lastchan], rpn_lsb[lastchan], b); |
d1762728ea4b
[svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff
changeset
|
245 break; |
d1762728ea4b
[svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff
changeset
|
246 } |
d1762728ea4b
[svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff
changeset
|
247 break; |
d1762728ea4b
[svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff
changeset
|
248 |
d1762728ea4b
[svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff
changeset
|
249 default: |
d1762728ea4b
[svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff
changeset
|
250 DEBUG_MSG("(Control %d: %d)\n", a, b); |
d1762728ea4b
[svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff
changeset
|
251 break; |
d1762728ea4b
[svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff
changeset
|
252 } |
d1762728ea4b
[svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff
changeset
|
253 if (control != 255) |
d1762728ea4b
[svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff
changeset
|
254 { |
d1762728ea4b
[svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff
changeset
|
255 MIDIEVENT(song->at, control, lastchan, b, 0); |
d1762728ea4b
[svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff
changeset
|
256 } |
d1762728ea4b
[svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff
changeset
|
257 } |
d1762728ea4b
[svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff
changeset
|
258 break; |
d1762728ea4b
[svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff
changeset
|
259 |
d1762728ea4b
[svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff
changeset
|
260 case 4: /* Program change */ |
d1762728ea4b
[svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff
changeset
|
261 a &= 0x7f; |
d1762728ea4b
[svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff
changeset
|
262 MIDIEVENT(song->at, ME_PROGRAM, lastchan, a, 0); |
d1762728ea4b
[svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff
changeset
|
263 |
d1762728ea4b
[svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff
changeset
|
264 case 5: /* Channel pressure - NOT IMPLEMENTED */ |
d1762728ea4b
[svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff
changeset
|
265 break; |
d1762728ea4b
[svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff
changeset
|
266 |
d1762728ea4b
[svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff
changeset
|
267 case 6: /* Pitch wheel */ |
d1762728ea4b
[svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff
changeset
|
268 mid_istream_read(stream, &b, 1, 1); |
d1762728ea4b
[svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff
changeset
|
269 b &= 0x7F; |
d1762728ea4b
[svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff
changeset
|
270 MIDIEVENT(song->at, ME_PITCHWHEEL, lastchan, a, b); |
d1762728ea4b
[svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff
changeset
|
271 |
d1762728ea4b
[svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff
changeset
|
272 default: |
d1762728ea4b
[svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff
changeset
|
273 DEBUG_MSG("*** Can't happen: status 0x%02X, channel 0x%02X\n", |
d1762728ea4b
[svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff
changeset
|
274 laststatus, lastchan); |
d1762728ea4b
[svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff
changeset
|
275 break; |
d1762728ea4b
[svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff
changeset
|
276 } |
d1762728ea4b
[svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff
changeset
|
277 } |
d1762728ea4b
[svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff
changeset
|
278 } |
d1762728ea4b
[svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff
changeset
|
279 |
d1762728ea4b
[svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff
changeset
|
280 return new; |
d1762728ea4b
[svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff
changeset
|
281 } |
d1762728ea4b
[svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff
changeset
|
282 |
d1762728ea4b
[svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff
changeset
|
283 #undef MIDIEVENT |
d1762728ea4b
[svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff
changeset
|
284 |
d1762728ea4b
[svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff
changeset
|
285 /* Read a midi track into the linked list, either merging with any previous |
d1762728ea4b
[svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff
changeset
|
286 tracks or appending to them. */ |
d1762728ea4b
[svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff
changeset
|
287 static int read_track(MidIStream *stream, MidSong *song, int append) |
d1762728ea4b
[svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff
changeset
|
288 { |
d1762728ea4b
[svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff
changeset
|
289 MidEventList *meep; |
d1762728ea4b
[svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff
changeset
|
290 MidEventList *next, *new; |
d1762728ea4b
[svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff
changeset
|
291 sint32 len; |
d1762728ea4b
[svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff
changeset
|
292 char tmp[4]; |
d1762728ea4b
[svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff
changeset
|
293 |
d1762728ea4b
[svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff
changeset
|
294 meep = song->evlist; |
d1762728ea4b
[svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff
changeset
|
295 if (append && meep) |
d1762728ea4b
[svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff
changeset
|
296 { |
d1762728ea4b
[svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff
changeset
|
297 /* find the last event in the list */ |
d1762728ea4b
[svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff
changeset
|
298 for (; meep->next; meep=meep->next) |
d1762728ea4b
[svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff
changeset
|
299 ; |
d1762728ea4b
[svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff
changeset
|
300 song->at = meep->event.time; |
d1762728ea4b
[svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff
changeset
|
301 } |
d1762728ea4b
[svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff
changeset
|
302 else |
d1762728ea4b
[svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff
changeset
|
303 song->at=0; |
d1762728ea4b
[svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff
changeset
|
304 |
d1762728ea4b
[svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff
changeset
|
305 /* Check the formalities */ |
d1762728ea4b
[svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff
changeset
|
306 |
d1762728ea4b
[svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff
changeset
|
307 if (mid_istream_read(stream, tmp, 1, 4) != 4 || mid_istream_read(stream, &len, 4, 1) != 1) |
d1762728ea4b
[svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff
changeset
|
308 { |
d1762728ea4b
[svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff
changeset
|
309 DEBUG_MSG("Can't read track header.\n"); |
d1762728ea4b
[svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff
changeset
|
310 return -1; |
d1762728ea4b
[svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff
changeset
|
311 } |
d1762728ea4b
[svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff
changeset
|
312 len=SWAPBE32(len); |
d1762728ea4b
[svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff
changeset
|
313 if (memcmp(tmp, "MTrk", 4)) |
d1762728ea4b
[svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff
changeset
|
314 { |
d1762728ea4b
[svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff
changeset
|
315 DEBUG_MSG("Corrupt MIDI file.\n"); |
d1762728ea4b
[svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff
changeset
|
316 return -2; |
d1762728ea4b
[svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff
changeset
|
317 } |
d1762728ea4b
[svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff
changeset
|
318 |
d1762728ea4b
[svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff
changeset
|
319 for (;;) |
d1762728ea4b
[svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff
changeset
|
320 { |
d1762728ea4b
[svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff
changeset
|
321 if (!(new=read_midi_event(stream, song))) /* Some kind of error */ |
d1762728ea4b
[svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff
changeset
|
322 return -2; |
d1762728ea4b
[svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff
changeset
|
323 |
d1762728ea4b
[svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff
changeset
|
324 if (new==MAGIC_EOT) /* End-of-track Hack. */ |
d1762728ea4b
[svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff
changeset
|
325 { |
d1762728ea4b
[svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff
changeset
|
326 return 0; |
d1762728ea4b
[svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff
changeset
|
327 } |
d1762728ea4b
[svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff
changeset
|
328 |
d1762728ea4b
[svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff
changeset
|
329 next=meep->next; |
d1762728ea4b
[svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff
changeset
|
330 while (next && (next->event.time < new->event.time)) |
d1762728ea4b
[svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff
changeset
|
331 { |
d1762728ea4b
[svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff
changeset
|
332 meep=next; |
d1762728ea4b
[svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff
changeset
|
333 next=meep->next; |
d1762728ea4b
[svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff
changeset
|
334 } |
d1762728ea4b
[svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff
changeset
|
335 |
d1762728ea4b
[svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff
changeset
|
336 new->next=next; |
d1762728ea4b
[svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff
changeset
|
337 meep->next=new; |
d1762728ea4b
[svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff
changeset
|
338 |
d1762728ea4b
[svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff
changeset
|
339 song->event_count++; /* Count the event. (About one?) */ |
d1762728ea4b
[svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff
changeset
|
340 meep=new; |
d1762728ea4b
[svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff
changeset
|
341 } |
d1762728ea4b
[svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff
changeset
|
342 } |
d1762728ea4b
[svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff
changeset
|
343 |
d1762728ea4b
[svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff
changeset
|
344 /* Free the linked event list from memory. */ |
d1762728ea4b
[svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff
changeset
|
345 static void free_midi_list(MidSong *song) |
d1762728ea4b
[svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff
changeset
|
346 { |
d1762728ea4b
[svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff
changeset
|
347 MidEventList *meep, *next; |
d1762728ea4b
[svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff
changeset
|
348 if (!(meep = song->evlist)) return; |
d1762728ea4b
[svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff
changeset
|
349 while (meep) |
d1762728ea4b
[svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff
changeset
|
350 { |
d1762728ea4b
[svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff
changeset
|
351 next=meep->next; |
d1762728ea4b
[svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff
changeset
|
352 free(meep); |
d1762728ea4b
[svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff
changeset
|
353 meep=next; |
d1762728ea4b
[svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff
changeset
|
354 } |
d1762728ea4b
[svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff
changeset
|
355 song->evlist=0; |
d1762728ea4b
[svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff
changeset
|
356 } |
d1762728ea4b
[svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff
changeset
|
357 |
d1762728ea4b
[svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff
changeset
|
358 /* Allocate an array of MidiEvents and fill it from the linked list of |
d1762728ea4b
[svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff
changeset
|
359 events, marking used instruments for loading. Convert event times to |
d1762728ea4b
[svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff
changeset
|
360 samples: handle tempo changes. Strip unnecessary events from the list. |
d1762728ea4b
[svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff
changeset
|
361 Free the linked list. */ |
d1762728ea4b
[svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff
changeset
|
362 static MidEvent *groom_list(MidSong *song, sint32 divisions,sint32 *eventsp, |
d1762728ea4b
[svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff
changeset
|
363 sint32 *samplesp) |
d1762728ea4b
[svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff
changeset
|
364 { |
d1762728ea4b
[svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff
changeset
|
365 MidEvent *groomed_list, *lp; |
d1762728ea4b
[svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff
changeset
|
366 MidEventList *meep; |
d1762728ea4b
[svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff
changeset
|
367 sint32 i, our_event_count, tempo, skip_this_event, new_value; |
d1762728ea4b
[svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff
changeset
|
368 sint32 sample_cum, samples_to_do, at, st, dt, counting_time; |
d1762728ea4b
[svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff
changeset
|
369 |
d1762728ea4b
[svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff
changeset
|
370 int current_bank[16], current_set[16], current_program[16]; |
d1762728ea4b
[svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff
changeset
|
371 /* Or should each bank have its own current program? */ |
d1762728ea4b
[svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff
changeset
|
372 |
d1762728ea4b
[svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff
changeset
|
373 for (i=0; i<16; i++) |
d1762728ea4b
[svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff
changeset
|
374 { |
d1762728ea4b
[svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff
changeset
|
375 current_bank[i]=0; |
d1762728ea4b
[svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff
changeset
|
376 current_set[i]=0; |
d1762728ea4b
[svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff
changeset
|
377 current_program[i]=song->default_program; |
d1762728ea4b
[svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff
changeset
|
378 } |
d1762728ea4b
[svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff
changeset
|
379 |
d1762728ea4b
[svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff
changeset
|
380 tempo=500000; |
d1762728ea4b
[svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff
changeset
|
381 compute_sample_increment(song, tempo, divisions); |
d1762728ea4b
[svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff
changeset
|
382 |
d1762728ea4b
[svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff
changeset
|
383 /* This may allocate a bit more than we need */ |
d1762728ea4b
[svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff
changeset
|
384 groomed_list=lp=safe_malloc(sizeof(MidEvent) * (song->event_count+1)); |
d1762728ea4b
[svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff
changeset
|
385 meep=song->evlist; |
d1762728ea4b
[svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff
changeset
|
386 |
d1762728ea4b
[svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff
changeset
|
387 our_event_count=0; |
d1762728ea4b
[svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff
changeset
|
388 st=at=sample_cum=0; |
d1762728ea4b
[svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff
changeset
|
389 counting_time=2; /* We strip any silence before the first NOTE ON. */ |
d1762728ea4b
[svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff
changeset
|
390 |
d1762728ea4b
[svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff
changeset
|
391 for (i = 0; i < song->event_count; i++) |
d1762728ea4b
[svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff
changeset
|
392 { |
d1762728ea4b
[svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff
changeset
|
393 skip_this_event=0; |
d1762728ea4b
[svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff
changeset
|
394 |
d1762728ea4b
[svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff
changeset
|
395 if (meep->event.type==ME_TEMPO) |
d1762728ea4b
[svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff
changeset
|
396 { |
d1762728ea4b
[svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff
changeset
|
397 tempo= |
d1762728ea4b
[svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff
changeset
|
398 meep->event.channel + meep->event.b * 256 + meep->event.a * 65536; |
d1762728ea4b
[svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff
changeset
|
399 compute_sample_increment(song, tempo, divisions); |
d1762728ea4b
[svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff
changeset
|
400 skip_this_event=1; |
d1762728ea4b
[svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff
changeset
|
401 } |
d1762728ea4b
[svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff
changeset
|
402 else switch (meep->event.type) |
d1762728ea4b
[svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff
changeset
|
403 { |
d1762728ea4b
[svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff
changeset
|
404 case ME_PROGRAM: |
d1762728ea4b
[svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff
changeset
|
405 if (ISDRUMCHANNEL(song, meep->event.channel)) |
d1762728ea4b
[svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff
changeset
|
406 { |
d1762728ea4b
[svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff
changeset
|
407 if (song->drumset[meep->event.a]) /* Is this a defined drumset? */ |
d1762728ea4b
[svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff
changeset
|
408 new_value=meep->event.a; |
d1762728ea4b
[svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff
changeset
|
409 else |
d1762728ea4b
[svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff
changeset
|
410 { |
d1762728ea4b
[svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff
changeset
|
411 DEBUG_MSG("Drum set %d is undefined\n", meep->event.a); |
d1762728ea4b
[svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff
changeset
|
412 new_value=meep->event.a=0; |
d1762728ea4b
[svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff
changeset
|
413 } |
d1762728ea4b
[svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff
changeset
|
414 if (current_set[meep->event.channel] != new_value) |
d1762728ea4b
[svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff
changeset
|
415 current_set[meep->event.channel]=new_value; |
d1762728ea4b
[svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff
changeset
|
416 else |
d1762728ea4b
[svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff
changeset
|
417 skip_this_event=1; |
d1762728ea4b
[svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff
changeset
|
418 } |
d1762728ea4b
[svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff
changeset
|
419 else |
d1762728ea4b
[svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff
changeset
|
420 { |
d1762728ea4b
[svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff
changeset
|
421 new_value=meep->event.a; |
d1762728ea4b
[svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff
changeset
|
422 if ((current_program[meep->event.channel] != SPECIAL_PROGRAM) |
d1762728ea4b
[svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff
changeset
|
423 && (current_program[meep->event.channel] != new_value)) |
d1762728ea4b
[svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff
changeset
|
424 current_program[meep->event.channel] = new_value; |
d1762728ea4b
[svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff
changeset
|
425 else |
d1762728ea4b
[svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff
changeset
|
426 skip_this_event=1; |
d1762728ea4b
[svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff
changeset
|
427 } |
d1762728ea4b
[svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff
changeset
|
428 break; |
d1762728ea4b
[svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff
changeset
|
429 |
d1762728ea4b
[svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff
changeset
|
430 case ME_NOTEON: |
d1762728ea4b
[svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff
changeset
|
431 if (counting_time) |
d1762728ea4b
[svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff
changeset
|
432 counting_time=1; |
d1762728ea4b
[svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff
changeset
|
433 if (ISDRUMCHANNEL(song, meep->event.channel)) |
d1762728ea4b
[svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff
changeset
|
434 { |
d1762728ea4b
[svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff
changeset
|
435 /* Mark this instrument to be loaded */ |
d1762728ea4b
[svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff
changeset
|
436 if (!(song->drumset[current_set[meep->event.channel]] |
d1762728ea4b
[svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff
changeset
|
437 ->instrument[meep->event.a])) |
d1762728ea4b
[svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff
changeset
|
438 song->drumset[current_set[meep->event.channel]] |
d1762728ea4b
[svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff
changeset
|
439 ->instrument[meep->event.a] = MAGIC_LOAD_INSTRUMENT; |
d1762728ea4b
[svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff
changeset
|
440 } |
d1762728ea4b
[svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff
changeset
|
441 else |
d1762728ea4b
[svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff
changeset
|
442 { |
d1762728ea4b
[svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff
changeset
|
443 if (current_program[meep->event.channel]==SPECIAL_PROGRAM) |
d1762728ea4b
[svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff
changeset
|
444 break; |
d1762728ea4b
[svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff
changeset
|
445 /* Mark this instrument to be loaded */ |
d1762728ea4b
[svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff
changeset
|
446 if (!(song->tonebank[current_bank[meep->event.channel]] |
d1762728ea4b
[svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff
changeset
|
447 ->instrument[current_program[meep->event.channel]])) |
d1762728ea4b
[svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff
changeset
|
448 song->tonebank[current_bank[meep->event.channel]] |
d1762728ea4b
[svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff
changeset
|
449 ->instrument[current_program[meep->event.channel]] = |
d1762728ea4b
[svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff
changeset
|
450 MAGIC_LOAD_INSTRUMENT; |
d1762728ea4b
[svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff
changeset
|
451 } |
d1762728ea4b
[svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff
changeset
|
452 break; |
d1762728ea4b
[svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff
changeset
|
453 |
d1762728ea4b
[svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff
changeset
|
454 case ME_TONE_BANK: |
d1762728ea4b
[svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff
changeset
|
455 if (ISDRUMCHANNEL(song, meep->event.channel)) |
d1762728ea4b
[svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff
changeset
|
456 { |
d1762728ea4b
[svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff
changeset
|
457 skip_this_event=1; |
d1762728ea4b
[svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff
changeset
|
458 break; |
d1762728ea4b
[svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff
changeset
|
459 } |
d1762728ea4b
[svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff
changeset
|
460 if (song->tonebank[meep->event.a]) /* Is this a defined tone bank? */ |
d1762728ea4b
[svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff
changeset
|
461 new_value=meep->event.a; |
d1762728ea4b
[svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff
changeset
|
462 else |
d1762728ea4b
[svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff
changeset
|
463 { |
d1762728ea4b
[svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff
changeset
|
464 DEBUG_MSG("Tone bank %d is undefined\n", meep->event.a); |
d1762728ea4b
[svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff
changeset
|
465 new_value=meep->event.a=0; |
d1762728ea4b
[svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff
changeset
|
466 } |
d1762728ea4b
[svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff
changeset
|
467 if (current_bank[meep->event.channel]!=new_value) |
d1762728ea4b
[svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff
changeset
|
468 current_bank[meep->event.channel]=new_value; |
d1762728ea4b
[svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff
changeset
|
469 else |
d1762728ea4b
[svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff
changeset
|
470 skip_this_event=1; |
d1762728ea4b
[svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff
changeset
|
471 break; |
d1762728ea4b
[svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff
changeset
|
472 } |
d1762728ea4b
[svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff
changeset
|
473 |
d1762728ea4b
[svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff
changeset
|
474 /* Recompute time in samples*/ |
d1762728ea4b
[svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff
changeset
|
475 if ((dt=meep->event.time - at) && !counting_time) |
d1762728ea4b
[svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff
changeset
|
476 { |
d1762728ea4b
[svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff
changeset
|
477 samples_to_do = song->sample_increment * dt; |
d1762728ea4b
[svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff
changeset
|
478 sample_cum += song->sample_correction * dt; |
d1762728ea4b
[svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff
changeset
|
479 if (sample_cum & 0xFFFF0000) |
d1762728ea4b
[svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff
changeset
|
480 { |
d1762728ea4b
[svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff
changeset
|
481 samples_to_do += ((sample_cum >> 16) & 0xFFFF); |
d1762728ea4b
[svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff
changeset
|
482 sample_cum &= 0x0000FFFF; |
d1762728ea4b
[svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff
changeset
|
483 } |
d1762728ea4b
[svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff
changeset
|
484 st += samples_to_do; |
d1762728ea4b
[svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff
changeset
|
485 } |
d1762728ea4b
[svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff
changeset
|
486 else if (counting_time==1) counting_time=0; |
d1762728ea4b
[svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff
changeset
|
487 if (!skip_this_event) |
d1762728ea4b
[svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff
changeset
|
488 { |
d1762728ea4b
[svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff
changeset
|
489 /* Add the event to the list */ |
d1762728ea4b
[svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff
changeset
|
490 *lp=meep->event; |
d1762728ea4b
[svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff
changeset
|
491 lp->time=st; |
d1762728ea4b
[svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff
changeset
|
492 lp++; |
d1762728ea4b
[svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff
changeset
|
493 our_event_count++; |
d1762728ea4b
[svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff
changeset
|
494 } |
d1762728ea4b
[svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff
changeset
|
495 at=meep->event.time; |
d1762728ea4b
[svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff
changeset
|
496 meep=meep->next; |
d1762728ea4b
[svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff
changeset
|
497 } |
d1762728ea4b
[svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff
changeset
|
498 /* Add an End-of-Track event */ |
d1762728ea4b
[svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff
changeset
|
499 lp->time=st; |
d1762728ea4b
[svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff
changeset
|
500 lp->type=ME_EOT; |
d1762728ea4b
[svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff
changeset
|
501 our_event_count++; |
d1762728ea4b
[svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff
changeset
|
502 free_midi_list(song); |
d1762728ea4b
[svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff
changeset
|
503 |
d1762728ea4b
[svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff
changeset
|
504 *eventsp=our_event_count; |
d1762728ea4b
[svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff
changeset
|
505 *samplesp=st; |
d1762728ea4b
[svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff
changeset
|
506 return groomed_list; |
d1762728ea4b
[svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff
changeset
|
507 } |
d1762728ea4b
[svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff
changeset
|
508 |
d1762728ea4b
[svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff
changeset
|
509 MidEvent *read_midi_file(MidIStream *stream, MidSong *song, sint32 *count, sint32 *sp) |
d1762728ea4b
[svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff
changeset
|
510 { |
d1762728ea4b
[svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff
changeset
|
511 sint32 len, divisions; |
d1762728ea4b
[svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff
changeset
|
512 sint16 format, tracks, divisions_tmp; |
d1762728ea4b
[svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff
changeset
|
513 int i; |
d1762728ea4b
[svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff
changeset
|
514 char tmp[4]; |
d1762728ea4b
[svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff
changeset
|
515 |
d1762728ea4b
[svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff
changeset
|
516 song->event_count=0; |
d1762728ea4b
[svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff
changeset
|
517 song->at=0; |
d1762728ea4b
[svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff
changeset
|
518 song->evlist=0; |
d1762728ea4b
[svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff
changeset
|
519 |
d1762728ea4b
[svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff
changeset
|
520 if (mid_istream_read(stream, tmp, 1, 4) != 4 || mid_istream_read(stream, &len, 4, 1) != 1) |
d1762728ea4b
[svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff
changeset
|
521 { |
d1762728ea4b
[svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff
changeset
|
522 DEBUG_MSG("Not a MIDI file!\n"); |
d1762728ea4b
[svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff
changeset
|
523 return 0; |
d1762728ea4b
[svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff
changeset
|
524 } |
d1762728ea4b
[svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff
changeset
|
525 len=SWAPBE32(len); |
d1762728ea4b
[svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff
changeset
|
526 if (memcmp(tmp, "MThd", 4) || len < 6) |
d1762728ea4b
[svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff
changeset
|
527 { |
d1762728ea4b
[svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff
changeset
|
528 DEBUG_MSG("Not a MIDI file!\n"); |
d1762728ea4b
[svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff
changeset
|
529 return 0; |
d1762728ea4b
[svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff
changeset
|
530 } |
d1762728ea4b
[svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff
changeset
|
531 |
d1762728ea4b
[svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff
changeset
|
532 mid_istream_read(stream, &format, 2, 1); |
d1762728ea4b
[svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff
changeset
|
533 mid_istream_read(stream, &tracks, 2, 1); |
d1762728ea4b
[svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff
changeset
|
534 mid_istream_read(stream, &divisions_tmp, 2, 1); |
d1762728ea4b
[svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff
changeset
|
535 format=SWAPBE16(format); |
d1762728ea4b
[svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff
changeset
|
536 tracks=SWAPBE16(tracks); |
d1762728ea4b
[svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff
changeset
|
537 divisions_tmp=SWAPBE16(divisions_tmp); |
d1762728ea4b
[svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff
changeset
|
538 |
d1762728ea4b
[svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff
changeset
|
539 if (divisions_tmp<0) |
d1762728ea4b
[svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff
changeset
|
540 { |
d1762728ea4b
[svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff
changeset
|
541 /* SMPTE time -- totally untested. Got a MIDI file that uses this? */ |
d1762728ea4b
[svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff
changeset
|
542 divisions= |
d1762728ea4b
[svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff
changeset
|
543 (sint32)(-(divisions_tmp/256)) * (sint32)(divisions_tmp & 0xFF); |
d1762728ea4b
[svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff
changeset
|
544 } |
d1762728ea4b
[svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff
changeset
|
545 else divisions=(sint32)(divisions_tmp); |
d1762728ea4b
[svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff
changeset
|
546 |
d1762728ea4b
[svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff
changeset
|
547 if (len > 6) |
d1762728ea4b
[svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff
changeset
|
548 { |
d1762728ea4b
[svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff
changeset
|
549 DEBUG_MSG("MIDI file header size %u bytes", len); |
d1762728ea4b
[svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff
changeset
|
550 mid_istream_skip(stream, len-6); /* skip the excess */ |
d1762728ea4b
[svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff
changeset
|
551 } |
d1762728ea4b
[svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff
changeset
|
552 if (format<0 || format >2) |
d1762728ea4b
[svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff
changeset
|
553 { |
d1762728ea4b
[svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff
changeset
|
554 DEBUG_MSG("Unknown MIDI file format %d\n", format); |
d1762728ea4b
[svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff
changeset
|
555 return 0; |
d1762728ea4b
[svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff
changeset
|
556 } |
d1762728ea4b
[svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff
changeset
|
557 DEBUG_MSG("Format: %d Tracks: %d Divisions: %d\n", |
d1762728ea4b
[svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff
changeset
|
558 format, tracks, divisions); |
d1762728ea4b
[svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff
changeset
|
559 |
d1762728ea4b
[svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff
changeset
|
560 /* Put a do-nothing event first in the list for easier processing */ |
d1762728ea4b
[svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff
changeset
|
561 song->evlist=safe_malloc(sizeof(MidEventList)); |
d1762728ea4b
[svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff
changeset
|
562 song->evlist->event.time=0; |
d1762728ea4b
[svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff
changeset
|
563 song->evlist->event.type=ME_NONE; |
d1762728ea4b
[svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff
changeset
|
564 song->evlist->next=0; |
d1762728ea4b
[svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff
changeset
|
565 song->event_count++; |
d1762728ea4b
[svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff
changeset
|
566 |
d1762728ea4b
[svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff
changeset
|
567 switch(format) |
d1762728ea4b
[svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff
changeset
|
568 { |
d1762728ea4b
[svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff
changeset
|
569 case 0: |
d1762728ea4b
[svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff
changeset
|
570 if (read_track(stream, song, 0)) |
d1762728ea4b
[svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff
changeset
|
571 { |
d1762728ea4b
[svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff
changeset
|
572 free_midi_list(song); |
d1762728ea4b
[svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff
changeset
|
573 return 0; |
d1762728ea4b
[svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff
changeset
|
574 } |
d1762728ea4b
[svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff
changeset
|
575 break; |
d1762728ea4b
[svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff
changeset
|
576 |
d1762728ea4b
[svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff
changeset
|
577 case 1: |
d1762728ea4b
[svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff
changeset
|
578 for (i=0; i<tracks; i++) |
d1762728ea4b
[svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff
changeset
|
579 if (read_track(stream, song, 0)) |
d1762728ea4b
[svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff
changeset
|
580 { |
d1762728ea4b
[svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff
changeset
|
581 free_midi_list(song); |
d1762728ea4b
[svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff
changeset
|
582 return 0; |
d1762728ea4b
[svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff
changeset
|
583 } |
d1762728ea4b
[svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff
changeset
|
584 break; |
d1762728ea4b
[svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff
changeset
|
585 |
d1762728ea4b
[svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff
changeset
|
586 case 2: /* We simply play the tracks sequentially */ |
d1762728ea4b
[svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff
changeset
|
587 for (i=0; i<tracks; i++) |
d1762728ea4b
[svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff
changeset
|
588 if (read_track(stream, song, 1)) |
d1762728ea4b
[svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff
changeset
|
589 { |
d1762728ea4b
[svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff
changeset
|
590 free_midi_list(song); |
d1762728ea4b
[svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff
changeset
|
591 return 0; |
d1762728ea4b
[svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff
changeset
|
592 } |
d1762728ea4b
[svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff
changeset
|
593 break; |
d1762728ea4b
[svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff
changeset
|
594 } |
d1762728ea4b
[svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff
changeset
|
595 return groom_list(song, divisions, count, sp); |
d1762728ea4b
[svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff
changeset
|
596 } |