summaryrefslogtreecommitdiff
path: root/apps/plugins/sdl/SDL_mixer/timidity/playmidi.c
diff options
context:
space:
mode:
Diffstat (limited to 'apps/plugins/sdl/SDL_mixer/timidity/playmidi.c')
-rw-r--r--apps/plugins/sdl/SDL_mixer/timidity/playmidi.c116
1 files changed, 58 insertions, 58 deletions
diff --git a/apps/plugins/sdl/SDL_mixer/timidity/playmidi.c b/apps/plugins/sdl/SDL_mixer/timidity/playmidi.c
index 84b18cf5cb..1638732dc5 100644
--- a/apps/plugins/sdl/SDL_mixer/timidity/playmidi.c
+++ b/apps/plugins/sdl/SDL_mixer/timidity/playmidi.c
@@ -6,9 +6,10 @@
6 it under the terms of the Perl Artistic License, available in COPYING. 6 it under the terms of the Perl Artistic License, available in COPYING.
7 */ 7 */
8 8
9#include "config.h"
10
9#include <SDL_rwops.h> 11#include <SDL_rwops.h>
10 12
11#include "config.h"
12#include "common.h" 13#include "common.h"
13#include "instrum.h" 14#include "instrum.h"
14#include "playmidi.h" 15#include "playmidi.h"
@@ -69,14 +70,14 @@ int XG_System_variation_type;
69 70
70 71
71static void adjust_amplification(void) 72static void adjust_amplification(void)
72{ 73{
73 master_volume = (FLOAT_T)(amplification) / (FLOAT_T)100.0; 74 master_volume = (FLOAT_T)(amplification) / (FLOAT_T)100.0;
74 master_volume /= 2; 75 master_volume /= 2;
75} 76}
76 77
77 78
78static void adjust_master_volume(int32 vol) 79static void adjust_master_volume(int32 vol)
79{ 80{
80 master_volume = (double)(vol*amplification) / 1638400.0L; 81 master_volume = (double)(vol*amplification) / 1638400.0L;
81 master_volume /= 2; 82 master_volume /= 2;
82} 83}
@@ -146,7 +147,7 @@ static void select_sample(int v, Instrument *ip)
146 } 147 }
147 148
148 f=voice[v].orig_frequency; 149 f=voice[v].orig_frequency;
149 /* 150 /*
150 No suitable sample found! We'll select the sample whose root 151 No suitable sample found! We'll select the sample whose root
151 frequency is closest to the one we want. (Actually we should 152 frequency is closest to the one we want. (Actually we should
152 probably convert the low, high, and root frequencies to MIDI note 153 probably convert the low, high, and root frequencies to MIDI note
@@ -214,11 +215,11 @@ static void select_stereo_samples(int v, InstrumentLayer *lp)
214 215
215static void recompute_freq(int v) 216static void recompute_freq(int v)
216{ 217{
217 int 218 int
218 sign=(voice[v].sample_increment < 0), /* for bidirectional loops */ 219 sign=(voice[v].sample_increment < 0), /* for bidirectional loops */
219 pb=channel[voice[v].channel].pitchbend; 220 pb=channel[voice[v].channel].pitchbend;
220 double a; 221 double a;
221 222
222 if (!voice[v].sample->sample_rate) 223 if (!voice[v].sample->sample_rate)
223 return; 224 return;
224 225
@@ -262,22 +263,22 @@ static void recompute_freq(int v)
262 (double)(play_mode->rate)), 263 (double)(play_mode->rate)),
263 FRACTION_BITS); 264 FRACTION_BITS);
264 265
265 if (sign) 266 if (sign)
266 a = -a; /* need to preserve the loop direction */ 267 a = -a; /* need to preserve the loop direction */
267 268
268 voice[v].sample_increment = (int32)(a); 269 voice[v].sample_increment = (int32)(a);
269} 270}
270 271
271static int expr_curve[128] = { 272static int expr_curve[128] = {
272 7, 8, 8, 8, 8, 8, 9, 9, 9, 9, 9, 10, 10, 10, 10, 11, 273 7, 8, 8, 8, 8, 8, 9, 9, 9, 9, 9, 10, 10, 10, 10, 11,
273 11, 11, 11, 12, 12, 12, 12, 13, 13, 13, 14, 14, 14, 14, 15, 15, 274 11, 11, 11, 12, 12, 12, 12, 13, 13, 13, 14, 14, 14, 14, 15, 15,
274 15, 16, 16, 17, 17, 17, 18, 18, 19, 19, 19, 20, 20, 21, 21, 22, 275 15, 16, 16, 17, 17, 17, 18, 18, 19, 19, 19, 20, 20, 21, 21, 22,
275 22, 23, 23, 24, 24, 25, 25, 26, 26, 27, 28, 28, 29, 30, 30, 31, 276 22, 23, 23, 24, 24, 25, 25, 26, 26, 27, 28, 28, 29, 30, 30, 31,
276 32, 32, 33, 34, 35, 35, 36, 37, 38, 39, 39, 40, 41, 42, 43, 44, 277 32, 32, 33, 34, 35, 35, 36, 37, 38, 39, 39, 40, 41, 42, 43, 44,
277 45, 46, 47, 48, 49, 50, 51, 53, 54, 55, 56, 57, 59, 60, 61, 63, 278 45, 46, 47, 48, 49, 50, 51, 53, 54, 55, 56, 57, 59, 60, 61, 63,
278 64, 65, 67, 68, 70, 71, 73, 75, 76, 78, 80, 82, 83, 85, 87, 89, 279 64, 65, 67, 68, 70, 71, 73, 75, 76, 78, 80, 82, 83, 85, 87, 89,
279 91, 93, 95, 97, 99, 102, 104, 106, 109, 111, 113, 116, 118, 121, 280 91, 93, 95, 97, 99, 102, 104, 106, 109, 111, 113, 116, 118, 121,
280 124, 127 281 124, 127
281}; 282};
282 283
283static int panf(int pan, int speaker, int separation) 284static int panf(int pan, int speaker, int separation)
@@ -423,7 +424,7 @@ static void recompute_amp(int v)
423/* just a variant of note_on() */ 424/* just a variant of note_on() */
424static int vc_alloc(int j) 425static int vc_alloc(int j)
425{ 426{
426 int i=voices; 427 int i=voices;
427 428
428 while (i--) 429 while (i--)
429 { 430 {
@@ -439,7 +440,7 @@ static void kill_note(int i);
439 440
440static void kill_others(int i) 441static void kill_others(int i)
441{ 442{
442 int j=voices; 443 int j=voices;
443 444
444 if (!voice[i].sample->exclusiveClass) return; 445 if (!voice[i].sample->exclusiveClass) return;
445 446
@@ -769,7 +770,7 @@ static void start_note(MidiEvent *e, int i)
769 ip = lp->instrument; 770 ip = lp->instrument;
770 if (ip->type == INST_GUS && ip->samples != 1) 771 if (ip->type == INST_GUS && ip->samples != 1)
771 { 772 {
772 ctl->cmsg(CMSG_WARNING, VERB_VERBOSE, 773 ctl->cmsg(CMSG_WARNING, VERB_VERBOSE,
773 "Strange: percussion instrument with %d samples!", ip->samples); 774 "Strange: percussion instrument with %d samples!", ip->samples);
774 } 775 }
775 776
@@ -989,14 +990,14 @@ static void kill_note(int i)
989/* Only one instance of a note can be playing on a single channel. */ 990/* Only one instance of a note can be playing on a single channel. */
990static void note_on(MidiEvent *e) 991static void note_on(MidiEvent *e)
991{ 992{
992 int i=voices, lowest=-1; 993 int i=voices, lowest=-1;
993 int32 lv=0x7FFFFFFF, v; 994 int32 lv=0x7FFFFFFF, v;
994 995
995 while (i--) 996 while (i--)
996 { 997 {
997 if (voice[i].status == VOICE_FREE) 998 if (voice[i].status == VOICE_FREE)
998 lowest=i; /* Can't get a lower volume than silence */ 999 lowest=i; /* Can't get a lower volume than silence */
999 else if (voice[i].channel==e->channel && 1000 else if (voice[i].channel==e->channel &&
1000 (voice[i].note==e->a || channel[voice[i].channel].mono)) 1001 (voice[i].note==e->a || channel[voice[i].channel].mono))
1001 kill_note(i); 1002 kill_note(i);
1002 } 1003 }
@@ -1007,7 +1008,7 @@ static void note_on(MidiEvent *e)
1007 start_note(e,lowest); 1008 start_note(e,lowest);
1008 return; 1009 return;
1009 } 1010 }
1010 1011
1011#if 0 1012#if 0
1012 /* Look for the decaying note with the lowest volume */ 1013 /* Look for the decaying note with the lowest volume */
1013 i=voices; 1014 i=voices;
@@ -1136,7 +1137,7 @@ static void all_notes_off(int c)
1136 if (voice[i].status==VOICE_ON && 1137 if (voice[i].status==VOICE_ON &&
1137 voice[i].channel==c) 1138 voice[i].channel==c)
1138 { 1139 {
1139 if (channel[c].sustain) 1140 if (channel[c].sustain)
1140 { 1141 {
1141 voice[i].status=VOICE_SUSTAINED; 1142 voice[i].status=VOICE_SUSTAINED;
1142 ctl->note(i); 1143 ctl->note(i);
@@ -1151,7 +1152,7 @@ static void all_sounds_off(int c)
1151{ 1152{
1152 int i=voices; 1153 int i=voices;
1153 while (i--) 1154 while (i--)
1154 if (voice[i].channel==c && 1155 if (voice[i].channel==c &&
1155 voice[i].status != VOICE_FREE && 1156 voice[i].status != VOICE_FREE &&
1156 voice[i].status != VOICE_DIE) 1157 voice[i].status != VOICE_DIE)
1157 { 1158 {
@@ -1232,29 +1233,29 @@ static void seek_forward(int32 until_time)
1232 current_event->a; 1233 current_event->a;
1233 channel[current_event->channel].pitchfactor=0; 1234 channel[current_event->channel].pitchfactor=0;
1234 break; 1235 break;
1235 1236
1236 case ME_PITCHWHEEL: 1237 case ME_PITCHWHEEL:
1237 channel[current_event->channel].pitchbend= 1238 channel[current_event->channel].pitchbend=
1238 current_event->a + current_event->b * 128; 1239 current_event->a + current_event->b * 128;
1239 channel[current_event->channel].pitchfactor=0; 1240 channel[current_event->channel].pitchfactor=0;
1240 break; 1241 break;
1241 1242
1242 case ME_MAINVOLUME: 1243 case ME_MAINVOLUME:
1243 channel[current_event->channel].volume=current_event->a; 1244 channel[current_event->channel].volume=current_event->a;
1244 break; 1245 break;
1245 1246
1246 case ME_MASTERVOLUME: 1247 case ME_MASTERVOLUME:
1247 adjust_master_volume(current_event->a + (current_event->b <<7)); 1248 adjust_master_volume(current_event->a + (current_event->b <<7));
1248 break; 1249 break;
1249 1250
1250 case ME_PAN: 1251 case ME_PAN:
1251 channel[current_event->channel].panning=current_event->a; 1252 channel[current_event->channel].panning=current_event->a;
1252 break; 1253 break;
1253 1254
1254 case ME_EXPRESSION: 1255 case ME_EXPRESSION:
1255 channel[current_event->channel].expression=current_event->a; 1256 channel[current_event->channel].expression=current_event->a;
1256 break; 1257 break;
1257 1258
1258 case ME_PROGRAM: 1259 case ME_PROGRAM:
1259 /* if (ISDRUMCHANNEL(current_event->channel)) */ 1260 /* if (ISDRUMCHANNEL(current_event->channel)) */
1260 if (channel[current_event->channel].kit) 1261 if (channel[current_event->channel].kit)
@@ -1310,11 +1311,11 @@ static void seek_forward(int32 until_time)
1310 case ME_RESET_CONTROLLERS: 1311 case ME_RESET_CONTROLLERS:
1311 reset_controllers(current_event->channel); 1312 reset_controllers(current_event->channel);
1312 break; 1313 break;
1313 1314
1314 case ME_TONE_BANK: 1315 case ME_TONE_BANK:
1315 channel[current_event->channel].bank=current_event->a; 1316 channel[current_event->channel].bank=current_event->a;
1316 break; 1317 break;
1317 1318
1318 case ME_EOT: 1319 case ME_EOT:
1319 current_sample=current_event->time; 1320 current_sample=current_event->time;
1320 return; 1321 return;
@@ -1336,7 +1337,7 @@ static void skip_to(int32 until_time)
1336 buffered_count=0; 1337 buffered_count=0;
1337 buffer_pointer=common_buffer; 1338 buffer_pointer=common_buffer;
1338 current_event=event_list; 1339 current_event=event_list;
1339 1340
1340 if (until_time) 1341 if (until_time)
1341 seek_forward(until_time); 1342 seek_forward(until_time);
1342 ctl->reset(); 1343 ctl->reset();
@@ -1351,15 +1352,15 @@ static int apply_controls(void)
1351 switch(rc=ctl->read(&val)) 1352 switch(rc=ctl->read(&val))
1352 { 1353 {
1353 case RC_QUIT: /* [] */ 1354 case RC_QUIT: /* [] */
1354 case RC_LOAD_FILE: 1355 case RC_LOAD_FILE:
1355 case RC_NEXT: /* >>| */ 1356 case RC_NEXT: /* >>| */
1356 case RC_REALLY_PREVIOUS: /* |<< */ 1357 case RC_REALLY_PREVIOUS: /* |<< */
1357 return rc; 1358 return rc;
1358 1359
1359 case RC_CHANGE_VOLUME: 1360 case RC_CHANGE_VOLUME:
1360 if (val>0 || amplification > -val) 1361 if (val>0 || amplification > -val)
1361 amplification += val; 1362 amplification += val;
1362 else 1363 else
1363 amplification=0; 1364 amplification=0;
1364 if (amplification > MAX_AMPLIFICATION) 1365 if (amplification > MAX_AMPLIFICATION)
1365 amplification=MAX_AMPLIFICATION; 1366 amplification=MAX_AMPLIFICATION;
@@ -1382,20 +1383,20 @@ static int apply_controls(void)
1382 skip_to(0); 1383 skip_to(0);
1383 did_skip=1; 1384 did_skip=1;
1384 break; 1385 break;
1385 1386
1386 case RC_JUMP: 1387 case RC_JUMP:
1387 if (val >= sample_count) 1388 if (val >= sample_count)
1388 return RC_NEXT; 1389 return RC_NEXT;
1389 skip_to(val); 1390 skip_to(val);
1390 return rc; 1391 return rc;
1391 1392
1392 case RC_FORWARD: /* >> */ 1393 case RC_FORWARD: /* >> */
1393 if (val+current_sample >= sample_count) 1394 if (val+current_sample >= sample_count)
1394 return RC_NEXT; 1395 return RC_NEXT;
1395 skip_to(val+current_sample); 1396 skip_to(val+current_sample);
1396 did_skip=1; 1397 did_skip=1;
1397 break; 1398 break;
1398 1399
1399 case RC_BACK: /* << */ 1400 case RC_BACK: /* << */
1400 if (current_sample > val) 1401 if (current_sample > val)
1401 skip_to(current_sample-val); 1402 skip_to(current_sample-val);
@@ -1405,10 +1406,10 @@ static int apply_controls(void)
1405 break; 1406 break;
1406 } 1407 }
1407 while (rc!= RC_NONE); 1408 while (rc!= RC_NONE);
1408 1409
1409 /* Advertise the skip so that we stop computing the audio buffer */ 1410 /* Advertise the skip so that we stop computing the audio buffer */
1410 if (did_skip) 1411 if (did_skip)
1411 return RC_JUMP; 1412 return RC_JUMP;
1412 else 1413 else
1413 return rc; 1414 return rc;
1414} 1415}
@@ -1466,7 +1467,7 @@ static int compute_data(void *stream, int32 count)
1466 s32tobuf(stream, common_buffer, channels*AUDIO_BUFFER_SIZE); 1467 s32tobuf(stream, common_buffer, channels*AUDIO_BUFFER_SIZE);
1467 buffer_pointer=common_buffer; 1468 buffer_pointer=common_buffer;
1468 buffered_count=0; 1469 buffered_count=0;
1469 1470
1470 ctl->current_time(current_sample); 1471 ctl->current_time(current_sample);
1471 if ((rc=apply_controls())!=RC_NONE) 1472 if ((rc=apply_controls())!=RC_NONE)
1472 return rc; 1473 return rc;
@@ -1485,7 +1486,7 @@ int Timidity_PlaySome(void *stream, int samples)
1485 //printf("Timidity_PlaySome()\n"); 1486 //printf("Timidity_PlaySome()\n");
1486 int rc = RC_NONE; 1487 int rc = RC_NONE;
1487 int32 end_sample; 1488 int32 end_sample;
1488 1489
1489 if ( ! midi_playing ) { 1490 if ( ! midi_playing ) {
1490 return RC_NONE; 1491 return RC_NONE;
1491 } 1492 }
@@ -1504,33 +1505,33 @@ int Timidity_PlaySome(void *stream, int samples)
1504 else 1505 else
1505 note_on(current_event); 1506 note_on(current_event);
1506 break; 1507 break;
1507 1508
1508 case ME_NOTEOFF: 1509 case ME_NOTEOFF:
1509 current_event->a += channel[current_event->channel].transpose; 1510 current_event->a += channel[current_event->channel].transpose;
1510 note_off(current_event); 1511 note_off(current_event);
1511 break; 1512 break;
1512 1513
1513 case ME_KEYPRESSURE: 1514 case ME_KEYPRESSURE:
1514 adjust_pressure(current_event); 1515 adjust_pressure(current_event);
1515 break; 1516 break;
1516 1517
1517 /* Effects affecting a single channel */ 1518 /* Effects affecting a single channel */
1518 1519
1519 case ME_PITCH_SENS: 1520 case ME_PITCH_SENS:
1520 channel[current_event->channel].pitchsens=current_event->a; 1521 channel[current_event->channel].pitchsens=current_event->a;
1521 channel[current_event->channel].pitchfactor=0; 1522 channel[current_event->channel].pitchfactor=0;
1522 break; 1523 break;
1523 1524
1524 case ME_PITCHWHEEL: 1525 case ME_PITCHWHEEL:
1525 channel[current_event->channel].pitchbend= 1526 channel[current_event->channel].pitchbend=
1526 current_event->a + current_event->b * 128; 1527 current_event->a + current_event->b * 128;
1527 channel[current_event->channel].pitchfactor=0; 1528 channel[current_event->channel].pitchfactor=0;
1528 /* Adjust pitch for notes already playing */ 1529 /* Adjust pitch for notes already playing */
1529 adjust_pitchbend(current_event->channel); 1530 adjust_pitchbend(current_event->channel);
1530 ctl->pitch_bend(current_event->channel, 1531 ctl->pitch_bend(current_event->channel,
1531 channel[current_event->channel].pitchbend); 1532 channel[current_event->channel].pitchbend);
1532 break; 1533 break;
1533 1534
1534 case ME_MAINVOLUME: 1535 case ME_MAINVOLUME:
1535 channel[current_event->channel].volume=current_event->a; 1536 channel[current_event->channel].volume=current_event->a;
1536 adjust_volume(current_event->channel); 1537 adjust_volume(current_event->channel);
@@ -1540,7 +1541,7 @@ int Timidity_PlaySome(void *stream, int samples)
1540 case ME_MASTERVOLUME: 1541 case ME_MASTERVOLUME:
1541 adjust_master_volume(current_event->a + (current_event->b <<7)); 1542 adjust_master_volume(current_event->a + (current_event->b <<7));
1542 break; 1543 break;
1543 1544
1544 case ME_REVERBERATION: 1545 case ME_REVERBERATION:
1545 channel[current_event->channel].reverberation=current_event->a; 1546 channel[current_event->channel].reverberation=current_event->a;
1546 break; 1547 break;
@@ -1555,13 +1556,13 @@ int Timidity_PlaySome(void *stream, int samples)
1555 adjust_panning(current_event->channel); 1556 adjust_panning(current_event->channel);
1556 ctl->panning(current_event->channel, current_event->a); 1557 ctl->panning(current_event->channel, current_event->a);
1557 break; 1558 break;
1558 1559
1559 case ME_EXPRESSION: 1560 case ME_EXPRESSION:
1560 channel[current_event->channel].expression=current_event->a; 1561 channel[current_event->channel].expression=current_event->a;
1561 adjust_volume(current_event->channel); 1562 adjust_volume(current_event->channel);
1562 ctl->expression(current_event->channel, current_event->a); 1563 ctl->expression(current_event->channel, current_event->a);
1563 break; 1564 break;
1564 1565
1565 case ME_PROGRAM: 1566 case ME_PROGRAM:
1566 /* if (ISDRUMCHANNEL(current_event->channel)) { */ 1567 /* if (ISDRUMCHANNEL(current_event->channel)) { */
1567 if (channel[current_event->channel].kit) { 1568 if (channel[current_event->channel].kit) {
@@ -1574,23 +1575,23 @@ int Timidity_PlaySome(void *stream, int samples)
1574 } 1575 }
1575 ctl->program(current_event->channel, current_event->a); 1576 ctl->program(current_event->channel, current_event->a);
1576 break; 1577 break;
1577 1578
1578 case ME_SUSTAIN: 1579 case ME_SUSTAIN:
1579 channel[current_event->channel].sustain=current_event->a; 1580 channel[current_event->channel].sustain=current_event->a;
1580 if (!current_event->a) 1581 if (!current_event->a)
1581 drop_sustain(current_event->channel); 1582 drop_sustain(current_event->channel);
1582 ctl->sustain(current_event->channel, current_event->a); 1583 ctl->sustain(current_event->channel, current_event->a);
1583 break; 1584 break;
1584 1585
1585 case ME_RESET_CONTROLLERS: 1586 case ME_RESET_CONTROLLERS:
1586 reset_controllers(current_event->channel); 1587 reset_controllers(current_event->channel);
1587 redraw_controllers(current_event->channel); 1588 redraw_controllers(current_event->channel);
1588 break; 1589 break;
1589 1590
1590 case ME_ALL_NOTES_OFF: 1591 case ME_ALL_NOTES_OFF:
1591 all_notes_off(current_event->channel); 1592 all_notes_off(current_event->channel);
1592 break; 1593 break;
1593 1594
1594 case ME_ALL_SOUNDS_OFF: 1595 case ME_ALL_SOUNDS_OFF:
1595 all_sounds_off(current_event->channel); 1596 all_sounds_off(current_event->channel);
1596 break; 1597 break;
@@ -1725,7 +1726,7 @@ void Timidity_FreeSong(MidiSong *song)
1725{ 1726{
1726 if (free_instruments_afterwards) 1727 if (free_instruments_afterwards)
1727 free_instruments(); 1728 free_instruments();
1728 1729
1729 free(song->events); 1730 free(song->events);
1730 free(song); 1731 free(song);
1731} 1732}
@@ -1743,4 +1744,3 @@ void Timidity_Close(void)
1743 free_instruments(); 1744 free_instruments();
1744 free_pathlist(); 1745 free_pathlist();
1745} 1746}
1746