mirror of
https://github.com/tildearrow/furnace.git
synced 2025-01-06 23:51:21 +00:00
wave synth work
now there is a preview
This commit is contained in:
parent
61916be495
commit
367d14357c
7 changed files with 109 additions and 13 deletions
|
@ -390,6 +390,7 @@ enum DivWaveSynthEffects {
|
|||
DIV_WS_SUBTRACT,
|
||||
DIV_WS_AVERAGE,
|
||||
DIV_WS_PHASE,
|
||||
DIV_WS_CHORUS,
|
||||
|
||||
DIV_WS_SINGLE_MAX,
|
||||
|
||||
|
@ -400,7 +401,9 @@ enum DivWaveSynthEffects {
|
|||
DIV_WS_PING_PONG,
|
||||
DIV_WS_OVERLAY,
|
||||
DIV_WS_NEGATIVE_OVERLAY,
|
||||
DIV_WS_PHASE_DUAL,
|
||||
DIV_WS_SLIDE,
|
||||
DIV_WS_MIX,
|
||||
DIV_WS_PHASE_MOD,
|
||||
|
||||
DIV_WS_DUAL_MAX
|
||||
};
|
||||
|
|
|
@ -84,6 +84,17 @@ bool DivWaveSynth::tick() {
|
|||
}
|
||||
updated=true;
|
||||
break;
|
||||
case DIV_WS_CHORUS:
|
||||
for (int i=0; i<=state.speed; i++) {
|
||||
output[pos]=(wave1[pos]+wave1[(pos+stage)%width])>>1;
|
||||
if (++pos>=width) {
|
||||
pos=0;
|
||||
stage+=state.param1;
|
||||
while (stage>=width) stage-=width;
|
||||
}
|
||||
}
|
||||
updated=true;
|
||||
break;
|
||||
case DIV_WS_WIPE:
|
||||
for (int i=0; i<=state.speed; i++) {
|
||||
output[pos]=(stage&1)?wave1[pos]:wave2[pos];
|
||||
|
@ -145,7 +156,20 @@ bool DivWaveSynth::tick() {
|
|||
}
|
||||
updated=true;
|
||||
break;
|
||||
case DIV_WS_PHASE_DUAL:
|
||||
case DIV_WS_SLIDE:
|
||||
break;
|
||||
case DIV_WS_MIX:
|
||||
for (int i=0; i<=state.speed; i++) {
|
||||
output[pos]=(wave1[pos]+wave2[(pos+stage)%width])>>1;
|
||||
if (++pos>=width) {
|
||||
pos=0;
|
||||
stage+=state.param1;
|
||||
while (stage>=width) stage-=width;
|
||||
}
|
||||
}
|
||||
updated=true;
|
||||
break;
|
||||
case DIV_WS_PHASE_MOD:
|
||||
break;
|
||||
}
|
||||
divCounter=state.rateDivider;
|
||||
|
|
|
@ -248,11 +248,13 @@ void FurnaceGUI::drawInsList() {
|
|||
}
|
||||
if (ImGui::Selectable(name.c_str(),(i==-1)?(curIns<0 || curIns>=e->song.insLen):(curIns==i))) {
|
||||
curIns=i;
|
||||
wavePreviewInit=true;
|
||||
}
|
||||
if (wantScrollList && curIns==i) ImGui::SetScrollHereY();
|
||||
if (settings.insFocusesPattern && patternOpen && ImGui::IsItemActivated()) {
|
||||
nextWindow=GUI_WINDOW_PATTERN;
|
||||
curIns=i;
|
||||
wavePreviewInit=true;
|
||||
}
|
||||
ImGui::PopStyleColor();
|
||||
if (ImGui::IsItemHovered() && i>=0) {
|
||||
|
|
|
@ -119,12 +119,14 @@ void FurnaceGUI::doAction(int what) {
|
|||
if (--curIns<-1) {
|
||||
curIns=-1;
|
||||
}
|
||||
wavePreviewInit=true;
|
||||
wantScrollList=true;
|
||||
break;
|
||||
case GUI_ACTION_INS_DOWN:
|
||||
if (++curIns>=(int)e->song.ins.size()) {
|
||||
curIns=((int)e->song.ins.size())-1;
|
||||
}
|
||||
wavePreviewInit=true;
|
||||
wantScrollList=true;
|
||||
break;
|
||||
case GUI_ACTION_STEP_UP:
|
||||
|
@ -536,6 +538,7 @@ void FurnaceGUI::doAction(int what) {
|
|||
} else {
|
||||
wantScrollList=true;
|
||||
MARK_MODIFIED;
|
||||
wavePreviewInit=true;
|
||||
}
|
||||
break;
|
||||
case GUI_ACTION_INS_LIST_DUPLICATE:
|
||||
|
@ -548,6 +551,7 @@ void FurnaceGUI::doAction(int what) {
|
|||
(*e->song.ins[curIns])=(*e->song.ins[prevIns]);
|
||||
wantScrollList=true;
|
||||
MARK_MODIFIED;
|
||||
wavePreviewInit=true;
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
@ -588,10 +592,12 @@ void FurnaceGUI::doAction(int what) {
|
|||
case GUI_ACTION_INS_LIST_UP:
|
||||
if (--curIns<0) curIns=0;
|
||||
wantScrollList=true;
|
||||
wavePreviewInit=true;
|
||||
break;
|
||||
case GUI_ACTION_INS_LIST_DOWN:
|
||||
if (++curIns>=(int)e->song.ins.size()) curIns=((int)e->song.ins.size())-1;
|
||||
wantScrollList=true;
|
||||
wavePreviewInit=true;
|
||||
break;
|
||||
|
||||
case GUI_ACTION_WAVE_LIST_ADD:
|
||||
|
@ -1221,6 +1227,7 @@ void FurnaceGUI::doAction(int what) {
|
|||
e->song.ins[curIns]->amiga.initSample=curSample;
|
||||
nextWindow=GUI_WINDOW_INS_EDIT;
|
||||
MARK_MODIFIED;
|
||||
wavePreviewInit=true;
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
|
|
@ -79,6 +79,7 @@ bool Particle::update(float frameTime) {
|
|||
|
||||
void FurnaceGUI::bindEngine(DivEngine* eng) {
|
||||
e=eng;
|
||||
wavePreview.setEngine(e);
|
||||
}
|
||||
|
||||
const char* FurnaceGUI::noteName(short note, short octave) {
|
||||
|
@ -924,6 +925,7 @@ void FurnaceGUI::valueInput(int num, bool direct, int target) {
|
|||
}
|
||||
if (settings.absorbInsInput) {
|
||||
curIns=pat->data[cursor.y][target];
|
||||
wavePreviewInit=true;
|
||||
}
|
||||
makeUndo(GUI_UNDO_PATTERN_EDIT);
|
||||
if (direct) {
|
||||
|
@ -2650,6 +2652,7 @@ bool FurnaceGUI::loop() {
|
|||
if (midiMap.programChange) {
|
||||
curIns=msg.data[0];
|
||||
if (curIns>=(int)e->song.ins.size()) curIns=e->song.ins.size()-1;
|
||||
wavePreviewInit=true;
|
||||
}
|
||||
break;
|
||||
case TA_MIDI_CONTROL:
|
||||
|
@ -3087,6 +3090,7 @@ bool FurnaceGUI::loop() {
|
|||
}
|
||||
} else {
|
||||
curIns=prevIns;
|
||||
wavePreviewInit=true;
|
||||
}
|
||||
prevIns=-3;
|
||||
}
|
||||
|
@ -4225,6 +4229,9 @@ FurnaceGUI::FurnaceGUI():
|
|||
latchVol(-1),
|
||||
latchEffect(-1),
|
||||
latchEffectVal(-1),
|
||||
wavePreviewLen(32),
|
||||
wavePreviewHeight(255),
|
||||
wavePreviewInit(true),
|
||||
wavePreviewOn(false),
|
||||
wavePreviewKey((SDL_Scancode)0),
|
||||
wavePreviewNote(0),
|
||||
|
|
|
@ -21,6 +21,7 @@
|
|||
#define _FUR_GUI_H
|
||||
|
||||
#include "../engine/engine.h"
|
||||
#include "../engine/waveSynth.h"
|
||||
#include "imgui.h"
|
||||
#include "imgui_impl_sdl.h"
|
||||
#include "imgui_impl_sdlrenderer.h"
|
||||
|
@ -1073,6 +1074,10 @@ class FurnaceGUI {
|
|||
OperationMask opMaskRandomize, opMaskFlip, opMaskCollapseExpand;
|
||||
short latchNote, latchIns, latchVol, latchEffect, latchEffectVal;
|
||||
|
||||
DivWaveSynth wavePreview;
|
||||
int wavePreviewLen, wavePreviewHeight;
|
||||
bool wavePreviewInit;
|
||||
|
||||
// bit 31: ctrl
|
||||
// bit 30: reserved for SDL scancode mask
|
||||
// bit 29: shift
|
||||
|
|
|
@ -191,23 +191,26 @@ const int orderedOps[4]={
|
|||
0, 2, 1, 3
|
||||
};
|
||||
|
||||
const char* singleWSEffects[6]={
|
||||
const char* singleWSEffects[7]={
|
||||
"None",
|
||||
"Invert",
|
||||
"Add",
|
||||
"Subtract",
|
||||
"Average",
|
||||
"Phase",
|
||||
"Chorus"
|
||||
};
|
||||
|
||||
const char* dualWSEffects[7]={
|
||||
const char* dualWSEffects[9]={
|
||||
"None (dual)",
|
||||
"Wipe",
|
||||
"Fade",
|
||||
"Wipe (ping-pong)",
|
||||
"Fade (ping-pong)",
|
||||
"Overlay",
|
||||
"Negative Overlay",
|
||||
"Phase (dual)",
|
||||
"Slide",
|
||||
"Mix Chorus",
|
||||
"Phase Modulation"
|
||||
};
|
||||
|
||||
const char* macroAbsoluteMode="Fixed";
|
||||
|
@ -1369,6 +1372,7 @@ void FurnaceGUI::drawInsEdit() {
|
|||
if (ImGui::Selectable(name.c_str(),curIns==(int)i)) {
|
||||
curIns=i;
|
||||
ins=e->song.ins[curIns];
|
||||
wavePreviewInit=true;
|
||||
}
|
||||
}
|
||||
ImGui::EndCombo();
|
||||
|
@ -2760,16 +2764,20 @@ void FurnaceGUI::drawInsEdit() {
|
|||
ins->type==DIV_INS_SCC ||
|
||||
ins->type==DIV_INS_NAMCO) {
|
||||
if (ImGui::BeginTabItem("Wavetable")) {
|
||||
ImGui::Checkbox("Enable synthesizer",&ins->ws.enabled);
|
||||
if (ImGui::Checkbox("Enable synthesizer",&ins->ws.enabled)) {
|
||||
wavePreviewInit=true;
|
||||
}
|
||||
ImGui::SameLine();
|
||||
ImGui::SetNextItemWidth(ImGui::GetContentRegionAvail().x);
|
||||
if (ins->ws.effect&0x80) {
|
||||
if ((ins->ws.effect&0x7f)>=DIV_WS_DUAL_MAX) {
|
||||
ins->ws.effect=0;
|
||||
wavePreviewInit=true;
|
||||
}
|
||||
} else {
|
||||
if ((ins->ws.effect&0x7f)>=DIV_WS_SINGLE_MAX) {
|
||||
ins->ws.effect=0;
|
||||
wavePreviewInit=true;
|
||||
}
|
||||
}
|
||||
if (ImGui::BeginCombo("##WSEffect",(ins->ws.effect&0x80)?dualWSEffects[ins->ws.effect&0x7f]:singleWSEffects[ins->ws.effect&0x7f])) {
|
||||
|
@ -2778,6 +2786,7 @@ void FurnaceGUI::drawInsEdit() {
|
|||
for (int i=0; i<DIV_WS_SINGLE_MAX; i++) {
|
||||
if (ImGui::Selectable(singleWSEffects[i])) {
|
||||
ins->ws.effect=i;
|
||||
wavePreviewInit=true;
|
||||
}
|
||||
}
|
||||
ImGui::Unindent();
|
||||
|
@ -2786,16 +2795,22 @@ void FurnaceGUI::drawInsEdit() {
|
|||
for (int i=129; i<DIV_WS_DUAL_MAX; i++) {
|
||||
if (ImGui::Selectable(dualWSEffects[i-128])) {
|
||||
ins->ws.effect=i;
|
||||
wavePreviewInit=true;
|
||||
}
|
||||
}
|
||||
ImGui::Unindent();
|
||||
ImGui::EndCombo();
|
||||
}
|
||||
if (ImGui::BeginTable("WSPreview",2)) {
|
||||
if (ImGui::BeginTable("WSPreview",3)) {
|
||||
DivWavetable* wave1=e->getWave(ins->ws.wave1);
|
||||
DivWavetable* wave2=e->getWave(ins->ws.wave2);
|
||||
if (wavePreviewInit) {
|
||||
wavePreview.init(ins,wavePreviewLen,wavePreviewHeight,true);
|
||||
wavePreviewInit=false;
|
||||
}
|
||||
float wavePreview1[256];
|
||||
float wavePreview2[256];
|
||||
float wavePreview3[256];
|
||||
for (int i=0; i<wave1->len; i++) {
|
||||
if (wave1->data[i]>wave1->max) {
|
||||
wavePreview1[i]=wave1->max;
|
||||
|
@ -2810,14 +2825,25 @@ void FurnaceGUI::drawInsEdit() {
|
|||
wavePreview2[i]=wave2->data[i];
|
||||
}
|
||||
}
|
||||
if (ins->ws.enabled) wavePreview.tick();
|
||||
for (int i=0; i<wavePreviewLen; i++) {
|
||||
if (wave2->data[i]>wavePreviewHeight) {
|
||||
wavePreview3[i]=wavePreviewHeight;
|
||||
} else {
|
||||
wavePreview3[i]=wavePreview.output[i];
|
||||
}
|
||||
}
|
||||
|
||||
ImGui::TableNextRow();
|
||||
ImGui::TableNextColumn();
|
||||
ImVec2 size1=ImVec2(ImGui::GetContentRegionAvail().x,64.0f*dpiScale);
|
||||
PlotNoLerp("##WaveformP1",wavePreview1,wave1->len+1,0,NULL,0,wave1->max,size1);
|
||||
PlotNoLerp("##WaveformP1",wavePreview1,wave1->len+1,0,"Wave 1",0,wave1->max,size1);
|
||||
ImGui::TableNextColumn();
|
||||
ImVec2 size2=ImVec2(ImGui::GetContentRegionAvail().x,64.0f*dpiScale);
|
||||
PlotNoLerp("##WaveformP2",wavePreview2,wave2->len+1,0,NULL,0,wave2->max,size2);
|
||||
PlotNoLerp("##WaveformP2",wavePreview2,wave2->len+1,0,"Wave 2",0,wave2->max,size2);
|
||||
ImGui::TableNextColumn();
|
||||
ImVec2 size3=ImVec2(ImGui::GetContentRegionAvail().x,64.0f*dpiScale);
|
||||
PlotNoLerp("##WaveformP3",wavePreview3,wavePreviewLen,0,"Result",0,wavePreviewHeight,size3);
|
||||
|
||||
ImGui::TableNextRow();
|
||||
ImGui::TableNextColumn();
|
||||
|
@ -2827,6 +2853,7 @@ void FurnaceGUI::drawInsEdit() {
|
|||
if (ImGui::InputInt("##SelWave1",&ins->ws.wave1,1,4)) {
|
||||
if (ins->ws.wave1<0) ins->ws.wave1=0;
|
||||
if (ins->ws.wave1>=(int)e->song.wave.size()) ins->ws.wave1=e->song.wave.size()-1;
|
||||
wavePreviewInit=true;
|
||||
}
|
||||
ImGui::TableNextColumn();
|
||||
ImGui::Text("Wave 2");
|
||||
|
@ -2835,21 +2862,42 @@ void FurnaceGUI::drawInsEdit() {
|
|||
if (ImGui::InputInt("##SelWave2",&ins->ws.wave2,1,4)) {
|
||||
if (ins->ws.wave2<0) ins->ws.wave2=0;
|
||||
if (ins->ws.wave2>=(int)e->song.wave.size()) ins->ws.wave2=e->song.wave.size()-1;
|
||||
wavePreviewInit=true;
|
||||
}
|
||||
ImGui::TableNextColumn();
|
||||
if (ImGui::Button(ICON_FA_REPEAT "##WSRestart")) {
|
||||
wavePreviewInit=true;
|
||||
}
|
||||
ImGui::SameLine();
|
||||
ImGui::Text("Preview Width");
|
||||
ImGui::SameLine();
|
||||
ImGui::SetNextItemWidth(ImGui::GetContentRegionAvail().x);
|
||||
if (ImGui::InputInt("##SelWave3",&wavePreviewLen,1,4)) {
|
||||
if (wavePreviewLen<1) wavePreviewLen=1;
|
||||
if (wavePreviewLen>256) wavePreviewLen=256;
|
||||
wavePreviewInit=true;
|
||||
}
|
||||
ImGui::EndTable();
|
||||
}
|
||||
|
||||
ImGui::InputScalar("Update Rate",ImGuiDataType_U8,&ins->ws.rateDivider,&_ONE,&_SEVEN);
|
||||
if (ImGui::InputScalar("Update Rate",ImGuiDataType_U8,&ins->ws.rateDivider,&_ONE,&_SEVEN)) {
|
||||
wavePreviewInit=true;
|
||||
}
|
||||
int speed=ins->ws.speed+1;
|
||||
if (ImGui::InputInt("Speed",&speed,1,16)) {
|
||||
if (speed<1) speed=1;
|
||||
if (speed>256) speed=256;
|
||||
ins->ws.speed=speed-1;
|
||||
wavePreviewInit=true;
|
||||
}
|
||||
|
||||
ImGui::InputScalar("Amount",ImGuiDataType_U8,&ins->ws.param1,&_ONE,&_SEVEN);
|
||||
if (ImGui::InputScalar("Amount",ImGuiDataType_U8,&ins->ws.param1,&_ONE,&_SEVEN)) {
|
||||
wavePreviewInit=true;
|
||||
}
|
||||
|
||||
ImGui::Checkbox("Global",&ins->ws.global);
|
||||
if (ImGui::Checkbox("Global",&ins->ws.global)) {
|
||||
wavePreviewInit=true;
|
||||
}
|
||||
|
||||
ImGui::EndTabItem();
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue