Skip to content

Commit d1790ee

Browse files
committed
add changes for JavaScript port
1 parent 768aa42 commit d1790ee

File tree

4 files changed

+65
-0
lines changed

4 files changed

+65
-0
lines changed

libtimidity/src/instrum.c

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -203,6 +203,19 @@ static void load_instrument(MidSong *song, const char *name,
203203
if (song->ifp == NULL)
204204
{
205205
DEBUG_MSG("Instrument `%s' can't be found.\n", name);
206+
207+
// Added for JavaScript port
208+
if (song->load_request_count < 128) {
209+
for (i=0; i < song->load_request_count; i++) {
210+
if (strcmp(song->load_requests[i], name) == 0) {
211+
return; // Already added this instrument, so return
212+
}
213+
}
214+
// Add instrument to load request list
215+
song->load_requests[song->load_request_count] = strdup(name);
216+
song->load_request_count += 1;
217+
}
218+
206219
return;
207220
}
208221
fp = song->ifp;

libtimidity/src/timidity.c

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -639,6 +639,11 @@ void mid_song_free(MidSong *song)
639639
timi_free(song->meta_data[i]);
640640
}
641641

642+
// Added for JavaScript port
643+
for (i = 0; i < song->load_request_count; i++) {
644+
timi_free(song->load_requests[i]);
645+
}
646+
642647
timi_free(song);
643648
}
644649

@@ -703,3 +708,26 @@ MidSong *mid_song_load_dls(MidIStream *stream, MidDLSPatches *dlspatches, MidSon
703708
{
704709
return NULL;
705710
}
711+
712+
// Added for JavaScript port
713+
extern MidSongOptions *mid_alloc_options(sint32 rate, uint16 format, uint8 channels, uint16 buffer_size)
714+
{
715+
MidSongOptions *o = (MidSongOptions *) timi_calloc(sizeof(MidSongOptions));
716+
o->rate = rate;
717+
o->format = format;
718+
o->channels = channels;
719+
o->buffer_size = buffer_size;
720+
return o;
721+
}
722+
723+
// Added for JavaScript port
724+
extern int mid_get_load_request_count(MidSong *song)
725+
{
726+
return song->load_request_count;
727+
}
728+
729+
// Added for JavaScript port
730+
extern char *mid_get_load_request(MidSong *song, int index)
731+
{
732+
return song->load_requests[index];
733+
}

libtimidity/src/timidity.h

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -265,6 +265,26 @@ extern "C" {
265265
*/
266266
TIMI_EXPORT extern void mid_song_free (MidSong *song);
267267

268+
// Added for JavaScript port
269+
/* Create a MidSongOptions instance on the heap.
270+
* The caller is responsible for freeing it using free() later.
271+
*/
272+
TIMI_EXPORT extern MidSongOptions *mid_alloc_options (sint32 rate,
273+
uint16 format,
274+
uint8 channels,
275+
uint16 buffer_size);
276+
277+
// Added for JavaScript port
278+
/* Return the amount of patch files that the song requires.
279+
*/
280+
TIMI_EXPORT extern int mid_get_load_request_count (MidSong *song);
281+
282+
// Added for JavaScript port
283+
/* Return the name of a patch file that the song requires.
284+
*/
285+
TIMI_EXPORT extern char *mid_get_load_request (MidSong *song,
286+
int index);
287+
268288
#ifdef __cplusplus
269289
}
270290
#endif

libtimidity/src/timidity_internal.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -257,6 +257,10 @@ struct _MidSong
257257
sint32 at;
258258
sint32 groomed_event_count;
259259
char *meta_data[MID_META_MAX];
260+
// Added for JavaScript port
261+
int load_request_count;
262+
// Added for JavaScript port
263+
char *load_requests[128];
260264
};
261265

262266
#endif /* TIMIDITY_INTERNAL_H */

0 commit comments

Comments
 (0)