| 1 |
/** |
| 2 |
* Furnace Tracker - multi-system chiptune tracker |
| 3 |
* Copyright (C) 2021-2025 tildearrow and contributors |
| 4 |
* |
| 5 |
* This program is free software; you can redistribute it and/or modify |
| 6 |
* it under the terms of the GNU General Public License as published by |
| 7 |
* the Free Software Foundation; either version 2 of the License, or |
| 8 |
* (at your option) any later version. |
| 9 |
* |
| 10 |
* This program is distributed in the hope that it will be useful, |
| 11 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 13 |
* GNU General Public License for more details. |
| 14 |
* |
| 15 |
* You should have received a copy of the GNU General Public License along |
| 16 |
* with this program; if not, write to the Free Software Foundation, Inc., |
| 17 |
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. |
| 18 |
*/ |
| 19 |
|
| 20 |
#define _USE_MATH_DEFINES |
| 21 |
#include "gui.h" |
| 22 |
#include "util.h" |
| 23 |
#include "plot_nolerp.h" |
| 24 |
#include "IconsFontAwesome4.h" |
| 25 |
#include "misc/cpp/imgui_stdlib.h" |
| 26 |
#include <fmt/printf.h> |
| 27 |
#include <math.h> |
| 28 |
#include <imgui.h> |
| 29 |
|
| 30 |
const char* waveGenBaseShapes[4]={ |
| 31 |
_N("Sine"), |
| 32 |
_N("Triangle"), |
| 33 |
_N("Saw"), |
| 34 |
_N("Pulse") |
| 35 |
}; |
| 36 |
|
| 37 |
const char* waveInterpolations[4]={ |
| 38 |
_N("None"), |
| 39 |
_N("Linear"), |
| 40 |
_N("Cosine"), |
| 41 |
_N("Cubic") |
| 42 |
}; |
| 43 |
|
| 44 |
typedef double (*WaveFunc) (double a); |
| 45 |
|
| 46 |
WaveFunc waveFuncs[]={ |
| 47 |
sinus, |
| 48 |
rectSin, |
| 49 |
absSin, |
| 50 |
quartSin, |
| 51 |
squiSin, |
| 52 |
squiAbsSin, |
| 53 |
|
| 54 |
square, |
| 55 |
rectSquare, |
| 56 |
|
| 57 |
saw, |
| 58 |
rectSaw, |
| 59 |
absSaw, |
| 60 |
|
| 61 |
cubSaw, |
| 62 |
rectCubSaw, |
| 63 |
absCubSaw, |
| 64 |
|
| 65 |
cubSine, |
| 66 |
rectCubSin, |
| 67 |
absCubSin, |
| 68 |
quartCubSin, |
| 69 |
squishCubSin, |
| 70 |
squishAbsCubSin, |
| 71 |
|
| 72 |
triangle, |
| 73 |
rectTri, |
| 74 |
absTri, |
| 75 |
quartTri, |
| 76 |
squiTri, |
| 77 |
absSquiTri, |
| 78 |
|
| 79 |
cubTriangle, |
| 80 |
cubRectTri, |
| 81 |
cubAbsTri, |
| 82 |
cubQuartTri, |
| 83 |
cubSquiTri, |
| 84 |
absCubSquiTri |
| 85 |
}; |
| 86 |
|
| 87 |
const char* fmWaveforms[] = { |
| 88 |
_N("Sine"), |
| 89 |
_N("Rect. Sine"), |
| 90 |
_N("Abs. Sine"), |
| 91 |
_N("Quart. Sine"), |
| 92 |
_N("Squish. Sine"), |
| 93 |
_N("Abs. Squish. Sine"), |
| 94 |
|
| 95 |
_N("Square"), |
| 96 |
_N("rectSquare"), |
| 97 |
|
| 98 |
_N("Saw"), |
| 99 |
_N("Rect. Saw"), |
| 100 |
_N("Abs. Saw"), |
| 101 |
|
| 102 |
_N("Cubed Saw"), |
| 103 |
_N("Rect. Cubed Saw"), |
| 104 |
_N("Abs. Cubed Saw"), |
| 105 |
|
| 106 |
_N("Cubed Sine"), |
| 107 |
_N("Rect. Cubed Sine"), |
| 108 |
_N("Abs. Cubed Sine"), |
| 109 |
_N("Quart. Cubed Sine"), |
| 110 |
_N("Squish. Cubed Sine"), |
| 111 |
_N("Squish. Abs. Cub. Sine"), |
| 112 |
|
| 113 |
_N("Triangle"), |
| 114 |
_N("Rect. Triangle"), |
| 115 |
_N("Abs. Triangle"), |
| 116 |
_N("Quart. Triangle"), |
| 117 |
_N("Squish. Triangle"), |
| 118 |
_N("Abs. Squish. Triangle"), |
| 119 |
|
| 120 |
_N("Cubed Triangle"), |
| 121 |
_N("Rect. Cubed Triangle"), |
| 122 |
_N("Abs. Cubed Triangle"), |
| 123 |
_N("Quart. Cubed Triangle"), |
| 124 |
_N("Squish. Cubed Triangle"), |
| 125 |
_N("Squish. Abs. Cub. Triangle"), |
| 126 |
}; |
| 127 |
|
| 128 |
const size_t fmWaveformsLen=sizeof(fmWaveforms)/sizeof(fmWaveforms[0]); |
| 129 |
|
| 130 |
const float multFactors[17]={ |
| 131 |
M_PI, |
| 132 |
2*M_PI, |
| 133 |
4*M_PI, |
| 134 |
6*M_PI, |
| 135 |
8*M_PI, |
| 136 |
10*M_PI, |
| 137 |
12*M_PI, |
| 138 |
14*M_PI, |
| 139 |
16*M_PI, |
| 140 |
18*M_PI, |
| 141 |
20*M_PI, |
| 142 |
22*M_PI, |
| 143 |
24*M_PI, |
| 144 |
26*M_PI, |
| 145 |
28*M_PI, |
| 146 |
30*M_PI, |
| 147 |
32*M_PI, |
| 148 |
}; |
| 149 |
|
| 150 |
void FurnaceGUI::doGenerateWave() { |
| 151 |
float finalResult[256]; |
| 152 |
if (curWave<0 || curWave>=(int)e->song.wave.size()) return; |
| 153 |
|
| 154 |
DivWavetable* wave=e->song.wave[curWave]; |
| 155 |
memset(finalResult,0,sizeof(float)*256); |
| 156 |
|
| 157 |
if (wave->len<2) return; |
| 158 |
|
| 159 |
if (waveGenFM) { |
| 160 |
float s0fb0=0; |
| 161 |
float s0fb1=0; |
| 162 |
float s1fb0=0; |
| 163 |
float s1fb1=0; |
| 164 |
float s2fb0=0; |
| 165 |
float s2fb1=0; |
| 166 |
float s3fb0=0; |
| 167 |
float s3fb1=0; |
| 168 |
|
| 169 |
float s0=0; |
| 170 |
float s1=0; |
| 171 |
float s2=0; |
| 172 |
float s3=1; |
| 173 |
|
| 174 |
for (int i=0; i<wave->len; i++) { |
| 175 |
float pos=(float)i/(float)wave->len; |
| 176 |
|
| 177 |
s0=waveFuncs[fmWaveform[0]]((pos + |
| 178 |
(waveGenFB[0] ? ((s0fb0 + s0fb1) * pow(2.0f, waveGenFB[0] - 8)) : 0.0f) + |
| 179 |
(waveGenFMCon0[3] ? s3 : 0.0f) + |
| 180 |
(waveGenFMCon0[2] ? s2 : 0.0f) + |
| 181 |
(waveGenFMCon0[1] ? s1 : 0.0f) + |
| 182 |
(waveGenFMCon0[0] ? s0 : 0.0f))* multFactors[waveGenMult[0]]) * waveGenTL[0]; |
| 183 |
|
| 184 |
s0fb0=s0fb1; |
| 185 |
s0fb1=s0; |
| 186 |
|
| 187 |
s1=waveFuncs[fmWaveform[1]]((pos + |
| 188 |
(waveGenFB[1] ? ((s1fb0 + s1fb1) * pow(2.0f, waveGenFB[1] - 8)) : 0.0f) + |
| 189 |
(waveGenFMCon1[3] ? s3 : 0.0f) + |
| 190 |
(waveGenFMCon1[2] ? s2 : 0.0f) + |
| 191 |
(waveGenFMCon1[1] ? s1 : 0.0f) + |
| 192 |
(waveGenFMCon1[0] ? s0 : 0.0f))* multFactors[waveGenMult[1]]) * waveGenTL[1]; |
| 193 |
|
| 194 |
s1fb0=s1fb1; |
| 195 |
s1fb1=s1; |
| 196 |
|
| 197 |
s2=waveFuncs[fmWaveform[2]]((pos + |
| 198 |
(waveGenFB[2] ? ((s2fb0 + s2fb1) * pow(2.0f, waveGenFB[2] - 8)) : 0.0f) + |
| 199 |
(waveGenFMCon2[3] ? s3 : 0.0f) + |
| 200 |
(waveGenFMCon2[2] ? s2 : 0.0f) + |
| 201 |
(waveGenFMCon2[1] ? s1 : 0.0f) + |
| 202 |
(waveGenFMCon2[0] ? s0 : 0.0f))* multFactors[waveGenMult[2]]) * waveGenTL[2]; |
| 203 |
|
| 204 |
s2fb0=s2fb1; |
| 205 |
s2fb1=s2; |
| 206 |
|
| 207 |
s3=waveFuncs[fmWaveform[3]]((pos + |
| 208 |
(waveGenFB[3] ? ((s3fb0 + s3fb1) * pow(2.0f, waveGenFB[3] - 8)) : 0.0f) + |
| 209 |
(waveGenFMCon3[3] ? s3 : 0.0f) + |
| 210 |
(waveGenFMCon3[2] ? s2 : 0.0f) + |
| 211 |
(waveGenFMCon3[1] ? s1 : 0.0f) + |
| 212 |
(waveGenFMCon3[0] ? s0 : 0.0f)) * multFactors[waveGenMult[3]])* waveGenTL[3]; |
| 213 |
|
| 214 |
s3fb0=s3fb1; |
| 215 |
s3fb1=s3; |
| 216 |
|
| 217 |
if (waveGenFMCon0[4]) finalResult[i]+=s0; |
| 218 |
if (waveGenFMCon1[4]) finalResult[i]+=s1; |
| 219 |
if (waveGenFMCon2[4]) finalResult[i]+=s2; |
| 220 |
if (waveGenFMCon3[4]) finalResult[i]+=s3; |
| 221 |
} |
| 222 |
} else { |
| 223 |
switch (waveGenBaseShape) { |
| 224 |
case 0: // sine |
| 225 |
for (int i=0; i<wave->len; i++) { |
| 226 |
for (int j=0; j<16; j++) { |
| 227 |
float pos=fmod((waveGenPhase[j]*wave->len)+(i*(j+1)),wave->len); |
| 228 |
float partial=sin((0.5+pos)*2.0*M_PI/(double)wave->len); |
| 229 |
partial=pow(partial,waveGenPower); |
| 230 |
partial*=waveGenAmp[j]; |
| 231 |
finalResult[i]+=partial; |
| 232 |
} |
| 233 |
} |
| 234 |
break; |
| 235 |
case 1: // triangle |
| 236 |
for (int i=0; i<wave->len; i++) { |
| 237 |
for (int j=0; j<16; j++) { |
| 238 |
float pos=fmod((waveGenPhase[j]*wave->len)+(i*(j+1)),wave->len); |
| 239 |
float partial=4.0*(0.5-fabs(0.5-(pos/(double)(wave->len-1))))-1.0; |
| 240 |
partial=pow(partial,waveGenPower); |
| 241 |
partial*=waveGenAmp[j]; |
| 242 |
finalResult[i]+=partial; |
| 243 |
} |
| 244 |
} |
| 245 |
break; |
| 246 |
case 2: // saw |
| 247 |
for (int i=0; i<wave->len; i++) { |
| 248 |
for (int j=0; j<16; j++) { |
| 249 |
float pos=fmod((waveGenPhase[j]*wave->len)+(i*(j+1)),wave->len); |
| 250 |
float partial=((2*pos)/(double)(wave->len-1))-1.0; |
| 251 |
partial=pow(partial,waveGenPower); |
| 252 |
partial*=waveGenAmp[j]; |
| 253 |
finalResult[i]+=partial; |
| 254 |
} |
| 255 |
} |
| 256 |
break; |
| 257 |
case 3: // pulse |
| 258 |
for (int i=0; i<wave->len; i++) { |
| 259 |
for (int j=0; j<16; j++) { |
| 260 |
float pos=fmod((waveGenPhase[j]*wave->len)+(i*(j+1)),wave->len); |
| 261 |
float partial=(pos>=(waveGenDuty*wave->len))?1:-1; |
| 262 |
partial=pow(partial,waveGenPower); |
| 263 |
partial*=waveGenAmp[j]; |
| 264 |
finalResult[i]+=partial; |
| 265 |
} |
| 266 |
} |
| 267 |
break; |
| 268 |
} |
| 269 |
} |
| 270 |
|
| 271 |
for (int i=waveGenInvertPoint*wave->len; i<wave->len; i++) { |
| 272 |
finalResult[i]=-finalResult[i]; |
| 273 |
} |
| 274 |
|
| 275 |
for (int i=0; i<wave->len; i++) { |
| 276 |
finalResult[i]=(1.0+finalResult[i])*0.5; |
| 277 |
if (finalResult[i]<0.0f) finalResult[i]=0.0f; |
| 278 |
if (finalResult[i]>1.0f) finalResult[i]=1.0f; |
| 279 |
wave->data[i]=round(finalResult[i]*wave->max); |
| 280 |
} |
| 281 |
|
| 282 |
e->notifyWaveChange(curWave); |
| 283 |
MARK_MODIFIED; |
| 284 |
} |
| 285 |
|
| 286 |
#define CENTER_TEXT(text) \ |
| 287 |
ImGui::SetCursorPosX(ImGui::GetCursorPosX()+0.5*(ImGui::GetContentRegionAvail().x-ImGui::CalcTextSize(text).x)); |
| 288 |
|
| 289 |
void FurnaceGUI::drawWaveEdit() { |
| 290 |
if (nextWindow==GUI_WINDOW_WAVE_EDIT) { |
| 291 |
waveEditOpen=true; |
| 292 |
ImGui::SetNextWindowFocus(); |
| 293 |
nextWindow=GUI_WINDOW_NOTHING; |
| 294 |
} |
| 295 |
if (!waveEditOpen) return; |
| 296 |
float wavePreview[257]; |
| 297 |
if (mobileUI) { |
| 298 |
patWindowPos=(portrait?ImVec2(0.0f,(mobileMenuPos*-0.65*canvasH)):ImVec2((0.16*canvasH)+0.5*canvasW*mobileMenuPos,0.0f)); |
| 299 |
patWindowSize=(portrait?ImVec2(canvasW,canvasH-(0.16*canvasW)-(pianoOpen?(0.4*canvasW):0.0f)):ImVec2(canvasW-(0.16*canvasH),canvasH-(pianoOpen?(0.3*canvasH):0.0f))); |
| 300 |
ImGui::SetNextWindowPos(patWindowPos); |
| 301 |
ImGui::SetNextWindowSize(patWindowSize); |
| 302 |
} else { |
| 303 |
ImGui::SetNextWindowSizeConstraints(ImVec2(300.0f*dpiScale,300.0f*dpiScale),ImVec2(canvasW,canvasH)); |
| 304 |
} |
| 305 |
if (ImGui::Begin("Wavetable Editor",&waveEditOpen,globalWinFlags|(settings.allowEditDocking?0:ImGuiWindowFlags_NoDocking),_("Wavetable Editor"))) { |
| 306 |
if (curWave<0 || curWave>=(int)e->song.wave.size()) { |
| 307 |
ImGui::SetCursorPosY(ImGui::GetCursorPosY()+(ImGui::GetContentRegionAvail().y-ImGui::GetFrameHeightWithSpacing()*2.0f)*0.5f); |
| 308 |
CENTER_TEXT(_("no wavetable selected")); |
| 309 |
ImGui::Text(_("no wavetable selected")); |
| 310 |
if (ImGui::BeginTable("noAssetCenter",3)) { |
| 311 |
ImGui::TableSetupColumn("c0",ImGuiTableColumnFlags_WidthStretch,0.5f); |
| 312 |
ImGui::TableSetupColumn("c1",ImGuiTableColumnFlags_WidthFixed); |
| 313 |
ImGui::TableSetupColumn("c2",ImGuiTableColumnFlags_WidthStretch,0.5f); |
| 314 |
|
| 315 |
ImGui::TableNextRow(); |
| 316 |
ImGui::TableNextColumn(); |
| 317 |
ImGui::TableNextColumn(); |
| 318 |
|
| 319 |
if (e->song.wave.size()>0) { |
| 320 |
if (ImGui::BeginCombo("##WaveSelect",_("select one..."))) { |
| 321 |
if (ImGui::BeginTable("WaveSelCombo",1,ImGuiTableFlags_ScrollY)) { |
| 322 |
actualWaveList(); |
| 323 |
ImGui::EndTable(); |
| 324 |
} |
| 325 |
ImGui::EndCombo(); |
| 326 |
} |
| 327 |
ImGui::SameLine(); |
| 328 |
ImGui::TextUnformatted(_("or")); |
| 329 |
ImGui::SameLine(); |
| 330 |
} |
| 331 |
if (ImGui::Button(_("Open"))) { |
| 332 |
doAction(GUI_ACTION_WAVE_LIST_OPEN); |
| 333 |
} |
| 334 |
ImGui::SameLine(); |
| 335 |
ImGui::TextUnformatted(_("or")); |
| 336 |
ImGui::SameLine(); |
| 337 |
if (ImGui::Button(_("Create New"))) { |
| 338 |
doAction(GUI_ACTION_WAVE_LIST_ADD); |
| 339 |
} |
| 340 |
|
| 341 |
ImGui::TableNextColumn(); |
| 342 |
ImGui::EndTable(); |
| 343 |
} |
| 344 |
} else { |
| 345 |
DivWavetable* wave=e->song.wave[curWave]; |
| 346 |
|
| 347 |
if (ImGui::BeginTable("WEProps",2)) { |
| 348 |
ImGui::TableSetupColumn("c0",ImGuiTableColumnFlags_WidthStretch); |
| 349 |
ImGui::TableSetupColumn("c1",ImGuiTableColumnFlags_WidthFixed); |
| 350 |
ImGui::TableNextRow(); |
| 351 |
|
| 352 |
ImGui::TableNextColumn(); |
| 353 |
ImGui::SetNextItemWidth(80.0f*dpiScale); |
| 354 |
if (ImGui::InputInt("##CurWave",&curWave,1,10)) { |
| 355 |
if (curWave<0) curWave=0; |
| 356 |
if (curWave>=(int)e->song.wave.size()) curWave=e->song.wave.size()-1; |
| 357 |
} |
| 358 |
ImGui::SameLine(); |
| 359 |
if (ImGui::Button(ICON_FA_FOLDER_OPEN "##WELoad")) { |
| 360 |
doAction(GUI_ACTION_WAVE_LIST_OPEN_REPLACE); |
| 361 |
} |
| 362 |
if (ImGui::IsItemHovered()) { |
| 363 |
ImGui::SetTooltip(_("Open")); |
| 364 |
} |
| 365 |
ImGui::SameLine(); |
| 366 |
if (ImGui::Button(ICON_FA_FLOPPY_O "##WESave")) { |
| 367 |
doAction(GUI_ACTION_WAVE_LIST_SAVE); |
| 368 |
} |
| 369 |
if (ImGui::IsItemHovered()) { |
| 370 |
ImGui::SetTooltip(_("Save")); |
| 371 |
} |
| 372 |
if (ImGui::BeginPopupContextItem("WaveSaveFormats",ImGuiMouseButton_Right)) { |
| 373 |
if (ImGui::MenuItem(_("save as .dmw..."))) { |
| 374 |
doAction(GUI_ACTION_WAVE_LIST_SAVE_DMW); |
| 375 |
} |
| 376 |
if (ImGui::MenuItem(_("save raw..."))) { |
| 377 |
doAction(GUI_ACTION_WAVE_LIST_SAVE_RAW); |
| 378 |
} |
| 379 |
ImGui::EndPopup(); |
| 380 |
} |
| 381 |
ImGui::SameLine(); |
| 382 |
if (ImGui::Button(ICON_FA_UPLOAD)) { |
| 383 |
doAction(GUI_ACTION_WAVE_LIST_CREATE_SAMPLE); |
| 384 |
} |
| 385 |
if (ImGui::IsItemHovered()) { |
| 386 |
ImGui::SetTooltip(_("create sample from wavetable")); |
| 387 |
} |
| 388 |
ImGui::SameLine(); |
| 389 |
|
| 390 |
if (ImGui::RadioButton(_("Steps"),waveEditStyle==0)) { |
| 391 |
waveEditStyle=0; |
| 392 |
} |
| 393 |
ImGui::SameLine(); |
| 394 |
if (ImGui::RadioButton(_("Lines"),waveEditStyle==1)) { |
| 395 |
waveEditStyle=1; |
| 396 |
} |
| 397 |
|
| 398 |
ImGui::TableNextColumn(); |
| 399 |
ImGui::Text(_("Width")); |
| 400 |
if (ImGui::IsItemHovered()) { |
| 401 |
ImGui::SetTooltip(_("use a width of:\n- any on Amiga/N163\n- 32 on Game Boy, PC Engine, SCC, Konami Bubble System, Namco WSG, Virtual Boy and WonderSwan\n- 64 on FDS\n- 128 on X1-010\n- 256 on SID3\nany other widths will be scaled during playback.")); |
| 402 |
} |
| 403 |
ImGui::SameLine(); |
| 404 |
ImGui::SetNextItemWidth(96.0f*dpiScale); |
| 405 |
if (ImGui::InputInt("##_WTW",&wave->len,1,16)) { |
| 406 |
if (wave->len>256) wave->len=256; |
| 407 |
if (wave->len<1) wave->len=1; |
| 408 |
e->notifyWaveChange(curWave); |
| 409 |
if (wavePreviewOn) e->previewWave(curWave,wavePreviewNote); |
| 410 |
MARK_MODIFIED; |
| 411 |
} |
| 412 |
ImGui::SameLine(); |
| 413 |
ImGui::Text(_("Height")); |
| 414 |
if (ImGui::IsItemHovered()) { |
| 415 |
ImGui::SetTooltip(_("use a height of:\n- 16 for Game Boy, WonderSwan, Namco WSG, Konami Bubble System, X1-010 Envelope shape and N163\n- 32 for PC Engine\n- 64 for FDS and Virtual Boy\n- 256 for X1-010, SCC and SID3\nany other heights will be scaled during playback.")); |
| 416 |
} |
| 417 |
ImGui::SameLine(); |
| 418 |
ImGui::SetNextItemWidth(96.0f*dpiScale); |
| 419 |
int realMax=wave->max+1; |
| 420 |
if (ImGui::InputInt("##_WTH",&realMax,1,16)) { |
| 421 |
if (realMax>256) realMax=256; |
| 422 |
if (realMax<2) realMax=2; |
| 423 |
wave->max=realMax-1; |
| 424 |
e->notifyWaveChange(curWave); |
| 425 |
MARK_MODIFIED; |
| 426 |
} |
| 427 |
|
| 428 |
ImGui::SameLine(); |
| 429 |
if (ImGui::Button(waveGenVisible?(ICON_FA_CHEVRON_RIGHT "##WEWaveGen"):(ICON_FA_CHEVRON_LEFT "##WEWaveGen"))) { |
| 430 |
waveGenVisible=!waveGenVisible; |
| 431 |
} |
| 432 |
|
| 433 |
ImGui::EndTable(); |
| 434 |
} |
| 435 |
|
| 436 |
for (int i=0; i<wave->len; i++) { |
| 437 |
if (wave->data[i]>wave->max) wave->data[i]=wave->max; |
| 438 |
wavePreview[i]=wave->data[i]; |
| 439 |
if (waveSigned && !waveHex) { |
| 440 |
wavePreview[i]-=(int)((wave->max+1)/2); |
| 441 |
} |
| 442 |
} |
| 443 |
if (wave->len>0) wavePreview[wave->len]=wave->data[wave->len-1]; |
| 444 |
|
| 445 |
if (ImGui::BeginTable("WEWaveSection",waveGenVisible?2:1)) { |
| 446 |
ImGui::TableSetupColumn("c0",ImGuiTableColumnFlags_WidthStretch); |
| 447 |
if (waveGenVisible) ImGui::TableSetupColumn("c1",ImGuiTableColumnFlags_WidthFixed,250.0f*dpiScale); |
| 448 |
ImGui::TableNextRow(); |
| 449 |
|
| 450 |
ImGui::TableNextColumn(); |
| 451 |
ImGui::PushStyleVar(ImGuiStyleVar_FramePadding,ImVec2(0.0f,0.0f)); |
| 452 |
|
| 453 |
ImVec2 contentRegion=ImGui::GetContentRegionAvail(); // wavetable graph size determined here |
| 454 |
contentRegion.y-=ImGui::GetFrameHeightWithSpacing()+ImGui::GetStyle().WindowPadding.y; |
| 455 |
if (waveEditStyle) { |
| 456 |
PlotNoLerp("##Waveform",wavePreview,wave->len+1,0,NULL,(waveSigned && !waveHex)?(-(int)((wave->max+1)/2)):0,(waveSigned && !waveHex)?((int)(wave->max/2)):wave->max,contentRegion); |
| 457 |
} else { |
| 458 |
PlotCustom("##Waveform",wavePreview,wave->len,0,NULL,(waveSigned && !waveHex)?(-(int)((wave->max+1)/2)):0,(waveSigned && !waveHex)?((int)(wave->max/2)):wave->max,contentRegion,sizeof(float),ImVec4(1.0f,1.0f,1.0f,1.0f),0,NULL,NULL,true); |
| 459 |
} |
| 460 |
if (ImGui::IsItemClicked(ImGuiMouseButton_Left)) { |
| 461 |
waveDragStart=ImGui::GetItemRectMin(); |
| 462 |
waveDragAreaSize=contentRegion; |
| 463 |
waveDragMin=0; |
| 464 |
waveDragMax=wave->max; |
| 465 |
waveDragLen=wave->len; |
| 466 |
waveDragActive=true; |
| 467 |
waveDragTarget=wave->data; |
| 468 |
processDrags(ImGui::GetMousePos().x,ImGui::GetMousePos().y); |
| 469 |
e->notifyWaveChange(curWave); |
| 470 |
modified=true; |
| 471 |
} |
| 472 |
ImGui::PopStyleVar(); |
| 473 |
|
| 474 |
if (waveGenVisible) { |
| 475 |
ImGui::TableNextColumn(); |
| 476 |
|
| 477 |
ImVec2 waveGenSize=ImGui::GetContentRegionAvail(); |
| 478 |
waveGenSize.y=contentRegion.y; |
| 479 |
if (ImGui::BeginChild("WaveGenView",waveGenSize)) { |
| 480 |
if (ImGui::BeginTabBar("WaveGenOpt")) { |
| 481 |
if (ImGui::BeginTabItem(_("Shapes"))) { |
| 482 |
waveGenFM=false; |
| 483 |
|
| 484 |
if (waveGenBaseShape<0) waveGenBaseShape=0; |
| 485 |
if (waveGenBaseShape>3) waveGenBaseShape=3; |
| 486 |
ImGui::SetNextItemWidth(ImGui::GetContentRegionAvail().x); |
| 487 |
if (CWSliderInt("##WGShape",&waveGenBaseShape,0,3,_(waveGenBaseShapes[waveGenBaseShape]))) { |
| 488 |
if (waveGenBaseShape<0) waveGenBaseShape=0; |
| 489 |
if (waveGenBaseShape>3) waveGenBaseShape=3; |
| 490 |
doGenerateWave(); |
| 491 |
} |
| 492 |
|
| 493 |
if (ImGui::BeginTable("WGShapeProps",2)) { |
| 494 |
ImGui::TableSetupColumn("c0",ImGuiTableColumnFlags_WidthFixed); |
| 495 |
ImGui::TableSetupColumn("c1",ImGuiTableColumnFlags_WidthStretch); |
| 496 |
|
| 497 |
ImGui::TableNextRow(); |
| 498 |
ImGui::TableNextColumn(); |
| 499 |
ImGui::AlignTextToFramePadding(); |
| 500 |
ImGui::Text(_("Duty")); |
| 501 |
ImGui::TableNextColumn(); |
| 502 |
ImGui::SetNextItemWidth(ImGui::GetContentRegionAvail().x); |
| 503 |
if (CWSliderFloat("##WGDuty",&waveGenDuty,0.0f,1.0f)) { |
| 504 |
doGenerateWave(); |
| 505 |
} rightClickable |
| 506 |
|
| 507 |
ImGui::TableNextRow(); |
| 508 |
ImGui::TableNextColumn(); |
| 509 |
ImGui::AlignTextToFramePadding(); |
| 510 |
ImGui::Text(_("Exponent")); |
| 511 |
ImGui::TableNextColumn(); |
| 512 |
ImGui::SetNextItemWidth(ImGui::GetContentRegionAvail().x); |
| 513 |
if (CWSliderInt("##WGExp",&waveGenPower,1,8)) { |
| 514 |
doGenerateWave(); |
| 515 |
} rightClickable |
| 516 |
|
| 517 |
ImGui::TableNextRow(); |
| 518 |
ImGui::TableNextColumn(); |
| 519 |
ImGui::AlignTextToFramePadding(); |
| 520 |
ImGui::Text(_("XOR Point")); |
| 521 |
ImGui::TableNextColumn(); |
| 522 |
ImGui::SetNextItemWidth(ImGui::GetContentRegionAvail().x); |
| 523 |
if (CWSliderFloat("##WGXOR",&waveGenInvertPoint,0.0f,1.0f)) { |
| 524 |
doGenerateWave(); |
| 525 |
} rightClickable |
| 526 |
|
| 527 |
ImGui::EndTable(); |
| 528 |
} |
| 529 |
|
| 530 |
if (ImGui::TreeNode(_("Amplitude/Phase"))) { |
| 531 |
if (ImGui::BeginTable("WGShapeProps",3)) { |
| 532 |
ImGui::TableSetupColumn("c0",ImGuiTableColumnFlags_WidthFixed); |
| 533 |
ImGui::TableSetupColumn("c1",ImGuiTableColumnFlags_WidthStretch,0.6f); |
| 534 |
ImGui::TableSetupColumn("c2",ImGuiTableColumnFlags_WidthStretch,0.4f); |
| 535 |
|
| 536 |
for (int i=0; i<16; i++) { |
| 537 |
ImGui::TableNextRow(); |
| 538 |
ImGui::TableNextColumn(); |
| 539 |
ImGui::AlignTextToFramePadding(); |
| 540 |
ImGui::Text("%d",i+1); |
| 541 |
ImGui::TableNextColumn(); |
| 542 |
ImGui::PushID(140+i); |
| 543 |
ImGui::SetNextItemWidth(ImGui::GetContentRegionAvail().x); |
| 544 |
if (CWSliderFloat("##WGAmp",&waveGenAmp[i],-1.0f,1.0f)) { |
| 545 |
doGenerateWave(); |
| 546 |
} rightClickable |
| 547 |
if (ImGui::IsItemClicked(ImGuiMouseButton_Middle)) { |
| 548 |
waveGenAmp[i]=0.0f; |
| 549 |
doGenerateWave(); |
| 550 |
} |
| 551 |
ImGui::PopID(); |
| 552 |
ImGui::TableNextColumn(); |
| 553 |
ImGui::PushID(140+i); |
| 554 |
ImGui::SetNextItemWidth(ImGui::GetContentRegionAvail().x); |
| 555 |
if (CWSliderFloat("##WGPhase",&waveGenPhase[i],0.0f,1.0f)) { |
| 556 |
doGenerateWave(); |
| 557 |
} rightClickable |
| 558 |
if (ImGui::IsItemClicked(ImGuiMouseButton_Middle)) { |
| 559 |
waveGenPhase[i]=0.0f; |
| 560 |
doGenerateWave(); |
| 561 |
} |
| 562 |
ImGui::PopID(); |
| 563 |
} |
| 564 |
|
| 565 |
ImGui::EndTable(); |
| 566 |
} |
| 567 |
ImGui::TreePop(); |
| 568 |
} |
| 569 |
ImGui::EndTabItem(); |
| 570 |
} |
| 571 |
if (ImGui::BeginTabItem(_("FM"))) { |
| 572 |
waveGenFM=true; |
| 573 |
|
| 574 |
if (ImGui::BeginTable("WGFMProps",4)) { |
| 575 |
ImGui::TableSetupColumn("c0",ImGuiTableColumnFlags_WidthFixed,ImGui::CalcTextSize("Op").x); |
| 576 |
ImGui::TableSetupColumn("c1",ImGuiTableColumnFlags_WidthStretch,0.5); |
| 577 |
ImGui::TableSetupColumn("c2",ImGuiTableColumnFlags_WidthStretch,0.25); |
| 578 |
ImGui::TableSetupColumn("c3", ImGuiTableColumnFlags_WidthStretch, 0.25); |
| 579 |
|
| 580 |
ImGui::TableNextRow(ImGuiTableRowFlags_Headers); |
| 581 |
ImGui::TableNextColumn(); |
| 582 |
ImGui::Text(_("Op")); |
| 583 |
ImGui::TableNextColumn(); |
| 584 |
ImGui::Text(_("Level")); |
| 585 |
ImGui::TableNextColumn(); |
| 586 |
ImGui::Text(_("Mult")); |
| 587 |
ImGui::TableNextColumn(); |
| 588 |
ImGui::Text(_("FB")); |
| 589 |
|
| 590 |
for (int i=0; i<4; i++) { |
| 591 |
ImGui::TableNextRow(); |
| 592 |
ImGui::TableNextColumn(); |
| 593 |
ImGui::AlignTextToFramePadding(); |
| 594 |
ImGui::Text("%d",i+1); |
| 595 |
|
| 596 |
ImGui::TableNextColumn(); |
| 597 |
ImGui::SetNextItemWidth(ImGui::GetContentRegionAvail().x); |
| 598 |
ImGui::PushID(i); |
| 599 |
if (CWSliderFloat("##WGTL",&waveGenTL[i],0.0f,1.0f)) { |
| 600 |
doGenerateWave(); |
| 601 |
} rightClickable |
| 602 |
ImGui::PopID(); |
| 603 |
|
| 604 |
ImGui::TableNextColumn(); |
| 605 |
ImGui::SetNextItemWidth(ImGui::GetContentRegionAvail().x); |
| 606 |
ImGui::PushID(i); |
| 607 |
if (CWSliderInt("##WGMULT",&waveGenMult[i],1,16)) { |
| 608 |
doGenerateWave(); |
| 609 |
} rightClickable |
| 610 |
ImGui::PopID(); |
| 611 |
|
| 612 |
ImGui::TableNextColumn(); |
| 613 |
ImGui::SetNextItemWidth(ImGui::GetContentRegionAvail().x); |
| 614 |
ImGui::PushID(i); |
| 615 |
if (CWSliderInt("##WGFB",&waveGenFB[i],0,7)) { |
| 616 |
doGenerateWave(); |
| 617 |
} rightClickable |
| 618 |
|
| 619 |
ImGui::PopID(); |
| 620 |
} |
| 621 |
|
| 622 |
ImGui::EndTable(); |
| 623 |
} |
| 624 |
|
| 625 |
if (ImGui::BeginTable("WGFMWAVE",2)) { |
| 626 |
ImGui::TableSetupColumn("c0",ImGuiTableColumnFlags_WidthFixed,ImGui::CalcTextSize(_("Op")).x); |
| 627 |
ImGui::TableSetupColumn("c1",ImGuiTableColumnFlags_WidthStretch,1); |
| 628 |
|
| 629 |
ImGui::TableNextRow(ImGuiTableRowFlags_Headers); |
| 630 |
ImGui::TableNextColumn(); |
| 631 |
ImGui::Text(_("Op")); |
| 632 |
ImGui::TableNextColumn(); |
| 633 |
ImGui::Text(_("Waveform")); |
| 634 |
|
| 635 |
for (int i=0; i<4; i++) { |
| 636 |
ImGui::TableNextRow(); |
| 637 |
ImGui::TableNextColumn(); |
| 638 |
ImGui::AlignTextToFramePadding(); |
| 639 |
ImGui::Text("%d",i+1); |
| 640 |
|
| 641 |
ImGui::TableNextColumn(); |
| 642 |
ImGui::SetNextItemWidth(ImGui::GetContentRegionAvail().x); |
| 643 |
ImGui::PushID(i); |
| 644 |
if (CWSliderInt("##WGWAVEFORM",&fmWaveform[i],0,fmWaveformsLen-1,_(fmWaveforms[fmWaveform[i]]))) { |
| 645 |
doGenerateWave(); |
| 646 |
} |
| 647 |
ImGui::PopID(); |
| 648 |
} |
| 649 |
ImGui::EndTable(); |
| 650 |
} |
| 651 |
|
| 652 |
CENTER_TEXT(_("Connection Diagram")); |
| 653 |
ImGui::Text(_("Connection Diagram")); |
| 654 |
|
| 655 |
if (ImGui::BeginTable("WGFMCon",6)) { |
| 656 |
ImGui::TableNextRow(); |
| 657 |
ImGui::TableNextColumn(); |
| 658 |
ImGui::Text(">>"); |
| 659 |
ImGui::TableNextColumn(); |
| 660 |
ImGui::Text("1"); |
| 661 |
ImGui::TableNextColumn(); |
| 662 |
ImGui::Text("2"); |
| 663 |
ImGui::TableNextColumn(); |
| 664 |
ImGui::Text("3"); |
| 665 |
ImGui::TableNextColumn(); |
| 666 |
ImGui::Text("4"); |
| 667 |
ImGui::TableNextColumn(); |
| 668 |
ImGui::Text(_("Out")); |
| 669 |
|
| 670 |
ImGui::TableNextRow(); |
| 671 |
ImGui::TableNextColumn(); |
| 672 |
ImGui::AlignTextToFramePadding(); |
| 673 |
ImGui::Text("1"); |
| 674 |
ImGui::TableNextColumn(); |
| 675 |
if (ImGui::Checkbox("##ConO1",&waveGenFMCon0[0])) { |
| 676 |
doGenerateWave(); |
| 677 |
} |
| 678 |
ImGui::TableNextColumn(); |
| 679 |
if (ImGui::Checkbox("##ConO2",&waveGenFMCon0[1])) { |
| 680 |
doGenerateWave(); |
| 681 |
} |
| 682 |
ImGui::TableNextColumn(); |
| 683 |
if (ImGui::Checkbox("##ConO3",&waveGenFMCon0[2])) { |
| 684 |
doGenerateWave(); |
| 685 |
} |
| 686 |
ImGui::TableNextColumn(); |
| 687 |
if (ImGui::Checkbox("##ConO4",&waveGenFMCon0[3])) { |
| 688 |
doGenerateWave(); |
| 689 |
} |
| 690 |
ImGui::TableNextColumn(); |
| 691 |
if (ImGui::Checkbox("##ConOO",&waveGenFMCon0[4])) { |
| 692 |
doGenerateWave(); |
| 693 |
} |
| 694 |
|
| 695 |
ImGui::TableNextRow(); |
| 696 |
ImGui::TableNextColumn(); |
| 697 |
ImGui::AlignTextToFramePadding(); |
| 698 |
ImGui::Text("2"); |
| 699 |
ImGui::TableNextColumn(); |
| 700 |
if (ImGui::Checkbox("##Con11",&waveGenFMCon1[0])) { |
| 701 |
doGenerateWave(); |
| 702 |
} |
| 703 |
ImGui::TableNextColumn(); |
| 704 |
if (ImGui::Checkbox("##Con12",&waveGenFMCon1[1])) { |
| 705 |
doGenerateWave(); |
| 706 |
} |
| 707 |
ImGui::TableNextColumn(); |
| 708 |
if (ImGui::Checkbox("##Con13",&waveGenFMCon1[2])) { |
| 709 |
doGenerateWave(); |
| 710 |
} |
| 711 |
ImGui::TableNextColumn(); |
| 712 |
if (ImGui::Checkbox("##Con14",&waveGenFMCon1[3])) { |
| 713 |
doGenerateWave(); |
| 714 |
} |
| 715 |
ImGui::TableNextColumn(); |
| 716 |
if (ImGui::Checkbox("##Con1O",&waveGenFMCon1[4])) { |
| 717 |
doGenerateWave(); |
| 718 |
} |
| 719 |
|
| 720 |
ImGui::TableNextRow(); |
| 721 |
ImGui::TableNextColumn(); |
| 722 |
ImGui::AlignTextToFramePadding(); |
| 723 |
ImGui::Text("3"); |
| 724 |
ImGui::TableNextColumn(); |
| 725 |
if (ImGui::Checkbox("##Con21",&waveGenFMCon2[0])) { |
| 726 |
doGenerateWave(); |
| 727 |
} |
| 728 |
ImGui::TableNextColumn(); |
| 729 |
if (ImGui::Checkbox("##Con22",&waveGenFMCon2[1])) { |
| 730 |
doGenerateWave(); |
| 731 |
} |
| 732 |
ImGui::TableNextColumn(); |
| 733 |
if (ImGui::Checkbox("##Con23",&waveGenFMCon2[2])) { |
| 734 |
doGenerateWave(); |
| 735 |
} |
| 736 |
ImGui::TableNextColumn(); |
| 737 |
if (ImGui::Checkbox("##Con24",&waveGenFMCon2[3])) { |
| 738 |
doGenerateWave(); |
| 739 |
} |
| 740 |
ImGui::TableNextColumn(); |
| 741 |
if (ImGui::Checkbox("##Con2O",&waveGenFMCon2[4])) { |
| 742 |
doGenerateWave(); |
| 743 |
} |
| 744 |
|
| 745 |
ImGui::TableNextRow(); |
| 746 |
ImGui::TableNextColumn(); |
| 747 |
ImGui::AlignTextToFramePadding(); |
| 748 |
ImGui::Text("4"); |
| 749 |
ImGui::TableNextColumn(); |
| 750 |
if (ImGui::Checkbox("##Con31",&waveGenFMCon3[0])) { |
| 751 |
doGenerateWave(); |
| 752 |
} |
| 753 |
ImGui::TableNextColumn(); |
| 754 |
if (ImGui::Checkbox("##Con32",&waveGenFMCon3[1])) { |
| 755 |
doGenerateWave(); |
| 756 |
} |
| 757 |
ImGui::TableNextColumn(); |
| 758 |
if (ImGui::Checkbox("##Con33",&waveGenFMCon3[2])) { |
| 759 |
doGenerateWave(); |
| 760 |
} |
| 761 |
ImGui::TableNextColumn(); |
| 762 |
if (ImGui::Checkbox("##Con34",&waveGenFMCon3[3])) { |
| 763 |
doGenerateWave(); |
| 764 |
} |
| 765 |
ImGui::TableNextColumn(); |
| 766 |
if (ImGui::Checkbox("##Con3O",&waveGenFMCon3[4])) { |
| 767 |
doGenerateWave(); |
| 768 |
} |
| 769 |
|
| 770 |
ImGui::EndTable(); |
| 771 |
} |
| 772 |
|
| 773 |
ImGui::EndTabItem(); |
| 774 |
} |
| 775 |
if (ImGui::BeginTabItem(_("WaveTools"))) { |
| 776 |
if (ImGui::BeginTable("WGParamItems",2)) { |
| 777 |
ImGui::TableSetupColumn("c0",ImGuiTableColumnFlags_WidthStretch); |
| 778 |
ImGui::TableSetupColumn("c1",ImGuiTableColumnFlags_WidthFixed); |
| 779 |
|
| 780 |
ImGui::TableNextRow(); |
| 781 |
ImGui::TableNextColumn(); |
| 782 |
ImGui::SetNextItemWidth(ImGui::GetContentRegionAvail().x); |
| 783 |
if (ImGui::InputInt("##WGScaleX",&waveGenScaleX,1,16)) { |
| 784 |
if (waveGenScaleX<2) waveGenScaleX=2; |
| 785 |
if (waveGenScaleX>256) waveGenScaleX=256; |
| 786 |
} |
| 787 |
ImGui::SetNextItemWidth(ImGui::GetContentRegionAvail().x); |
| 788 |
if (CWSliderInt("##WGInterpolation",&waveInterpolation,0,3,_(waveInterpolations[waveInterpolation]))) { |
| 789 |
if (waveInterpolation<0) waveInterpolation=0; |
| 790 |
if (waveInterpolation>3) waveInterpolation=3; |
| 791 |
} |
| 792 |
ImGui::TableNextColumn(); |
| 793 |
if (ImGui::Button(_("Scale X"))) { |
| 794 |
if (waveGenScaleX>0 && wave->len!=waveGenScaleX) e->lockEngine([this,wave]() { |
| 795 |
int origData[256]; |
| 796 |
// Copy original wave to temp buffer |
| 797 |
// If longer than 256 samples, return |
| 798 |
if (wave->len>256) { |
| 799 |
showError(_("wavetable longer than 256 samples!")); |
| 800 |
return; |
| 801 |
} |
| 802 |
memcpy(origData,wave->data,wave->len*sizeof(int)); |
| 803 |
|
| 804 |
float t=0; // Index used into `origData` |
| 805 |
|
| 806 |
for (int i=0; i<waveGenScaleX; i++, t+=(float)wave->len/waveGenScaleX) { |
| 807 |
switch (waveInterpolation) { |
| 808 |
case 0: { |
| 809 |
wave->data[i]=origData[i*wave->len/waveGenScaleX]; |
| 810 |
break; |
| 811 |
} |
| 812 |
case 1: { // Linear |
| 813 |
int idx=t; // Implicitly floors `t` |
| 814 |
int s0=origData[(idx)%wave->len]; |
| 815 |
int s1=origData[(idx+1)%wave->len]; |
| 816 |
double mu=(t-idx); |
| 817 |
wave->data[i]=s0+mu*s1-(mu*s0); |
| 818 |
break; |
| 819 |
} |
| 820 |
case 2: { // Cosine |
| 821 |
int idx=t; // Implicitly floors `t` |
| 822 |
int s0=origData[(idx)%wave->len]; |
| 823 |
int s1=origData[(idx+1)%wave->len]; |
| 824 |
double mu=(t-idx); |
| 825 |
double muCos=(1-cos(mu*M_PI))/2; |
| 826 |
wave->data[i]=s0+muCos*s1-(muCos*s0); |
| 827 |
break; |
| 828 |
} |
| 829 |
case 3: { // Cubic Spline |
| 830 |
int idx=t; // Implicitly floors `t` |
| 831 |
int s0=origData[((idx-1%wave->len+wave->len)%wave->len)]; |
| 832 |
int s1=origData[(idx)%wave->len]; |
| 833 |
int s2=origData[(idx+1)%wave->len]; |
| 834 |
int s3=origData[(idx+2)%wave->len]; |
| 835 |
double mu=(t-idx); |
| 836 |
double mu2=mu*mu; |
| 837 |
double a0=-0.5*s0+1.5*s1-1.5*s2+0.5*s3; |
| 838 |
double a1=s0-2.5*s1+2*s2-0.5*s3; |
| 839 |
double a2=-0.5*s0+0.5*s2; |
| 840 |
double a3=s1; |
| 841 |
wave->data[i]=(a0*mu*mu2+a1*mu2+a2*mu+a3); |
| 842 |
break; |
| 843 |
} |
| 844 |
default: { // No interpolation |
| 845 |
wave->data[i]=origData[i*wave->len/waveGenScaleX]; |
| 846 |
break; |
| 847 |
} |
| 848 |
} |
| 849 |
} |
| 850 |
wave->len=waveGenScaleX; |
| 851 |
MARK_MODIFIED; |
| 852 |
}); |
| 853 |
e->notifyWaveChange(curWave); |
| 854 |
} |
| 855 |
|
| 856 |
ImGui::TableNextRow(); |
| 857 |
ImGui::TableNextColumn(); |
| 858 |
ImGui::SetNextItemWidth(ImGui::GetContentRegionAvail().x); |
| 859 |
if (ImGui::InputInt("##WGScaleY",&waveGenScaleY,1,16)) { |
| 860 |
if (waveGenScaleY<2) waveGenScaleY=2; |
| 861 |
if (waveGenScaleY>256) waveGenScaleY=256; |
| 862 |
} |
| 863 |
ImGui::TableNextColumn(); |
| 864 |
if (ImGui::Button(_("Scale Y"))) { |
| 865 |
if (waveGenScaleY>0 && wave->max!=(waveGenScaleY-1)) e->lockEngine([this,wave]() { |
| 866 |
for (int i=0; i<wave->len; i++) { |
| 867 |
wave->data[i]=(wave->data[i]*(waveGenScaleY))/(wave->max+1); |
| 868 |
} |
| 869 |
wave->max=waveGenScaleY-1; |
| 870 |
MARK_MODIFIED; |
| 871 |
}); |
| 872 |
e->notifyWaveChange(curWave); |
| 873 |
} |
| 874 |
|
| 875 |
ImGui::TableNextRow(); |
| 876 |
ImGui::TableNextColumn(); |
| 877 |
ImGui::SetNextItemWidth(ImGui::GetContentRegionAvail().x); |
| 878 |
if (ImGui::InputInt("##WGOffsetX",&waveGenOffsetX,1,16)) { |
| 879 |
if (waveGenOffsetX<-wave->len+1) waveGenOffsetX=-wave->len+1; |
| 880 |
if (waveGenOffsetX>wave->len-1) waveGenOffsetX=wave->len-1; |
| 881 |
} |
| 882 |
ImGui::TableNextColumn(); |
| 883 |
if (ImGui::Button(_("Offset X"))) { |
| 884 |
if (waveGenOffsetX!=0 && wave->len>0) e->lockEngine([this,wave]() { |
| 885 |
int origData[256]; |
| 886 |
memcpy(origData,wave->data,wave->len*sizeof(int)); |
| 887 |
int realOff=-waveGenOffsetX; |
| 888 |
while (realOff<0) realOff+=wave->len; |
| 889 |
|
| 890 |
for (int i=0; i<wave->len; i++) { |
| 891 |
wave->data[i]=origData[(i+realOff)%wave->len]; |
| 892 |
} |
| 893 |
MARK_MODIFIED; |
| 894 |
}); |
| 895 |
e->notifyWaveChange(curWave); |
| 896 |
} |
| 897 |
|
| 898 |
ImGui::TableNextRow(); |
| 899 |
ImGui::TableNextColumn(); |
| 900 |
ImGui::SetNextItemWidth(ImGui::GetContentRegionAvail().x); |
| 901 |
if (ImGui::InputInt("##WGOffsetY",&waveGenOffsetY,1,16)) { |
| 902 |
if (waveGenOffsetY<-wave->max) waveGenOffsetY=-wave->max; |
| 903 |
if (waveGenOffsetY>wave->max) waveGenOffsetY=wave->max; |
| 904 |
} |
| 905 |
ImGui::TableNextColumn(); |
| 906 |
if (ImGui::Button(_("Offset Y"))) { |
| 907 |
if (waveGenOffsetY!=0) e->lockEngine([this,wave]() { |
| 908 |
for (int i=0; i<wave->len; i++) { |
| 909 |
wave->data[i]=CLAMP(wave->data[i]+waveGenOffsetY,0,wave->max); |
| 910 |
} |
| 911 |
MARK_MODIFIED; |
| 912 |
}); |
| 913 |
e->notifyWaveChange(curWave); |
| 914 |
} |
| 915 |
|
| 916 |
ImGui::TableNextRow(); |
| 917 |
ImGui::TableNextColumn(); |
| 918 |
ImGui::SetNextItemWidth(ImGui::GetContentRegionAvail().x); |
| 919 |
if (ImGui::InputInt("##WGSmooth",&waveGenSmooth,1,4)) { |
| 920 |
if (waveGenSmooth>wave->len) waveGenSmooth=wave->len; |
| 921 |
if (waveGenSmooth<1) waveGenSmooth=1; |
| 922 |
} |
| 923 |
ImGui::TableNextColumn(); |
| 924 |
if (ImGui::Button(_("Smooth"))) { |
| 925 |
if (waveGenSmooth>0) e->lockEngine([this,wave]() { |
| 926 |
int origData[256]; |
| 927 |
memcpy(origData,wave->data,wave->len*sizeof(int)); |
| 928 |
for (int i=0; i<wave->len; i++) { |
| 929 |
int dataSum=0; |
| 930 |
for (int j=i; j<i+waveGenSmooth+1; j++) { |
| 931 |
int pos=(j-((waveGenSmooth+1)/2)); |
| 932 |
while (pos<0) pos+=wave->len; |
| 933 |
dataSum+=origData[pos%wave->len]; |
| 934 |
} |
| 935 |
dataSum/=waveGenSmooth+1; |
| 936 |
wave->data[i]=dataSum; |
| 937 |
} |
| 938 |
MARK_MODIFIED; |
| 939 |
}); |
| 940 |
e->notifyWaveChange(curWave); |
| 941 |
} |
| 942 |
|
| 943 |
ImGui::TableNextRow(); |
| 944 |
ImGui::TableNextColumn(); |
| 945 |
ImGui::SetNextItemWidth(ImGui::GetContentRegionAvail().x); |
| 946 |
float amp=waveGenAmplify*100.0f; |
| 947 |
if (ImGui::InputFloat("##WGAmplify",&,1.0f,10.0f)) { |
| 948 |
waveGenAmplify=amp/100.0f; |
| 949 |
if (waveGenAmplify<0.0f) waveGenAmplify=0.0f; |
| 950 |
if (waveGenAmplify>100.0f) waveGenAmplify=100.0f; |
| 951 |
} |
| 952 |
ImGui::TableNextColumn(); |
| 953 |
if (ImGui::Button(_("Amplify"))) { |
| 954 |
if (waveGenAmplify!=1.0f) e->lockEngine([this,wave]() { |
| 955 |
for (int i=0; i<wave->len; i++) { |
| 956 |
wave->data[i]=CLAMP(round((float)(wave->data[i]-(int)( /* Clang can you stop complaining */ (int)(wave->max+1)/(int)2))*waveGenAmplify),(int)(-((wave->max+1)/2)),(int)(wave->max/2))+(int)((wave->max+1)/2); |
| 957 |
} |
| 958 |
MARK_MODIFIED; |
| 959 |
}); |
| 960 |
e->notifyWaveChange(curWave); |
| 961 |
} |
| 962 |
|
| 963 |
ImGui::EndTable(); |
| 964 |
} |
| 965 |
|
| 966 |
ImVec2 buttonSize=ImGui::GetContentRegionAvail(); |
| 967 |
buttonSize.y=0.0f; |
| 968 |
ImVec2 buttonSizeHalf=buttonSize; |
| 969 |
buttonSizeHalf.x-=ImGui::GetStyle().ItemSpacing.x; |
| 970 |
buttonSizeHalf.x*=0.5; |
| 971 |
|
| 972 |
if (ImGui::Button(_("Normalize"),buttonSize)) { |
| 973 |
e->lockEngine([this,wave]() { |
| 974 |
// find lowest point |
| 975 |
int lowest=wave->max; |
| 976 |
for (int i=0; i<wave->len; i++) { |
| 977 |
if (wave->data[i]<lowest) lowest=wave->data[i]; |
| 978 |
} |
| 979 |
|
| 980 |
// find highest point |
| 981 |
int highest=0; |
| 982 |
for (int i=0; i<wave->len; i++) { |
| 983 |
if (wave->data[i]>highest) highest=wave->data[i]; |
| 984 |
} |
| 985 |
|
| 986 |
// abort if lowest and highest points are equal |
| 987 |
if (lowest==highest) return; |
| 988 |
|
| 989 |
// abort if lowest and highest points already span the entire height |
| 990 |
if (lowest==wave->max && highest==0) return; |
| 991 |
|
| 992 |
// apply offset |
| 993 |
for (int i=0; i<wave->len; i++) { |
| 994 |
wave->data[i]-=lowest; |
| 995 |
} |
| 996 |
highest-=lowest; |
| 997 |
|
| 998 |
// scale |
| 999 |
for (int i=0; i<wave->len; i++) { |
| 1000 |
wave->data[i]=(wave->data[i]*wave->max)/highest; |
| 1001 |
} |
| 1002 |
MARK_MODIFIED; |
| 1003 |
}); |
| 1004 |
e->notifyWaveChange(curWave); |
| 1005 |
} |
| 1006 |
if (ImGui::Button(_("Invert"),buttonSizeHalf)) { |
| 1007 |
e->lockEngine([this,wave]() { |
| 1008 |
for (int i=0; i<wave->len; i++) { |
| 1009 |
wave->data[i]=wave->max-wave->data[i]; |
| 1010 |
} |
| 1011 |
MARK_MODIFIED; |
| 1012 |
}); |
| 1013 |
e->notifyWaveChange(curWave); |
| 1014 |
} |
| 1015 |
ImGui::SameLine(); |
| 1016 |
if (ImGui::Button(_("Reverse"),buttonSizeHalf)) { |
| 1017 |
e->lockEngine([this,wave]() { |
| 1018 |
int origData[256]; |
| 1019 |
memcpy(origData,wave->data,wave->len*sizeof(int)); |
| 1020 |
|
| 1021 |
for (int i=0; i<wave->len; i++) { |
| 1022 |
wave->data[i]=origData[wave->len-1-i]; |
| 1023 |
} |
| 1024 |
MARK_MODIFIED; |
| 1025 |
}); |
| 1026 |
e->notifyWaveChange(curWave); |
| 1027 |
} |
| 1028 |
|
| 1029 |
if (ImGui::Button(_("Half"),buttonSizeHalf)) { |
| 1030 |
int origData[256]; |
| 1031 |
memcpy(origData,wave->data,wave->len*sizeof(int)); |
| 1032 |
|
| 1033 |
for (int i=0; i<wave->len; i++) { |
| 1034 |
wave->data[i]=origData[i>>1]; |
| 1035 |
} |
| 1036 |
e->notifyWaveChange(curWave); |
| 1037 |
MARK_MODIFIED; |
| 1038 |
} |
| 1039 |
ImGui::SameLine(); |
| 1040 |
if (ImGui::Button(_("Double"),buttonSizeHalf)) { |
| 1041 |
int origData[256]; |
| 1042 |
memcpy(origData,wave->data,wave->len*sizeof(int)); |
| 1043 |
|
| 1044 |
for (int i=0; i<wave->len; i++) { |
| 1045 |
wave->data[i]=origData[(i*2)%wave->len]; |
| 1046 |
} |
| 1047 |
e->notifyWaveChange(curWave); |
| 1048 |
MARK_MODIFIED; |
| 1049 |
} |
| 1050 |
|
| 1051 |
if (ImGui::Button(_("Convert Signed/Unsigned"),buttonSize)) { |
| 1052 |
if (wave->max>0) e->lockEngine([this,wave]() { |
| 1053 |
for (int i=0; i<wave->len; i++) { |
| 1054 |
if (wave->data[i]>(wave->max/2)) { |
| 1055 |
wave->data[i]-=(wave->max+1)/2; |
| 1056 |
} else { |
| 1057 |
wave->data[i]+=(wave->max+1)/2; |
| 1058 |
} |
| 1059 |
} |
| 1060 |
MARK_MODIFIED; |
| 1061 |
}); |
| 1062 |
e->notifyWaveChange(curWave); |
| 1063 |
} |
| 1064 |
if (ImGui::Button(_("Randomize"),buttonSize)) { |
| 1065 |
if (wave->max>0) e->lockEngine([this,wave]() { |
| 1066 |
for (int i=0; i<wave->len; i++) { |
| 1067 |
wave->data[i]=rand()%(wave->max+1); |
| 1068 |
} |
| 1069 |
MARK_MODIFIED; |
| 1070 |
}); |
| 1071 |
e->notifyWaveChange(curWave); |
| 1072 |
} |
| 1073 |
ImGui::EndTabItem(); |
| 1074 |
} |
| 1075 |
ImGui::EndTabBar(); |
| 1076 |
} |
| 1077 |
} |
| 1078 |
ImGui::EndChild(); |
| 1079 |
} |
| 1080 |
ImGui::EndTable(); |
| 1081 |
} |
| 1082 |
|
| 1083 |
if (ImGui::RadioButton(_("Dec"),!waveHex)) { |
| 1084 |
waveHex=false; |
| 1085 |
} |
| 1086 |
ImGui::SameLine(); |
| 1087 |
if (ImGui::RadioButton(_("Hex"),waveHex)) { |
| 1088 |
waveHex=true; |
| 1089 |
} |
| 1090 |
ImGui::SameLine(); |
| 1091 |
if (!waveHex) if (ImGui::Button(waveSigned?"±##WaveSign":"+##WaveSign",ImVec2(ImGui::GetFrameHeight(),ImGui::GetFrameHeight()))) { |
| 1092 |
waveSigned=!waveSigned; |
| 1093 |
} |
| 1094 |
if (ImGui::IsItemHovered()) { |
| 1095 |
ImGui::SetTooltip(_("Signed/Unsigned")); |
| 1096 |
} |
| 1097 |
ImGui::SameLine(); |
| 1098 |
ImGui::SetNextItemWidth(ImGui::GetContentRegionAvail().x); // wavetable text input size found here |
| 1099 |
if (ImGui::InputText("##MMLWave",&mmlStringW)) { |
| 1100 |
int actualData[256]; |
| 1101 |
decodeMMLStrW(mmlStringW,actualData,wave->len,(waveSigned && !waveHex)?(-((wave->max+1)/2)):0,(waveSigned && !waveHex)?(wave->max/2):wave->max,waveHex); |
| 1102 |
MARK_MODIFIED; |
| 1103 |
if (waveSigned && !waveHex) { |
| 1104 |
for (int i=0; i<wave->len; i++) { |
| 1105 |
actualData[i]+=(wave->max+1)/2; |
| 1106 |
} |
| 1107 |
} |
| 1108 |
memcpy(wave->data,actualData,wave->len*sizeof(int)); |
| 1109 |
} |
| 1110 |
if (!ImGui::IsItemActive()) { |
| 1111 |
int actualData[256]; |
| 1112 |
memcpy(actualData,wave->data,256*sizeof(int)); |
| 1113 |
if (waveSigned && !waveHex) { |
| 1114 |
for (int i=0; i<wave->len; i++) { |
| 1115 |
actualData[i]-=(wave->max+1)/2; |
| 1116 |
} |
| 1117 |
} |
| 1118 |
encodeMMLStr(mmlStringW,actualData,wave->len,-1,-1,waveHex); |
| 1119 |
} |
| 1120 |
} |
| 1121 |
} |
| 1122 |
if (ImGui::IsWindowFocused(ImGuiFocusedFlags_ChildWindows)) curWindow=GUI_WINDOW_WAVE_EDIT; |
| 1123 |
ImGui::End(); |
| 1124 |
} |