diff options
| author | Stepan Moskovchenko <stevenm@rockbox.org> | 2007-11-05 05:35:10 +0000 |
|---|---|---|
| committer | Stepan Moskovchenko <stevenm@rockbox.org> | 2007-11-05 05:35:10 +0000 |
| commit | bdfe87c0f11c152e95cb9034d50cd97e94e7be72 (patch) | |
| tree | 27e751300789c9c381891500e2d839433c48c280 /apps/plugins/midi/sequencer.c | |
| parent | 47eb569b624ffa89756b121603ef315a19ffde22 (diff) | |
| download | rockbox-bdfe87c0f11c152e95cb9034d50cd97e94e7be72.zip rockbox-bdfe87c0f11c152e95cb9034d50cd97e94e7be72.tar.gz rockbox-bdfe87c0f11c152e95cb9034d50cd97e94e7be72.tar.bz2 rockbox-bdfe87c0f11c152e95cb9034d50cd97e94e7be72.tar.xz | |
MIDI: Make seeking neater by moving it into another file. Will be more useful later.
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@15467 a1c6a512-1295-4272-9138-f99709370657
Diffstat (limited to 'apps/plugins/midi/sequencer.c')
| -rw-r--r-- | apps/plugins/midi/sequencer.c | 71 |
1 files changed, 63 insertions, 8 deletions
diff --git a/apps/plugins/midi/sequencer.c b/apps/plugins/midi/sequencer.c index b9cc83f..4e6c15f 100644 --- a/apps/plugins/midi/sequencer.c +++ b/apps/plugins/midi/sequencer.c @@ -142,7 +142,6 @@ const uint32_t pitchTbl[] ICONST_ATTR={ static void findDelta(struct SynthObject * so, int ch, int note) { - struct GWaveform * wf = patchSet[chPat[ch]]->waveforms[patchSet[chPat[ch]]->noteTable[note]]; so->wf=wf; unsigned int delta= 0; @@ -152,14 +151,8 @@ static void findDelta(struct SynthObject * so, int ch, int note) so->delta = delta; } -static inline void setPW(int ch, int msb, int lsb) +static inline void computeDeltas(int ch) { - chPW[ch] = msb<<2|lsb>>5; - - int totalBend = (chPW[ch]-256) * chPBDepth[ch]; - chPBNoteOffset[ch] = totalBend >> 8; - chPBFractBend[ch] = pitchTbl[(totalBend & 0xFF) + 256]; - int a=0; for(a = 0; a<MAX_VOICES; a++) { @@ -170,6 +163,17 @@ static inline void setPW(int ch, int msb, int lsb) } } +static inline void setPW(int ch, int msb, int lsb) +{ + chPW[ch] = msb<<2|lsb>>5; + + int totalBend = (chPW[ch]-256) * chPBDepth[ch]; + chPBNoteOffset[ch] = totalBend >> 8; + chPBFractBend[ch] = pitchTbl[(totalBend & 0xFF) + 256]; + + computeDeltas(ch); +} + inline void pressNote(int ch, int note, int vol) { static int lastKill = 0; @@ -376,7 +380,58 @@ void rewindFile(void) } } + int tick(void) ICODE_ATTR; + +void seekBackward(int nsec) +{ + int notesUsed = 0, a=0; + int desiredTime = playingTime - nsec; /* Rewind 5 sec */ + + if(desiredTime < 0) + desiredTime = 0; + + /* Set controllers to default values */ + resetControllers(); + + /* Set the tempo to defalt */ + bpm=mf->div*1000000/tempo; + numberOfSamples=SAMPLE_RATE/bpm; + + + /* Reset the tracks to start */ + rewindFile(); + + /* Reset the time counter to 0 */ + playingTime = 0; + samplesThisSecond = 0; + + /* Quickly run through any initial things that occur before notes */ + do + { + notesUsed = 0; + for(a=0; a<MAX_VOICES; a++) + if(voices[a].isUsed == 1) + notesUsed++; + tick(); + } while(notesUsed == 0); + + /* Reset the time counter to 0 */ + playingTime = 0; + samplesThisSecond = 0; + + /* Tick until goal is reached */ + while(playingTime < desiredTime) + tick(); +} + + +void seekForward(int nsec) +{ + int desiredTime = playingTime + nsec; + while(tick() && playingTime < desiredTime); +} + int tick(void) { if(mf==NULL) |