GUI: define sample edit texture

This commit is contained in:
tildearrow 2022-03-17 03:43:02 -05:00
parent d6dfe2636a
commit 3c1b1b69fc
3 changed files with 107 additions and 34 deletions

View File

@ -6952,6 +6952,10 @@ bool FurnaceGUI::finish() {
FurnaceGUI::FurnaceGUI(): FurnaceGUI::FurnaceGUI():
e(NULL), e(NULL),
sampleTex(NULL),
sampleTexW(0),
sampleTexH(0),
updateSampleTex(true),
quit(false), quit(false),
warnQuit(false), warnQuit(false),
willCommit(false), willCommit(false),

View File

@ -466,6 +466,10 @@ class FurnaceGUI {
SDL_Window* sdlWin; SDL_Window* sdlWin;
SDL_Renderer* sdlRend; SDL_Renderer* sdlRend;
SDL_Texture* sampleTex;
int sampleTexW, sampleTexH;
bool updateSampleTex;
String workingDir, fileName, clipboard, warnString, errorString, lastError, curFileName, nextFile; String workingDir, fileName, clipboard, warnString, errorString, lastError, curFileName, nextFile;
String workingDirSong, workingDirIns, workingDirWave, workingDirSample, workingDirAudioExport, workingDirVGMExport, workingDirFont; String workingDirSong, workingDirIns, workingDirWave, workingDirSample, workingDirAudioExport, workingDirVGMExport, workingDirFont;
String mmlString[13]; String mmlString[13];

View File

@ -17,9 +17,13 @@
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/ */
#include "gui.h" #include "gui.h"
#include "../ta-log.h"
#include "IconsFontAwesome4.h" #include "IconsFontAwesome4.h"
#include "misc/cpp/imgui_stdlib.h" #include "misc/cpp/imgui_stdlib.h"
#include "guiConst.h" #include "guiConst.h"
#include <SDL_error.h>
#include <SDL_pixels.h>
#include <SDL_render.h>
#include <imgui.h> #include <imgui.h>
void FurnaceGUI::drawSampleEdit() { void FurnaceGUI::drawSampleEdit() {
@ -40,7 +44,13 @@ void FurnaceGUI::drawSampleEdit() {
sampleType=sampleDepths[sample->depth]; sampleType=sampleDepths[sample->depth];
} }
} }
ImGui::InputText("Name",&sample->name); ImGui::Text("Name");
ImGui::SetNextItemWidth(ImGui::GetContentRegionAvail().x);
ImGui::InputText("##SampleName",&sample->name);
if (ImGui::BeginTable("SampleProps",4,ImGuiTableFlags_SizingStretchSame)) {
ImGui::TableNextRow();
ImGui::TableNextColumn();
if (ImGui::BeginCombo("Type",sampleType.c_str())) { if (ImGui::BeginCombo("Type",sampleType.c_str())) {
for (int i=0; i<17; i++) { for (int i=0; i<17; i++) {
if (sampleDepths[i]==NULL) continue; if (sampleDepths[i]==NULL) continue;
@ -54,15 +64,20 @@ void FurnaceGUI::drawSampleEdit() {
} }
ImGui::EndCombo(); ImGui::EndCombo();
} }
ImGui::TableNextColumn();
if (ImGui::InputInt("Rate (Hz)",&sample->rate,10,200)) { if (ImGui::InputInt("Rate (Hz)",&sample->rate,10,200)) {
if (sample->rate<100) sample->rate=100; if (sample->rate<100) sample->rate=100;
if (sample->rate>96000) sample->rate=96000; if (sample->rate>96000) sample->rate=96000;
} }
ImGui::TableNextColumn();
if (ImGui::InputInt("Pitch of C-4 (Hz)",&sample->centerRate,10,200)) { if (ImGui::InputInt("Pitch of C-4 (Hz)",&sample->centerRate,10,200)) {
if (sample->centerRate<100) sample->centerRate=100; if (sample->centerRate<100) sample->centerRate=100;
if (sample->centerRate>65535) sample->centerRate=65535; if (sample->centerRate>65535) sample->centerRate=65535;
} }
ImGui::Text("effective rate: %dHz",e->getEffectiveSampleRate(sample->rate));
ImGui::TableNextColumn();
bool doLoop=(sample->loopStart>=0); bool doLoop=(sample->loopStart>=0);
if (ImGui::Checkbox("Loop",&doLoop)) { if (ImGui::Checkbox("Loop",&doLoop)) {
if (doLoop) { if (doLoop) {
@ -79,6 +94,10 @@ void FurnaceGUI::drawSampleEdit() {
} }
} }
} }
ImGui::EndTable();
}
/*
if (ImGui::Button("Apply")) { if (ImGui::Button("Apply")) {
e->renderSamplesP(); e->renderSamplesP();
} }
@ -89,8 +108,54 @@ void FurnaceGUI::drawSampleEdit() {
ImGui::SameLine(); ImGui::SameLine();
if (ImGui::Button(ICON_FA_VOLUME_OFF "##StopSample")) { if (ImGui::Button(ICON_FA_VOLUME_OFF "##StopSample")) {
e->stopSamplePreview(); e->stopSamplePreview();
} }*/
ImGui::Separator(); ImGui::Separator();
ImVec2 avail=ImGui::GetContentRegionAvail();
//int availX=avail.x;
int availY=avail.y;
if (sampleTex==NULL || sampleTexW!=avail.x || sampleTexH!=avail.y) {
if (sampleTex!=NULL) {
SDL_DestroyTexture(sampleTex);
sampleTex=NULL;
}
if (avail.x>=1 && avail.y>=1) {
logD("recreating sample texture.\n");
sampleTex=SDL_CreateTexture(sdlRend,SDL_PIXELFORMAT_ARGB8888,SDL_TEXTUREACCESS_STREAMING,avail.x,avail.y);
sampleTexW=avail.x;
sampleTexH=avail.y;
if (sampleTex==NULL) {
logE("error while creating sample texture! %s\n",SDL_GetError());
} else {
updateSampleTex=true;
}
}
}
if (sampleTex!=NULL) {
if (updateSampleTex) {
unsigned char* data=NULL;
int pitch=0;
logD("updating sample texture.\n");
if (SDL_LockTexture(sampleTex,NULL,(void**)&data,&pitch)!=0) {
logE("error while locking sample texture! %s\n",SDL_GetError());
} else {
for (int i=0; i<pitch*availY; i+=4) {
data[i]=255;
data[i+1]=255;
data[i+2]=255;
data[i+3]=255;
}
SDL_UnlockTexture(sampleTex);
}
updateSampleTex=false;
}
ImGui::Image(sampleTex,avail);
}
/*
bool considerations=false; bool considerations=false;
ImGui::Text("notes:"); ImGui::Text("notes:");
if (sample->loopStart>=0) { if (sample->loopStart>=0) {
@ -129,7 +194,7 @@ void FurnaceGUI::drawSampleEdit() {
} }
if (!considerations) { if (!considerations) {
ImGui::Text("- none"); ImGui::Text("- none");
} }*/
} }
} }
if (ImGui::IsWindowFocused(ImGuiFocusedFlags_ChildWindows)) curWindow=GUI_WINDOW_SAMPLE_EDIT; if (ImGui::IsWindowFocused(ImGuiFocusedFlags_ChildWindows)) curWindow=GUI_WINDOW_SAMPLE_EDIT;