From 45458667e64624723a1a2046ac8180e1c50c96e4 Mon Sep 17 00:00:00 2001
From: Laine Walker-Avina <lwalkera@ieee.org>
Date: Tue, 3 Nov 2009 03:59:14 -0800
Subject: [PATCH 2/2] SCI sfx: Let each SongIterator remap its own channels
---
engines/sci/sfx/iterator.cpp | 47 +++++++++++++++++------------------
engines/sci/sfx/iterator.h | 2 +
engines/sci/sfx/iterator_internal.h | 4 ---
3 files changed, 25 insertions(+), 28 deletions(-)
diff --git a/engines/sci/sfx/iterator.cpp b/engines/sci/sfx/iterator.cpp
index 69fedbd..4ef4d87 100644
a
|
b
|
int BaseSongIterator::parseMidiCommand(byte *buf, int *result, SongIteratorChann
|
375 | 375 | } else { |
376 | 376 | if ((cmd & 0xf0) == 0x90) /* note on? */ |
377 | 377 | channel->notes_played++; |
| 378 | #if 0 |
| 379 | /* Perform remapping, if neccessary */ |
| 380 | if (cmd != SCI_MIDI_SET_SIGNAL |
| 381 | && cmd < 0xf0) { /* Not a generic command */ |
| 382 | int chan = cmd & 0xf; |
| 383 | int op = cmd & 0xf0; |
378 | 384 | |
| 385 | chan = channel_remap[chan]; |
| 386 | buf[0] = chan | op; |
| 387 | } |
| 388 | #endif |
379 | 389 | /* Process as normal MIDI operation */ |
380 | 390 | return 0; |
381 | 391 | } |
… |
… |
TeeSongIterator::TeeSongIterator(SongIterator *left, SongIterator *right) {
|
1364 | 1374 | _children[TEE_LEFT].it = left; |
1365 | 1375 | _children[TEE_RIGHT].it = right; |
1366 | 1376 | |
1367 | | // By default, don't remap |
1368 | | for (i = 0; i < 16; i++) { |
1369 | | _children[TEE_LEFT].channel_remap[i] = i; |
1370 | | _children[TEE_RIGHT].channel_remap[i] = i; |
1371 | | } |
1372 | | |
1373 | 1377 | /* Default to lhs channels */ |
1374 | 1378 | channel_mask = left->channel_mask; |
1375 | 1379 | for (i = 0; i < 16; i++) |
… |
… |
TeeSongIterator::TeeSongIterator(SongIterator *left, SongIterator *right) {
|
1386 | 1390 | //warning("[songit-tee <%08lx,%08lx>] Could not remap right channel #%d: Out of channels", |
1387 | 1391 | // left->ID, right->ID, i); |
1388 | 1392 | } else { |
1389 | | _children[TEE_RIGHT].channel_remap[i] = firstfree; |
| 1393 | _children[TEE_RIGHT].it->channel_remap[i] = firstfree; |
1390 | 1394 | |
1391 | 1395 | channel_mask |= (1 << firstfree); |
1392 | 1396 | } |
… |
… |
TeeSongIterator::TeeSongIterator(SongIterator *left, SongIterator *right) {
|
1402 | 1406 | for (c = 0 ; c < 2; c++) |
1403 | 1407 | for (i = 0 ; i < 16; i++) |
1404 | 1408 | fprintf(stderr, " map [%d][%d] -> %d\n", |
1405 | | c, i, _children[c].channel_remap[i]); |
| 1409 | c, i, _children[c].it->channel_remap[i]); |
1406 | 1410 | } |
1407 | 1411 | #endif |
1408 | 1412 | |
… |
… |
int TeeSongIterator::nextCommand(byte *buf, int *result) {
|
1514 | 1518 | fprintf(stderr, "\tl:%d / r:%d / chose %d\n", |
1515 | 1519 | _children[TEE_LEFT].retval, _children[TEE_RIGHT].retval, retid); |
1516 | 1520 | #endif |
1517 | | #if 0 |
1518 | | if (_children[retid].retval == 0) { |
1519 | | /* Perform remapping, if neccessary */ |
1520 | | byte *buf = _children[retid].buf; |
1521 | | if (*buf != SCI_MIDI_SET_SIGNAL |
1522 | | && *buf < 0xf0) { /* Not a generic command */ |
1523 | | int chan = *buf & 0xf; |
1524 | | int op = *buf & 0xf0; |
1525 | | |
1526 | | chan = _children[retid].channel_remap[chan]; |
1527 | | |
1528 | | *buf = chan | op; |
1529 | | } |
1530 | | } |
1531 | | #endif |
1532 | | |
1533 | 1521 | /* Adjust delta times */ |
1534 | 1522 | if (_children[retid].retval > 0 |
1535 | 1523 | && _children[1-retid].retval > 0) { |
… |
… |
int songit_next(SongIterator **it, byte *buf, int *result, int mask) {
|
1660 | 1648 | |
1661 | 1649 | SongIterator *old_it = *it; |
1662 | 1650 | *it = new CleanupSongIterator(channel_mask); |
| 1651 | for(uint i = 0; i < MIDI_CHANNELS; i++) |
| 1652 | (*it)->channel_remap[i] = old_it->channel_remap[i]; |
1663 | 1653 | song_iterator_transfer_death_listeners(*it, old_it); |
1664 | 1654 | if (mask & IT_READER_MAY_FREE) |
1665 | 1655 | delete old_it; |
… |
… |
SongIterator::SongIterator() {
|
1691 | 1681 | fade.action = FADE_ACTION_NONE; |
1692 | 1682 | priority = 0; |
1693 | 1683 | memset(_deathListeners, 0, sizeof(_deathListeners)); |
| 1684 | |
| 1685 | // By default, don't remap |
| 1686 | for (uint i = 0; i < 16; i++) { |
| 1687 | channel_remap[i] = i; |
| 1688 | } |
1694 | 1689 | } |
1695 | 1690 | |
1696 | 1691 | SongIterator::SongIterator(const SongIterator &si) { |
… |
… |
SongIterator::SongIterator(const SongIterator &si) {
|
1699 | 1694 | fade = si.fade; |
1700 | 1695 | priority = si.priority; |
1701 | 1696 | memset(_deathListeners, 0, sizeof(_deathListeners)); |
| 1697 | |
| 1698 | for (uint i = 0; i < 16; i++) { |
| 1699 | channel_remap[i] = si.channel_remap[i]; |
| 1700 | } |
1702 | 1701 | } |
1703 | 1702 | |
1704 | 1703 | |
diff --git a/engines/sci/sfx/iterator.h b/engines/sci/sfx/iterator.h
index 4e6df36..d66faa1 100644
a
|
b
|
|
29 | 29 | #define SCI_SFX_SFX_ITERATOR_H |
30 | 30 | |
31 | 31 | #include "sci/sfx/sfx_pcm.h" |
| 32 | #include "sci/sfx/sci_midi.h" |
32 | 33 | |
33 | 34 | namespace Audio { |
34 | 35 | class AudioStream; |
… |
… |
public:
|
156 | 157 | |
157 | 158 | /* See songit_* for the constructor and non-virtual member functions */ |
158 | 159 | |
| 160 | byte channel_remap[MIDI_CHANNELS]; ///< Remapping for channels |
159 | 161 | |
160 | 162 | public: |
161 | 163 | SongIterator(); |
diff --git a/engines/sci/sfx/iterator_internal.h b/engines/sci/sfx/iterator_internal.h
index faf0672..15b15ed 100644
a
|
b
|
public:
|
256 | 256 | byte buf[4]; |
257 | 257 | int result; |
258 | 258 | int retval; |
259 | | |
260 | | /* Remapping for channels */ |
261 | | byte channel_remap[MIDI_CHANNELS]; |
262 | | |
263 | 259 | } _children[2]; |
264 | 260 | |
265 | 261 | public: |