Mercurial > hg > dmlib
changeset 215:5523ea253603
Possibly fix new note/instrument handling logic.
author | Matti Hamalainen <ccr@tnsp.org> |
---|---|
date | Sun, 07 Oct 2012 21:35:51 +0300 |
parents | 71400075a4ca |
children | 247b03797fc9 |
files | jssplr.c |
diffstat | 1 files changed, 57 insertions(+), 35 deletions(-) [+] |
line wrap: on
line diff
--- a/jssplr.c Sun Oct 07 21:35:31 2012 +0300 +++ b/jssplr.c Sun Oct 07 21:35:51 2012 +0300 @@ -1087,7 +1087,7 @@ static void jmpProcessNewRow(JSSPlayer * mp, int channel) { JSSNote *currNote; - BOOL newNote = FALSE; + BOOL newNote = FALSE, newExtInstrument = FALSE; int tmp, paramX, paramY; JSSPlayerChannel *chn = &(mp->channels[channel]); @@ -1099,9 +1099,9 @@ else if (currNote->note >= 0 && currNote->note <= 96) { - // New note was set newNote = TRUE; chn->note = currNote->note; + chn->keyOff = FALSE; } // Check for new instrument @@ -1115,51 +1115,73 @@ chn->keyOff = FALSE; chn->fadeOutVol = mpMaxFadeoutVol; + JMPSETNDFLAGS(cdfNewPanPos | cdfPlay | cdfNewVolume); + // We save the instrument number here for later use - if (currNote->instrument >= 0 && - currNote->instrument < mp->module->nextInstruments) + chn->nextInstrument = currNote->instrument; + newExtInstrument = TRUE; + } + + + if (newNote) + { + if (chn->nextInstrument >= 0 && + chn->nextInstrument < mp->module->nextInstruments && + mp->module->extInstruments[chn->nextInstrument] != NULL) { - chn->nextInstrument = currNote->instrument; - chn->extInstrument = mp->module->extInstruments[currNote->instrument]; + chn->extInstrument = mp->module->extInstruments[chn->nextInstrument]; + } + else + { + chn->extInstrument = NULL; + chn->instrument = NULL; + chn->ninstrument = jsetNotSet; + } - // Get instrument number + if (chn->extInstrument != NULL) + { tmp = chn->extInstrument->sNumForNotes[chn->note]; - if (tmp >= 0 && tmp < mp->module->ninstruments) + if (tmp >= 0 && tmp < mp->module->ninstruments && + mp->module->instruments[tmp] != NULL) { - JSSInstrument *inst = mp->module->instruments[tmp]; - if (tmp != chn->ninstrument) + if (chn->ninstrument != tmp) + JMPSETNDFLAGS(cdfNewInstr); + + chn->ninstrument = tmp; + chn->instrument = mp->module->instruments[chn->ninstrument]; + + if (newExtInstrument) { - JMPSETNDFLAGS(cdfNewInstr); + chn->volume = chn->instrument->volume; + chn->panning = chn->instrument->EPanning; + JMPSETNDFLAGS(cdfNewPanPos | cdfNewVolume); } - chn->ninstrument = tmp; - chn->instrument = inst; - chn->volume = inst->volume; - chn->panning = inst->EPanning; - chn->position = 0; - JMPSETNDFLAGS(cdfPlay | cdfNewPos | cdfNewPanPos); } } - - // XXX possibly wrong? - JMPSETNDFLAGS(cdfNewVolume); + + if (chn->instrument != NULL) + { + JSSInstrument *inst = chn->instrument; + + // Save old pitch for later use + chn->oldPitch = chn->pitch; + + chn->position = 0; + + // Compute new pitch + tmp = dmClamp(chn->note + inst->ERelNote, 0, 119); + chn->pitch = jmpGetPeriodFromNote(mp, tmp, inst->EFineTune); + JMPSETNDFLAGS(cdfNewPitch | cdfPlay | cdfNewPos); + } + else + { + chn->volume = 0; + chn->panning = jchPanMiddle; + JMPSETNDFLAGS(cdfPlay | cdfNewPanPos | cdfNewVolume); + } } - if (newNote && chn->instrument != NULL) - { - JSSInstrument *inst = chn->instrument; - - // Save old pitch for later use - chn->oldPitch = chn->pitch; - - chn->position = 0; - - // Compute new pitch - tmp = dmClamp(chn->note + inst->ERelNote, 0, 119); - chn->pitch = jmpGetPeriodFromNote(mp, tmp, inst->EFineTune); - JMPSETNDFLAGS(cdfNewPitch | cdfPlay | cdfNewPos); - } - // Process the volume column JMPMAKEPARAM(currNote->volume, paramX, paramY);