summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorStepan Moskovchenko <stevenm@rockbox.org>2007-11-05 05:35:10 +0000
committerStepan Moskovchenko <stevenm@rockbox.org>2007-11-05 05:35:10 +0000
commitbdfe87c0f11c152e95cb9034d50cd97e94e7be72 (patch)
tree27e751300789c9c381891500e2d839433c48c280
parent47eb569b624ffa89756b121603ef315a19ffde22 (diff)
downloadrockbox-bdfe87c0f11c152e95cb9034d50cd97e94e7be72.tar.gz
rockbox-bdfe87c0f11c152e95cb9034d50cd97e94e7be72.zip
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
-rw-r--r--apps/plugins/midi/midiplay.c58
-rw-r--r--apps/plugins/midi/sequencer.c71
-rw-r--r--apps/plugins/midi/sequencer.h3
3 files changed, 70 insertions, 62 deletions
diff --git a/apps/plugins/midi/midiplay.c b/apps/plugins/midi/midiplay.c
index c69c8b1ad6..cc8746308f 100644
--- a/apps/plugins/midi/midiplay.c
+++ b/apps/plugins/midi/midiplay.c
@@ -108,7 +108,6 @@ int numberOfSamples IBSS_ATTR; /* the number of samples in the current tick */
108int playingTime IBSS_ATTR; /* How many seconds into the file have we been playing? */ 108int playingTime IBSS_ATTR; /* How many seconds into the file have we been playing? */
109int samplesThisSecond IBSS_ATTR; /* How many samples produced during this second so far? */ 109int samplesThisSecond IBSS_ATTR; /* How many samples produced during this second so far? */
110 110
111
112long bpm IBSS_ATTR; 111long bpm IBSS_ATTR;
113 112
114int32_t gmbuf[BUF_SIZE*NBUF]; 113int32_t gmbuf[BUF_SIZE*NBUF];
@@ -123,6 +122,7 @@ enum plugin_status plugin_start(struct plugin_api* api, void* parameter)
123{ 122{
124 int retval = 0; 123 int retval = 0;
125 124
125
126 PLUGIN_IRAM_INIT(api) 126 PLUGIN_IRAM_INIT(api)
127 127
128 rb = api; 128 rb = api;
@@ -317,66 +317,16 @@ static int midimain(void * filename)
317 /* Rewinding is tricky. Basically start the file over */ 317 /* Rewinding is tricky. Basically start the file over */
318 /* but run through the tracks without the synth running */ 318 /* but run through the tracks without the synth running */
319 rb->pcm_play_stop(); 319 rb->pcm_play_stop();
320 320 seekBackward(5);
321 int desiredTime = playingTime - 5; /* Rewind 5 sec */
322
323 if(desiredTime < 0)
324 desiredTime = 0;
325
326 /* Set controllers to default values */
327 resetControllers();
328
329 /* Set the tempo to defalt */
330 bpm=mf->div*1000000/tempo;
331 numberOfSamples=SAMPLE_RATE/bpm;
332
333
334 /* Reset the tracks to start */
335 rewindFile();
336
337 /* Reset the time counter to 0 */
338 playingTime = 0;
339 samplesThisSecond = 0;
340
341 /* Quickly run through any initial things that occur before notes */
342 do
343 {
344 notesUsed = 0;
345 for(a=0; a<MAX_VOICES; a++)
346 if(voices[a].isUsed == 1)
347 notesUsed++;
348 tick();
349 } while(notesUsed == 0);
350
351 /* Reset the time counter to 0 */
352 playingTime = 0;
353 samplesThisSecond = 0;
354
355
356
357 /* Tick until goal is reached */
358 while(playingTime < desiredTime)
359 tick();
360
361 rb->pcm_play_data(&get_more, NULL, 0); 321 rb->pcm_play_data(&get_more, NULL, 0);
322
362 break; 323 break;
363 } 324 }
364 325
365 case BTN_RIGHT: 326 case BTN_RIGHT:
366 { 327 {
367 /* Skip 5 seconds forward */
368 /* Skipping forward is easy */
369 /* Should skip length be retrieved from the RB settings? */
370 int samp = 5*SAMPLE_RATE;
371
372 /* Have the issue where numberOfSamples changes within this tick */
373 int tickCount = samp / numberOfSamples;
374 int a=0;
375
376 rb->pcm_play_stop(); 328 rb->pcm_play_stop();
377 329 seekForward(5);
378 for(a=0; a<tickCount; a++)
379 tick();
380 rb->pcm_play_data(&get_more, NULL, 0); 330 rb->pcm_play_data(&get_more, NULL, 0);
381 break; 331 break;
382 } 332 }
diff --git a/apps/plugins/midi/sequencer.c b/apps/plugins/midi/sequencer.c
index b9cc83f9ad..4e6c15fba6 100644
--- a/apps/plugins/midi/sequencer.c
+++ b/apps/plugins/midi/sequencer.c
@@ -142,7 +142,6 @@ const uint32_t pitchTbl[] ICONST_ATTR={
142 142
143static void findDelta(struct SynthObject * so, int ch, int note) 143static void findDelta(struct SynthObject * so, int ch, int note)
144{ 144{
145
146 struct GWaveform * wf = patchSet[chPat[ch]]->waveforms[patchSet[chPat[ch]]->noteTable[note]]; 145 struct GWaveform * wf = patchSet[chPat[ch]]->waveforms[patchSet[chPat[ch]]->noteTable[note]];
147 so->wf=wf; 146 so->wf=wf;
148 unsigned int delta= 0; 147 unsigned int delta= 0;
@@ -152,14 +151,8 @@ static void findDelta(struct SynthObject * so, int ch, int note)
152 so->delta = delta; 151 so->delta = delta;
153} 152}
154 153
155static inline void setPW(int ch, int msb, int lsb) 154static inline void computeDeltas(int ch)
156{ 155{
157 chPW[ch] = msb<<2|lsb>>5;
158
159 int totalBend = (chPW[ch]-256) * chPBDepth[ch];
160 chPBNoteOffset[ch] = totalBend >> 8;
161 chPBFractBend[ch] = pitchTbl[(totalBend & 0xFF) + 256];
162
163 int a=0; 156 int a=0;
164 for(a = 0; a<MAX_VOICES; a++) 157 for(a = 0; a<MAX_VOICES; a++)
165 { 158 {
@@ -170,6 +163,17 @@ static inline void setPW(int ch, int msb, int lsb)
170 } 163 }
171} 164}
172 165
166static inline void setPW(int ch, int msb, int lsb)
167{
168 chPW[ch] = msb<<2|lsb>>5;
169
170 int totalBend = (chPW[ch]-256) * chPBDepth[ch];
171 chPBNoteOffset[ch] = totalBend >> 8;
172 chPBFractBend[ch] = pitchTbl[(totalBend & 0xFF) + 256];
173
174 computeDeltas(ch);
175}
176
173inline void pressNote(int ch, int note, int vol) 177inline void pressNote(int ch, int note, int vol)
174{ 178{
175 static int lastKill = 0; 179 static int lastKill = 0;
@@ -376,7 +380,58 @@ void rewindFile(void)
376 } 380 }
377} 381}
378 382
383
379int tick(void) ICODE_ATTR; 384int tick(void) ICODE_ATTR;
385
386void seekBackward(int nsec)
387{
388 int notesUsed = 0, a=0;
389 int desiredTime = playingTime - nsec; /* Rewind 5 sec */
390
391 if(desiredTime < 0)
392 desiredTime = 0;
393
394 /* Set controllers to default values */
395 resetControllers();
396
397 /* Set the tempo to defalt */
398 bpm=mf->div*1000000/tempo;
399 numberOfSamples=SAMPLE_RATE/bpm;
400
401
402 /* Reset the tracks to start */
403 rewindFile();
404
405 /* Reset the time counter to 0 */
406 playingTime = 0;
407 samplesThisSecond = 0;
408
409 /* Quickly run through any initial things that occur before notes */
410 do
411 {
412 notesUsed = 0;
413 for(a=0; a<MAX_VOICES; a++)
414 if(voices[a].isUsed == 1)
415 notesUsed++;
416 tick();
417 } while(notesUsed == 0);
418
419 /* Reset the time counter to 0 */
420 playingTime = 0;
421 samplesThisSecond = 0;
422
423 /* Tick until goal is reached */
424 while(playingTime < desiredTime)
425 tick();
426}
427
428
429void seekForward(int nsec)
430{
431 int desiredTime = playingTime + nsec;
432 while(tick() && playingTime < desiredTime);
433}
434
380int tick(void) 435int tick(void)
381{ 436{
382 if(mf==NULL) 437 if(mf==NULL)
diff --git a/apps/plugins/midi/sequencer.h b/apps/plugins/midi/sequencer.h
index 8cb190442c..0c90d70604 100644
--- a/apps/plugins/midi/sequencer.h
+++ b/apps/plugins/midi/sequencer.h
@@ -23,5 +23,8 @@ int tick(void);
23void pressNote(int ch, int note, int vol); 23void pressNote(int ch, int note, int vol);
24void rewindFile(void); 24void rewindFile(void);
25 25
26void seekForward(int nSec);
27void seekBackward(int nSec);
28
26extern long tempo; 29extern long tempo;
27 30