Mercurial > hg > dmlib
changeset 221:5c36aff80205
Factor note triggering to a separate function.
author | Matti Hamalainen <ccr@tnsp.org> |
---|---|
date | Mon, 08 Oct 2012 00:19:12 +0300 |
parents | b0407a4c0a11 |
children | 63be671823d3 |
files | jssplr.c |
diffstat | 1 files changed, 63 insertions(+), 57 deletions(-) [+] |
line wrap: on
line diff
--- a/jssplr.c Sun Oct 07 23:24:08 2012 +0300 +++ b/jssplr.c Mon Oct 08 00:19:12 2012 +0300 @@ -1086,11 +1086,72 @@ } +static void jmpTriggerNote(JSSPlayer * mp, JSSPlayerChannel *chn, BOOL newExtInstrument) +{ + if (chn->nextInstrument >= 0 && + chn->nextInstrument < mp->module->nextInstruments && + mp->module->extInstruments[chn->nextInstrument] != NULL) + { + chn->extInstrument = mp->module->extInstruments[chn->nextInstrument]; + } + else + { + chn->extInstrument = NULL; + chn->instrument = NULL; + chn->ninstrument = jsetNotSet; + } + + if (chn->extInstrument != NULL) + { + int tmp = chn->extInstrument->sNumForNotes[chn->note]; + + if (tmp >= 0 && tmp < mp->module->ninstruments && + mp->module->instruments[tmp] != NULL) + { + if (chn->ninstrument != tmp) + JMPSETNDFLAGS(cdfNewInstr); + + chn->ninstrument = tmp; + chn->instrument = mp->module->instruments[chn->ninstrument]; + + if (newExtInstrument) + { + chn->volume = chn->instrument->volume; + chn->panning = chn->instrument->EPanning; + JMPSETNDFLAGS(cdfNewPanPos | cdfNewVolume); + } + } + } + + if (chn->instrument != NULL) + { + int tmp; + 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(cdfStop | cdfNewPanPos | cdfNewVolume); + } +} + + static void jmpProcessNewRow(JSSPlayer * mp, int channel) { JSSNote *currNote; BOOL newNote = FALSE, newExtInstrument = FALSE; - int tmp, paramX, paramY; + int paramX, paramY; JSSPlayerChannel *chn = &(mp->channels[channel]); JMPGETNOTE(currNote, mp->row, channel); @@ -1124,64 +1185,9 @@ newExtInstrument = TRUE; } - if (newNote) { - if (chn->nextInstrument >= 0 && - chn->nextInstrument < mp->module->nextInstruments && - mp->module->extInstruments[chn->nextInstrument] != NULL) - { - chn->extInstrument = mp->module->extInstruments[chn->nextInstrument]; - } - else - { - chn->extInstrument = NULL; - chn->instrument = NULL; - chn->ninstrument = jsetNotSet; - } - - if (chn->extInstrument != NULL) - { - tmp = chn->extInstrument->sNumForNotes[chn->note]; - - if (tmp >= 0 && tmp < mp->module->ninstruments && - mp->module->instruments[tmp] != NULL) - { - if (chn->ninstrument != tmp) - JMPSETNDFLAGS(cdfNewInstr); - - chn->ninstrument = tmp; - chn->instrument = mp->module->instruments[chn->ninstrument]; - - if (newExtInstrument) - { - chn->volume = chn->instrument->volume; - chn->panning = chn->instrument->EPanning; - JMPSETNDFLAGS(cdfNewPanPos | 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(cdfStop | cdfNewPanPos | cdfNewVolume); - } + jmpTriggerNote(mp, chn, newExtInstrument); } // Process the volume column