mirror of
https://github.com/tildearrow/furnace.git
synced 2024-11-05 04:15:05 +00:00
allow sample preview via keyboard
This commit is contained in:
parent
05bbfaced2
commit
46fd774f30
4 changed files with 53 additions and 3 deletions
|
@ -2868,7 +2868,7 @@ int DivEngine::getEffectiveSampleRate(int rate) {
|
|||
return rate;
|
||||
}
|
||||
|
||||
void DivEngine::previewSample(int sample) {
|
||||
void DivEngine::previewSample(int sample, int note) {
|
||||
isBusy.lock();
|
||||
if (sample<0 || sample>=(int)song.sample.size()) {
|
||||
sPreview.sample=-1;
|
||||
|
@ -2877,7 +2877,12 @@ void DivEngine::previewSample(int sample) {
|
|||
return;
|
||||
}
|
||||
blip_clear(samp_bb);
|
||||
blip_set_rates(samp_bb,song.sample[sample]->rate,got.rate);
|
||||
double rate=song.sample[sample]->rate;
|
||||
if (note>=0) {
|
||||
rate=(440.0*pow(2.0,(double)(note+3)/12.0));
|
||||
if (rate<=0) rate=song.sample[sample]->rate;
|
||||
}
|
||||
blip_set_rates(samp_bb,rate,got.rate);
|
||||
samp_prevSample=0;
|
||||
sPreview.pos=0;
|
||||
sPreview.sample=sample;
|
||||
|
@ -2885,6 +2890,13 @@ void DivEngine::previewSample(int sample) {
|
|||
isBusy.unlock();
|
||||
}
|
||||
|
||||
void DivEngine::stopSamplePreview() {
|
||||
isBusy.lock();
|
||||
sPreview.sample=-1;
|
||||
sPreview.pos=0;
|
||||
isBusy.unlock();
|
||||
}
|
||||
|
||||
void DivEngine::previewWave(int wave, int note) {
|
||||
isBusy.lock();
|
||||
if (wave<0 || wave>=(int)song.wave.size()) {
|
||||
|
@ -2907,8 +2919,10 @@ void DivEngine::previewWave(int wave, int note) {
|
|||
}
|
||||
|
||||
void DivEngine::stopWavePreview() {
|
||||
isBusy.lock();
|
||||
sPreview.wave=-1;
|
||||
sPreview.pos=0;
|
||||
isBusy.unlock();
|
||||
}
|
||||
|
||||
String DivEngine::getConfigPath() {
|
||||
|
|
|
@ -263,7 +263,8 @@ class DivEngine {
|
|||
void syncReset();
|
||||
|
||||
// trigger sample preview
|
||||
void previewSample(int sample);
|
||||
void previewSample(int sample, int note=-1);
|
||||
void stopSamplePreview();
|
||||
|
||||
// trigger wave preview
|
||||
void previewWave(int wave, int note);
|
||||
|
|
|
@ -3108,6 +3108,22 @@ void FurnaceGUI::keyDown(SDL_Event& ev) {
|
|||
}
|
||||
}
|
||||
break;
|
||||
case GUI_WINDOW_SAMPLE_EDIT:
|
||||
case GUI_WINDOW_SAMPLE_LIST:
|
||||
if (!ev.key.repeat) {
|
||||
try {
|
||||
int key=noteKeys.at(ev.key.keysym.scancode);
|
||||
int num=12*curOctave+key;
|
||||
if (key!=100) {
|
||||
e->previewSample(curSample,num);
|
||||
samplePreviewOn=true;
|
||||
samplePreviewKey=ev.key.keysym.scancode;
|
||||
samplePreviewNote=num;
|
||||
}
|
||||
} catch (std::out_of_range& e) {
|
||||
}
|
||||
}
|
||||
break;
|
||||
case GUI_WINDOW_WAVE_LIST:
|
||||
case GUI_WINDOW_WAVE_EDIT:
|
||||
if (!ev.key.repeat) {
|
||||
|
@ -3137,6 +3153,12 @@ void FurnaceGUI::keyUp(SDL_Event& ev) {
|
|||
e->stopWavePreview();
|
||||
}
|
||||
}
|
||||
if (samplePreviewOn) {
|
||||
if (ev.key.keysym.scancode==samplePreviewKey) {
|
||||
samplePreviewOn=false;
|
||||
e->stopSamplePreview();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
bool dirExists(String what) {
|
||||
|
@ -3485,6 +3507,12 @@ bool FurnaceGUI::loop() {
|
|||
e->stopWavePreview();
|
||||
}
|
||||
}
|
||||
if (samplePreviewOn) {
|
||||
if (ev.key.keysym.scancode==samplePreviewKey) {
|
||||
samplePreviewOn=false;
|
||||
e->stopSamplePreview();
|
||||
}
|
||||
}
|
||||
}
|
||||
break;
|
||||
case SDL_QUIT:
|
||||
|
@ -4094,6 +4122,9 @@ FurnaceGUI::FurnaceGUI():
|
|||
wavePreviewOn(false),
|
||||
wavePreviewKey((SDL_Scancode)0),
|
||||
wavePreviewNote(0),
|
||||
samplePreviewOn(false),
|
||||
samplePreviewKey((SDL_Scancode)0),
|
||||
samplePreviewNote(0),
|
||||
arpMacroScroll(0),
|
||||
macroDragStart(0,0),
|
||||
macroDragAreaSize(0,0),
|
||||
|
|
|
@ -240,6 +240,10 @@ class FurnaceGUI {
|
|||
SDL_Scancode wavePreviewKey;
|
||||
int wavePreviewNote;
|
||||
|
||||
bool samplePreviewOn;
|
||||
SDL_Scancode samplePreviewKey;
|
||||
int samplePreviewNote;
|
||||
|
||||
std::map<SDL_Scancode,int> noteKeys;
|
||||
std::map<SDL_Keycode,int> valueKeys;
|
||||
|
||||
|
|
Loading…
Reference in a new issue