GUI: sample editor preview in selection

This commit is contained in:
tildearrow 2022-05-29 02:13:08 -05:00
parent 957e35af0b
commit 84d4ca63c2
5 changed files with 28 additions and 11 deletions

View File

@ -6,7 +6,6 @@
- the last three compat flags
- add OPL drum instrument type
- Game Boy envelope macro/sequence
- sample editor preview in selection
- rewrite the system name detection function anyway
- unified data view
- volume commands should work on Game Boy

View File

@ -1471,8 +1471,10 @@ int DivEngine::getEffectiveSampleRate(int rate) {
return rate;
}
void DivEngine::previewSample(int sample, int note) {
void DivEngine::previewSample(int sample, int note, int pStart, int pEnd) {
BUSY_BEGIN;
sPreview.pBegin=pStart;
sPreview.pEnd=pEnd;
if (sample<0 || sample>=(int)song.sample.size()) {
sPreview.sample=-1;
sPreview.pos=0;
@ -1488,7 +1490,7 @@ void DivEngine::previewSample(int sample, int note) {
if (rate<100) rate=100;
blip_set_rates(samp_bb,rate,got.rate);
samp_prevSample=0;
sPreview.pos=0;
sPreview.pos=(sPreview.pBegin>=0)?sPreview.pBegin:0;
sPreview.sample=sample;
sPreview.wave=-1;
BUSY_END;

View File

@ -339,10 +339,13 @@ class DivEngine {
int sample;
int wave;
unsigned int pos;
int pBegin, pEnd;
SamplePreview():
sample(-1),
wave(-1),
pos(0) {}
pos(0),
pBegin(-1),
pEnd(-1) {}
} sPreview;
short vibTable[64];
@ -525,7 +528,7 @@ class DivEngine {
void syncReset();
// trigger sample preview
void previewSample(int sample, int note=-1);
void previewSample(int sample, int note=-1, int pStart=-1, int pEnd=-1);
void stopSamplePreview();
// trigger wave preview

View File

@ -1159,7 +1159,7 @@ void DivEngine::nextBuf(float** in, float** out, int inChans, int outChans, unsi
DivSample* s=song.sample[sPreview.sample];
for (size_t i=0; i<prevtotal; i++) {
if (sPreview.pos>=s->samples) {
if (sPreview.pos>=s->samples || (sPreview.pEnd>=0 && (int)sPreview.pos>=sPreview.pEnd)) {
samp_temp=0;
} else {
samp_temp=s->data16[sPreview.pos++];
@ -1167,15 +1167,15 @@ void DivEngine::nextBuf(float** in, float** out, int inChans, int outChans, unsi
blip_add_delta(samp_bb,i,samp_temp-samp_prevSample);
samp_prevSample=samp_temp;
if (sPreview.pos>=s->samples) {
if (s->loopStart>=0 && s->loopStart<(int)s->samples) {
if (sPreview.pos>=s->samples || (sPreview.pEnd>=0 && (int)sPreview.pos>=sPreview.pEnd)) {
if (s->loopStart>=0 && s->loopStart<(int)s->samples && (int)sPreview.pos>=s->loopStart) {
sPreview.pos=s->loopStart;
}
}
}
if (sPreview.pos>=s->samples) {
if (s->loopStart>=0 && s->loopStart<(int)s->samples) {
if (sPreview.pos>=s->samples || (sPreview.pEnd>=0 && (int)sPreview.pos>=sPreview.pEnd)) {
if (s->loopStart>=0 && s->loopStart<(int)s->samples && (int)sPreview.pos>=s->loopStart) {
sPreview.pos=s->loopStart;
} else {
sPreview.sample=-1;

View File

@ -2243,7 +2243,20 @@ int FurnaceGUI::processEvent(SDL_Event* ev) {
int key=noteKeys.at(ev->key.keysym.scancode);
int num=12*curOctave+key;
if (key!=100 && key!=101 && key!=102) {
e->previewSample(curSample,num);
int pStart=-1;
int pEnd=-1;
if (curWindow==GUI_WINDOW_SAMPLE_EDIT) {
if (sampleSelStart!=sampleSelEnd) {
pStart=sampleSelStart;
pEnd=sampleSelEnd;
if (pStart>pEnd) {
pStart^=pEnd;
pEnd^=pStart;
pStart^=pEnd;
}
}
}
e->previewSample(curSample,num,pStart,pEnd);
samplePreviewOn=true;
samplePreviewKey=ev->key.keysym.scancode;
samplePreviewNote=num;