Merge branch 'master' of https://github.com/tildearrow/furnace into snes

This commit is contained in:
Natt Akuma 2022-06-10 23:00:03 +07:00
commit 47768edd20
11 changed files with 275 additions and 23 deletions

View file

@ -21,6 +21,26 @@
#include "../ta-log.h"
#include "taAudio.h"
String sanitizePortName(const String& name) {
#if defined(_WIN32)
// remove port number
size_t namePos=name.rfind(' ');
if (namePos!=String::npos) {
return name.substr(0,namePos);
}
return name;
#elif defined(__linux__)
// remove port location
size_t namePos=name.rfind(' ');
if (namePos!=String::npos) {
return name.substr(0,namePos);
}
return name;
#else
return name;
#endif
}
// --- IN ---
bool TAMidiInRtMidi::gather() {
@ -56,7 +76,7 @@ std::vector<String> TAMidiInRtMidi::listDevices() {
unsigned int count=port->getPortCount();
logD("got port count.");
for (unsigned int i=0; i<count; i++) {
String name=port->getPortName(i);
String name=sanitizePortName(port->getPortName(i));
if (name!="") ret.push_back(name);
}
} catch (RtMidiError& e) {
@ -75,8 +95,12 @@ bool TAMidiInRtMidi::openDevice(String name) {
try {
bool portOpen=false;
unsigned int count=port->getPortCount();
logD("finding port %s...",name);
for (unsigned int i=0; i<count; i++) {
if (port->getPortName(i)==name) {
String portName=sanitizePortName(port->getPortName(i));
logV("- %d: %s",i,portName);
if (portName==name) {
logD("opening port %d...",i);
port->openPort(i);
portOpen=true;
break;
@ -184,8 +208,12 @@ bool TAMidiOutRtMidi::openDevice(String name) {
try {
bool portOpen=false;
unsigned int count=port->getPortCount();
logD("finding port %s...",name);
for (unsigned int i=0; i<count; i++) {
if (port->getPortName(i)==name) {
String portName=sanitizePortName(port->getPortName(i));
logV("- %d: %s",i,portName);
if (portName==name) {
logD("opening port %d...",i);
port->openPort(i);
portOpen=true;
break;
@ -222,7 +250,7 @@ std::vector<String> TAMidiOutRtMidi::listDevices() {
try {
unsigned int count=port->getPortCount();
for (unsigned int i=0; i<count; i++) {
String name=port->getPortName(i);
String name=sanitizePortName(port->getPortName(i));
if (name!="") ret.push_back(name);
}
} catch (RtMidiError& e) {
@ -248,4 +276,4 @@ bool TAMidiOutRtMidi::quit() {
port=NULL;
}
return true;
}
}

View file

@ -306,7 +306,7 @@ void DivPlatformBubSysWSG::reset() {
for (int i=0; i<2; i++) {
chan[i]=DivPlatformBubSysWSG::Channel();
chan[i].std.setEngine(parent);
chan[i].ws.setEngine(parent);
chan[i].ws.setEngine(parent,8);
chan[i].ws.init(NULL,32,15,false);
}
if (dumpWrites) {

View file

@ -332,7 +332,7 @@ void DivPlatformSCC::reset() {
for (int i=0; i<5; i++) {
chan[i]=DivPlatformSCC::Channel();
chan[i].std.setEngine(parent);
chan[i].ws.setEngine(parent);
chan[i].ws.setEngine(parent,128);
chan[i].ws.init(NULL,32,255,false);
chan[i].vol=15;
chan[i].outVol=15;

View file

@ -243,8 +243,13 @@ void DivWaveSynth::changeWave2(int num) {
first=true;
}
void DivWaveSynth::setEngine(DivEngine* engine) {
void DivWaveSynth::setEngine(DivEngine* engine, int waveFloor) {
e=engine;
memset(wave1,waveFloor,256);
memset(wave2,waveFloor,256);
for (int i=0; i<256; i++) {
output[i]=waveFloor;
}
}
void DivWaveSynth::init(DivInstrument* which, int w, int h, bool insChanged) {

View file

@ -70,7 +70,7 @@ class DivWaveSynth {
* @param insChanged whether the instrument has changed.
*/
void init(DivInstrument* which, int width, int height, bool insChanged=false);
void setEngine(DivEngine* engine);
void setEngine(DivEngine* engine, int waveFloor=0);
DivWaveSynth():
e(NULL),
pos(0),

View file

@ -3,6 +3,7 @@
#include "IconsFontAwesome4.h"
#include "misc/cpp/imgui_stdlib.h"
#include "guiConst.h"
#include "intConst.h"
const char* queryModes[GUI_QUERY_MAX]={
"ignore",
@ -17,6 +18,7 @@ const char* queryModes[GUI_QUERY_MAX]={
const char* queryReplaceModes[GUI_QUERY_REPLACE_MAX]={
"set",
"add",
"add (overflow)",
"clear"
};
@ -289,7 +291,11 @@ void FurnaceGUI::drawFindReplace() {
curQuery.push_back(FurnaceGUIFindQuery());
}
if (ImGui::BeginTable("QueryLimits",2)) {
if (ImGui::BeginTable("QueryLimits",3)) {
ImGui::TableSetupColumn("c0",ImGuiTableColumnFlags_WidthFixed);
ImGui::TableSetupColumn("c1",ImGuiTableColumnFlags_WidthStretch,0.5f);
ImGui::TableSetupColumn("c2",ImGuiTableColumnFlags_WidthStretch,0.5f);
ImGui::TableNextRow();
ImGui::TableNextColumn();
@ -332,6 +338,7 @@ void FurnaceGUI::drawFindReplace() {
}
ImGui::EndDisabled();
ImGui::TableNextColumn();
ImGui::Text("Match effect position:");
if (ImGui::RadioButton("No",curQueryEffectPos==0)) {
@ -355,37 +362,189 @@ void FurnaceGUI::drawFindReplace() {
ImGui::TableNextRow();
ImGui::TableNextColumn();
ImGui::Checkbox("From start",&curQueryFromStart);
ImGui::TableNextColumn();
ImGui::Checkbox("Backwards",&curQueryBackwards);
ImGui::EndTable();
}
if (ImGui::TreeNode("Replace")) {
if (ImGui::BeginTable("QueryReplace",3)) {
ImGui::TableNextRow();
ImGui::TableNextColumn();
ImGui::Text("Note");
if (ImGui::BeginTable("QueryReplace",3,ImGuiTableFlags_BordersOuter)) {
ImGui::TableSetupColumn("c0",ImGuiTableColumnFlags_WidthFixed);
ImGui::TableSetupColumn("c1",ImGuiTableColumnFlags_WidthStretch,0.5);
ImGui::TableSetupColumn("c2",ImGuiTableColumnFlags_WidthStretch,0.5);
ImGui::TableNextRow();
ImGui::TableNextColumn();
ImGui::Text("Ins");
ImGui::Checkbox("Note",&queryReplaceNoteDo);
ImGui::TableNextColumn();
ImGui::BeginDisabled(!queryReplaceNoteDo);
ImGui::SetNextItemWidth(ImGui::GetContentRegionAvail().x);
ImGui::Combo("##NRMode",&queryReplaceNoteMode,queryReplaceModes,GUI_QUERY_REPLACE_MAX);
ImGui::TableNextColumn();
ImGui::SetNextItemWidth(ImGui::GetContentRegionAvail().x);
if (queryReplaceNoteMode==GUI_QUERY_REPLACE_SET) {
if (queryReplaceNote==130) {
snprintf(tempID,1024,"REL");
} else if (queryReplaceNote==129) {
snprintf(tempID,1024,"===");
} else if (queryReplaceNote==128) {
snprintf(tempID,1024,"OFF");
} else if (queryReplaceNote>=-60 && queryReplaceNote<120) {
snprintf(tempID,1024,"%s",noteNames[queryReplaceNote+60]);
} else {
snprintf(tempID,1024,"???");
queryReplaceNote=0;
}
if (ImGui::BeginCombo("##NRValueC",tempID)) {
for (int j=0; j<180; j++) {
snprintf(tempID,1024,"%s",noteNames[j]);
if (ImGui::Selectable(tempID,queryReplaceNote==(j-60))) {
queryReplaceNote=j-60;
}
}
if (ImGui::Selectable("OFF",queryReplaceNote==128)) {
queryReplaceNote=128;
}
if (ImGui::Selectable("===",queryReplaceNote==129)) {
queryReplaceNote=129;
}
if (ImGui::Selectable("REL",queryReplaceNote==130)) {
queryReplaceNote=130;
}
ImGui::EndCombo();
}
} else if (queryReplaceNoteMode==GUI_QUERY_REPLACE_ADD || queryReplaceNoteMode==GUI_QUERY_REPLACE_ADD_OVERFLOW) {
if (ImGui::InputInt("##NRValue",&queryReplaceNote,1,12)) {
if (queryReplaceNote<-180) queryReplaceNote=-180;
if (queryReplaceNote>180) queryReplaceNote=180;
}
}
ImGui::EndDisabled();
ImGui::TableNextRow();
ImGui::TableNextColumn();
ImGui::Text("Volume");
/*ImGui::TableNextRow();
ImGui::Checkbox("Ins",&queryReplaceInsDo);
ImGui::TableNextColumn();
ImGui::Text("Effect");
ImGui::BeginDisabled(!queryReplaceInsDo);
ImGui::SetNextItemWidth(ImGui::GetContentRegionAvail().x);
ImGui::Combo("##IRMode",&queryReplaceInsMode,queryReplaceModes,GUI_QUERY_REPLACE_MAX);
ImGui::TableNextColumn();
ImGui::SetNextItemWidth(ImGui::GetContentRegionAvail().x);
if (queryReplaceInsMode==GUI_QUERY_REPLACE_SET) {
if (ImGui::InputScalar("##IRValueH",ImGuiDataType_S32,&queryReplaceIns,&_ONE,&_SIXTEEN,"%.2X",ImGuiInputTextFlags_CharsHexadecimal)) {
if (queryReplaceIns<0) queryReplaceIns=0;
if (queryReplaceIns>255) queryReplaceIns=255;
}
} else if (queryReplaceInsMode==GUI_QUERY_REPLACE_ADD || queryReplaceInsMode==GUI_QUERY_REPLACE_ADD_OVERFLOW) {
if (ImGui::InputInt("##IRValue",&queryReplaceIns,1,12)) {
if (queryReplaceIns<-255) queryReplaceIns=-255;
if (queryReplaceIns>255) queryReplaceIns=255;
}
}
ImGui::EndDisabled();
ImGui::TableNextRow();
ImGui::TableNextColumn();
ImGui::Text("Value");*/
ImGui::Checkbox("Volume",&queryReplaceVolDo);
ImGui::TableNextColumn();
ImGui::BeginDisabled(!queryReplaceVolDo);
ImGui::SetNextItemWidth(ImGui::GetContentRegionAvail().x);
ImGui::Combo("##VRMode",&queryReplaceVolMode,queryReplaceModes,GUI_QUERY_REPLACE_MAX);
ImGui::TableNextColumn();
ImGui::SetNextItemWidth(ImGui::GetContentRegionAvail().x);
if (queryReplaceVolMode==GUI_QUERY_REPLACE_SET) {
if (ImGui::InputScalar("##VRValueH",ImGuiDataType_S32,&queryReplaceVol,&_ONE,&_SIXTEEN,"%.2X",ImGuiInputTextFlags_CharsHexadecimal)) {
if (queryReplaceVol<0) queryReplaceVol=0;
if (queryReplaceVol>255) queryReplaceVol=255;
}
} else if (queryReplaceVolMode==GUI_QUERY_REPLACE_ADD || queryReplaceVolMode==GUI_QUERY_REPLACE_ADD_OVERFLOW) {
if (ImGui::InputInt("##VRValue",&queryReplaceVol,1,12)) {
if (queryReplaceVol<-255) queryReplaceVol=-255;
if (queryReplaceVol>255) queryReplaceVol=255;
}
}
ImGui::EndDisabled();
for (int i=0; i<queryReplaceEffectCount; i++) {
ImGui::PushID(0x100+i);
ImGui::TableNextRow();
ImGui::TableNextColumn();
ImGui::Checkbox("Effect",&queryReplaceEffectDo[i]);
ImGui::TableNextColumn();
ImGui::BeginDisabled(!queryReplaceEffectDo[i]);
ImGui::SetNextItemWidth(ImGui::GetContentRegionAvail().x);
ImGui::Combo("##ERMode",&queryReplaceEffectMode[i],queryReplaceModes,GUI_QUERY_REPLACE_MAX);
ImGui::TableNextColumn();
ImGui::SetNextItemWidth(ImGui::GetContentRegionAvail().x);
if (queryReplaceEffectMode[i]==GUI_QUERY_REPLACE_SET) {
if (ImGui::InputScalar("##ERValueH",ImGuiDataType_S32,&queryReplaceEffect[i],&_ONE,&_SIXTEEN,"%.2X",ImGuiInputTextFlags_CharsHexadecimal)) {
if (queryReplaceEffect[i]<0) queryReplaceEffect[i]=0;
if (queryReplaceEffect[i]>255) queryReplaceEffect[i]=255;
}
} else if (queryReplaceEffectMode[i]==GUI_QUERY_REPLACE_ADD || queryReplaceEffectMode[i]==GUI_QUERY_REPLACE_ADD_OVERFLOW) {
if (ImGui::InputInt("##ERValue",&queryReplaceEffect[i],1,12)) {
if (queryReplaceEffect[i]<-255) queryReplaceEffect[i]=-255;
if (queryReplaceEffect[i]>255) queryReplaceEffect[i]=255;
}
}
ImGui::EndDisabled();
ImGui::TableNextRow();
ImGui::TableNextColumn();
ImGui::Checkbox("Value",&queryReplaceEffectValDo[i]);
ImGui::TableNextColumn();
ImGui::BeginDisabled(!queryReplaceEffectValDo[i]);
ImGui::SetNextItemWidth(ImGui::GetContentRegionAvail().x);
ImGui::Combo("##ERMode",&queryReplaceEffectValMode[i],queryReplaceModes,GUI_QUERY_REPLACE_MAX);
ImGui::TableNextColumn();
ImGui::SetNextItemWidth(ImGui::GetContentRegionAvail().x);
if (queryReplaceEffectValMode[i]==GUI_QUERY_REPLACE_SET) {
if (ImGui::InputScalar("##ERValueH",ImGuiDataType_S32,&queryReplaceEffectVal[i],&_ONE,&_SIXTEEN,"%.2X",ImGuiInputTextFlags_CharsHexadecimal)) {
if (queryReplaceEffectVal[i]<0) queryReplaceEffectVal[i]=0;
if (queryReplaceEffectVal[i]>255) queryReplaceEffectVal[i]=255;
}
} else if (queryReplaceEffectValMode[i]==GUI_QUERY_REPLACE_ADD || queryReplaceEffectValMode[i]==GUI_QUERY_REPLACE_ADD_OVERFLOW) {
if (ImGui::InputInt("##ERValue",&queryReplaceEffectVal[i],1,12)) {
if (queryReplaceEffectVal[i]<-255) queryReplaceEffectVal[i]=-255;
if (queryReplaceEffectVal[i]>255) queryReplaceEffectVal[i]=255;
}
}
ImGui::EndDisabled();
ImGui::PopID();
}
ImGui::TableNextRow();
ImGui::TableNextColumn();
ImGui::TableNextColumn();
if (queryReplaceEffectCount<8) {
if (ImGui::Button("Add effect")) {
queryReplaceEffectCount++;
}
}
ImGui::TableNextColumn();
if (queryReplaceEffectCount>0) {
if (ImGui::Button("Remove effect")) {
queryReplaceEffectCount--;
}
}
ImGui::EndTable();
}
ImGui::Text("Effect replace mode:");
if (ImGui::RadioButton("Clear effects",queryReplaceEffectPos==0)) {
queryReplaceEffectPos=0;
}
if (ImGui::RadioButton("Replace matches only",queryReplaceEffectPos==1)) {
queryReplaceEffectPos=1;
}
if (ImGui::RadioButton("Replace matches, then free spaces",queryReplaceEffectPos==2)) {
queryReplaceEffectPos=2;
}
if (ImGui::RadioButton("Insert in free spaces",queryReplaceEffectPos==3)) {
queryReplaceEffectPos=3;
}
if (ImGui::Button("Replace##QueryReplace")) {
// TODO
}

View file

@ -4431,6 +4431,25 @@ FurnaceGUI::FurnaceGUI():
wavePreviewLen(32),
wavePreviewHeight(255),
wavePreviewInit(true),
pgSys(0),
pgAddr(0),
pgVal(0),
curQueryRangeX(false),
curQueryBackwards(false),
curQueryRangeXMin(0), curQueryRangeXMax(0),
curQueryRangeY(0),
curQueryEffectPos(0),
queryReplaceEffectCount(0),
queryReplaceEffectPos(0),
queryReplaceNoteMode(0),
queryReplaceInsMode(0),
queryReplaceVolMode(0),
queryReplaceNote(0),
queryReplaceIns(0),
queryReplaceVol(0),
queryReplaceNoteDo(false),
queryReplaceInsDo(false),
queryReplaceVolDo(false),
wavePreviewOn(false),
wavePreviewKey((SDL_Scancode)0),
wavePreviewNote(0),
@ -4624,4 +4643,11 @@ FurnaceGUI::FurnaceGUI():
memset(pianoKeyHit,0,sizeof(float)*180);
memset(pianoKeyPressed,0,sizeof(bool)*180);
memset(queryReplaceEffectMode,0,sizeof(int)*8);
memset(queryReplaceEffectValMode,0,sizeof(int)*8);
memset(queryReplaceEffect,0,sizeof(int)*8);
memset(queryReplaceEffectVal,0,sizeof(int)*8);
memset(queryReplaceEffectDo,0,sizeof(bool)*8);
memset(queryReplaceEffectValDo,0,sizeof(bool)*8);
}

View file

@ -818,6 +818,7 @@ enum FurnaceGUIFindQueryModes {
enum FurnaceGUIFindQueryReplaceModes {
GUI_QUERY_REPLACE_SET=0,
GUI_QUERY_REPLACE_ADD,
GUI_QUERY_REPLACE_ADD_OVERFLOW,
GUI_QUERY_REPLACE_CLEAR,
GUI_QUERY_REPLACE_MAX
@ -1170,11 +1171,29 @@ class FurnaceGUI {
int pgSys, pgAddr, pgVal;
std::vector<FurnaceGUIFindQuery> curQuery;
bool curQueryRangeX, curQueryFromStart, curQueryBackwards;
bool curQueryRangeX, curQueryBackwards;
int curQueryRangeXMin, curQueryRangeXMax;
int curQueryRangeY;
int curQueryEffectPos;
int queryReplaceEffectCount;
int queryReplaceEffectPos;
int queryReplaceNoteMode;
int queryReplaceInsMode;
int queryReplaceVolMode;
int queryReplaceEffectMode[8];
int queryReplaceEffectValMode[8];
int queryReplaceNote;
int queryReplaceIns;
int queryReplaceVol;
int queryReplaceEffect[8];
int queryReplaceEffectVal[8];
bool queryReplaceNoteDo;
bool queryReplaceInsDo;
bool queryReplaceVolDo;
bool queryReplaceEffectDo[8];
bool queryReplaceEffectValDo[8];
struct ActiveNote {
int chan;
int note;

View file

@ -25,6 +25,7 @@ const int _THREE=3;
const int _SEVEN=7;
const int _TEN=10;
const int _FIFTEEN=15;
const int _SIXTEEN=16;
const int _THIRTY_ONE=31;
const int _SIXTY_FOUR=64;
const int _ONE_HUNDRED=100;

View file

@ -27,6 +27,7 @@ extern const int _THREE;
extern const int _SEVEN;
extern const int _TEN;
extern const int _FIFTEEN;
extern const int _SIXTEEN;
extern const int _THIRTY_ONE;
extern const int _SIXTY_FOUR;
extern const int _ONE_HUNDRED;

View file

@ -30,6 +30,7 @@
#ifdef _WIN32
#define WIN32_LEAN_AND_MEAN
#include <windows.h>
#include <combaseapi.h>
#include <shellapi.h>
#else
#include <unistd.h>
@ -243,6 +244,12 @@ void initParams() {
// TODO: add crash log
int main(int argc, char** argv) {
initLog();
#ifdef _WIN32
HRESULT coResult=CoInitializeEx(NULL,COINIT_MULTITHREADED);
if (coResult!=S_OK) {
logE("CoInitializeEx failed!");
}
#endif
#if !(defined(__APPLE__) || defined(_WIN32) || defined(ANDROID))
// workaround for Wayland HiDPI issue
if (getenv("SDL_VIDEODRIVER")==NULL) {
@ -446,6 +453,12 @@ int main(int argc, char** argv) {
logI("stopping engine.");
e.quit();
#ifdef _WIN32
if (coResult==S_OK || coResult==S_FALSE) {
CoUninitialize();
}
#endif
return 0;
}