mirror of
https://github.com/tildearrow/furnace.git
synced 2024-12-31 20:11:29 +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;
|
return rate;
|
||||||
}
|
}
|
||||||
|
|
||||||
void DivEngine::previewSample(int sample) {
|
void DivEngine::previewSample(int sample, int note) {
|
||||||
isBusy.lock();
|
isBusy.lock();
|
||||||
if (sample<0 || sample>=(int)song.sample.size()) {
|
if (sample<0 || sample>=(int)song.sample.size()) {
|
||||||
sPreview.sample=-1;
|
sPreview.sample=-1;
|
||||||
|
@ -2877,7 +2877,12 @@ void DivEngine::previewSample(int sample) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
blip_clear(samp_bb);
|
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;
|
samp_prevSample=0;
|
||||||
sPreview.pos=0;
|
sPreview.pos=0;
|
||||||
sPreview.sample=sample;
|
sPreview.sample=sample;
|
||||||
|
@ -2885,6 +2890,13 @@ void DivEngine::previewSample(int sample) {
|
||||||
isBusy.unlock();
|
isBusy.unlock();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void DivEngine::stopSamplePreview() {
|
||||||
|
isBusy.lock();
|
||||||
|
sPreview.sample=-1;
|
||||||
|
sPreview.pos=0;
|
||||||
|
isBusy.unlock();
|
||||||
|
}
|
||||||
|
|
||||||
void DivEngine::previewWave(int wave, int note) {
|
void DivEngine::previewWave(int wave, int note) {
|
||||||
isBusy.lock();
|
isBusy.lock();
|
||||||
if (wave<0 || wave>=(int)song.wave.size()) {
|
if (wave<0 || wave>=(int)song.wave.size()) {
|
||||||
|
@ -2907,8 +2919,10 @@ void DivEngine::previewWave(int wave, int note) {
|
||||||
}
|
}
|
||||||
|
|
||||||
void DivEngine::stopWavePreview() {
|
void DivEngine::stopWavePreview() {
|
||||||
|
isBusy.lock();
|
||||||
sPreview.wave=-1;
|
sPreview.wave=-1;
|
||||||
sPreview.pos=0;
|
sPreview.pos=0;
|
||||||
|
isBusy.unlock();
|
||||||
}
|
}
|
||||||
|
|
||||||
String DivEngine::getConfigPath() {
|
String DivEngine::getConfigPath() {
|
||||||
|
|
|
@ -263,7 +263,8 @@ class DivEngine {
|
||||||
void syncReset();
|
void syncReset();
|
||||||
|
|
||||||
// trigger sample preview
|
// trigger sample preview
|
||||||
void previewSample(int sample);
|
void previewSample(int sample, int note=-1);
|
||||||
|
void stopSamplePreview();
|
||||||
|
|
||||||
// trigger wave preview
|
// trigger wave preview
|
||||||
void previewWave(int wave, int note);
|
void previewWave(int wave, int note);
|
||||||
|
|
|
@ -3108,6 +3108,22 @@ void FurnaceGUI::keyDown(SDL_Event& ev) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
break;
|
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_LIST:
|
||||||
case GUI_WINDOW_WAVE_EDIT:
|
case GUI_WINDOW_WAVE_EDIT:
|
||||||
if (!ev.key.repeat) {
|
if (!ev.key.repeat) {
|
||||||
|
@ -3137,6 +3153,12 @@ void FurnaceGUI::keyUp(SDL_Event& ev) {
|
||||||
e->stopWavePreview();
|
e->stopWavePreview();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if (samplePreviewOn) {
|
||||||
|
if (ev.key.keysym.scancode==samplePreviewKey) {
|
||||||
|
samplePreviewOn=false;
|
||||||
|
e->stopSamplePreview();
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
bool dirExists(String what) {
|
bool dirExists(String what) {
|
||||||
|
@ -3485,6 +3507,12 @@ bool FurnaceGUI::loop() {
|
||||||
e->stopWavePreview();
|
e->stopWavePreview();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if (samplePreviewOn) {
|
||||||
|
if (ev.key.keysym.scancode==samplePreviewKey) {
|
||||||
|
samplePreviewOn=false;
|
||||||
|
e->stopSamplePreview();
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case SDL_QUIT:
|
case SDL_QUIT:
|
||||||
|
@ -4094,6 +4122,9 @@ FurnaceGUI::FurnaceGUI():
|
||||||
wavePreviewOn(false),
|
wavePreviewOn(false),
|
||||||
wavePreviewKey((SDL_Scancode)0),
|
wavePreviewKey((SDL_Scancode)0),
|
||||||
wavePreviewNote(0),
|
wavePreviewNote(0),
|
||||||
|
samplePreviewOn(false),
|
||||||
|
samplePreviewKey((SDL_Scancode)0),
|
||||||
|
samplePreviewNote(0),
|
||||||
arpMacroScroll(0),
|
arpMacroScroll(0),
|
||||||
macroDragStart(0,0),
|
macroDragStart(0,0),
|
||||||
macroDragAreaSize(0,0),
|
macroDragAreaSize(0,0),
|
||||||
|
|
|
@ -240,6 +240,10 @@ class FurnaceGUI {
|
||||||
SDL_Scancode wavePreviewKey;
|
SDL_Scancode wavePreviewKey;
|
||||||
int wavePreviewNote;
|
int wavePreviewNote;
|
||||||
|
|
||||||
|
bool samplePreviewOn;
|
||||||
|
SDL_Scancode samplePreviewKey;
|
||||||
|
int samplePreviewNote;
|
||||||
|
|
||||||
std::map<SDL_Scancode,int> noteKeys;
|
std::map<SDL_Scancode,int> noteKeys;
|
||||||
std::map<SDL_Keycode,int> valueKeys;
|
std::map<SDL_Keycode,int> valueKeys;
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue