mirror of
https://github.com/Rockbox/rockbox.git
synced 2025-10-14 02:27:39 -04:00
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
This commit is contained in:
parent
47eb569b62
commit
bdfe87c0f1
3 changed files with 71 additions and 63 deletions
|
@ -108,7 +108,6 @@ int numberOfSamples IBSS_ATTR; /* the number of samples in the current tick */
|
|||
int playingTime IBSS_ATTR; /* How many seconds into the file have we been playing? */
|
||||
int samplesThisSecond IBSS_ATTR; /* How many samples produced during this second so far? */
|
||||
|
||||
|
||||
long bpm IBSS_ATTR;
|
||||
|
||||
int32_t gmbuf[BUF_SIZE*NBUF];
|
||||
|
@ -123,6 +122,7 @@ enum plugin_status plugin_start(struct plugin_api* api, void* parameter)
|
|||
{
|
||||
int retval = 0;
|
||||
|
||||
|
||||
PLUGIN_IRAM_INIT(api)
|
||||
|
||||
rb = api;
|
||||
|
@ -317,66 +317,16 @@ static int midimain(void * filename)
|
|||
/* Rewinding is tricky. Basically start the file over */
|
||||
/* but run through the tracks without the synth running */
|
||||
rb->pcm_play_stop();
|
||||
|
||||
int desiredTime = playingTime - 5; /* 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();
|
||||
|
||||
seekBackward(5);
|
||||
rb->pcm_play_data(&get_more, NULL, 0);
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
case BTN_RIGHT:
|
||||
{
|
||||
/* Skip 5 seconds forward */
|
||||
/* Skipping forward is easy */
|
||||
/* Should skip length be retrieved from the RB settings? */
|
||||
int samp = 5*SAMPLE_RATE;
|
||||
|
||||
/* Have the issue where numberOfSamples changes within this tick */
|
||||
int tickCount = samp / numberOfSamples;
|
||||
int a=0;
|
||||
|
||||
rb->pcm_play_stop();
|
||||
|
||||
for(a=0; a<tickCount; a++)
|
||||
tick();
|
||||
seekForward(5);
|
||||
rb->pcm_play_data(&get_more, NULL, 0);
|
||||
break;
|
||||
}
|
||||
|
|
|
@ -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,6 +151,18 @@ static void findDelta(struct SynthObject * so, int ch, int note)
|
|||
so->delta = delta;
|
||||
}
|
||||
|
||||
static inline void computeDeltas(int ch)
|
||||
{
|
||||
int a=0;
|
||||
for(a = 0; a<MAX_VOICES; a++)
|
||||
{
|
||||
if(voices[a].isUsed==1 && voices[a].ch == ch)
|
||||
{
|
||||
findDelta(&voices[a], ch, voices[a].note);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static inline void setPW(int ch, int msb, int lsb)
|
||||
{
|
||||
chPW[ch] = msb<<2|lsb>>5;
|
||||
|
@ -160,14 +171,7 @@ static inline void setPW(int ch, int msb, int lsb)
|
|||
chPBNoteOffset[ch] = totalBend >> 8;
|
||||
chPBFractBend[ch] = pitchTbl[(totalBend & 0xFF) + 256];
|
||||
|
||||
int a=0;
|
||||
for(a = 0; a<MAX_VOICES; a++)
|
||||
{
|
||||
if(voices[a].isUsed==1 && voices[a].ch == ch)
|
||||
{
|
||||
findDelta(&voices[a], ch, voices[a].note);
|
||||
}
|
||||
}
|
||||
computeDeltas(ch);
|
||||
}
|
||||
|
||||
inline void pressNote(int ch, int note, int vol)
|
||||
|
@ -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)
|
||||
|
|
|
@ -23,5 +23,8 @@ int tick(void);
|
|||
void pressNote(int ch, int note, int vol);
|
||||
void rewindFile(void);
|
||||
|
||||
void seekForward(int nSec);
|
||||
void seekBackward(int nSec);
|
||||
|
||||
extern long tempo;
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue