| 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 <imgui.h> |
| 23 |
#include <imgui_internal.h> |
| 24 |
#include <math.h> |
| 25 |
#include "../ta-log.h" |
| 26 |
#include "IconsFontAwesome4.h" |
| 27 |
#include "furIcons.h" |
| 28 |
#include "misc/cpp/imgui_stdlib.h" |
| 29 |
#include <fmt/printf.h> |
| 30 |
#include "guiConst.h" |
| 31 |
#include "sampleUtil.h" |
| 32 |
#include "util.h" |
| 33 |
#include "intConst.h" |
| 34 |
|
| 35 |
#define SWAP_COLOR_ARGB(x) \ |
| 36 |
x=(x&0xff00ff00)|((x&0xff)<<16)|((x&0xff0000)>>16); |
| 37 |
|
| 38 |
#define SWAP_COLOR_BGRA(x) \ |
| 39 |
x=((x&0xff0000000)>>24)|((x&0xffffff)<<8); |
| 40 |
|
| 41 |
#define SWAP_COLOR_RGBA(x) \ |
| 42 |
x=((x&0xff)<<24)|((x&0xff00)<<8)|((x&0xff0000)>>8)|((x&0xff000000)>>24); |
| 43 |
|
| 44 |
const double timeDivisors[10]={ |
| 45 |
1000.0, 500.0, 200.0, 100.0, 50.0, 20.0, 10.0, 5.0, 2.0, 1.0 |
| 46 |
}; |
| 47 |
|
| 48 |
const double timeMultipliers[13]={ |
| 49 |
1.0, 2.0, 5.0, 10.0, 20.0, 30.0, |
| 50 |
60.0, 2*60.0, 5*60.0, 10*60.0, 20*60.0, 30*60.0, |
| 51 |
3600.0 |
| 52 |
}; |
| 53 |
|
| 54 |
#define CENTER_TEXT(text) \ |
| 55 |
ImGui::SetCursorPosX(ImGui::GetCursorPosX()+0.5*(ImGui::GetContentRegionAvail().x-ImGui::CalcTextSize(text).x)); |
| 56 |
|
| 57 |
#define SAMPLE_WARN(_x,_text) \ |
| 58 |
if (_x.find(_text)==String::npos) { \ |
| 59 |
if (!_x.empty()) _x+='\n'; \ |
| 60 |
_x+=_text; \ |
| 61 |
} |
| 62 |
|
| 63 |
#define MAX_RATE(_name,_x) \ |
| 64 |
if (e->isPreviewingSample()) { \ |
| 65 |
if ((int)e->getSamplePreviewRate()>(int)(_x)) { \ |
| 66 |
SAMPLE_WARN(warnRate,fmt::sprintf(_("%s: maximum sample rate is %d"),_name,(int)(_x))); \ |
| 67 |
} \ |
| 68 |
} |
| 69 |
|
| 70 |
#define MIN_RATE(_name,_x) \ |
| 71 |
if (e->isPreviewingSample()) { \ |
| 72 |
if ((int)e->getSamplePreviewRate()<(int)(_x)) { \ |
| 73 |
SAMPLE_WARN(warnRate,fmt::sprintf(_("%s: minimum sample rate is %d"),_name,(int)(_x))); \ |
| 74 |
} \ |
| 75 |
} |
| 76 |
|
| 77 |
#define EXACT_RATE(_name,_x) \ |
| 78 |
if (e->isPreviewingSample()) { \ |
| 79 |
if ((int)e->getSamplePreviewRate()!=(int)(_x)) { \ |
| 80 |
SAMPLE_WARN(warnRate,fmt::sprintf(_("%s: sample rate must be %d"),_name,(int)(_x))); \ |
| 81 |
} \ |
| 82 |
} |
| 83 |
|
| 84 |
#define EXACT_2RATES(_name,_x,_y) \ |
| 85 |
if (e->isPreviewingSample()) { \ |
| 86 |
if (((int)e->getSamplePreviewRate()!=(int)(_x)) || (int)e->getSamplePreviewRate()!=(int)(_y)) { \ |
| 87 |
SAMPLE_WARN(warnRate,fmt::sprintf(_("%s: sample rate must be %d or %d"),_name,(int)(_x),(int)(_y))); \ |
| 88 |
} \ |
| 89 |
} |
| 90 |
|
| 91 |
void FurnaceGUI::drawSampleEdit() { |
| 92 |
if (nextWindow==GUI_WINDOW_SAMPLE_EDIT) { |
| 93 |
sampleEditOpen=true; |
| 94 |
ImGui::SetNextWindowFocus(); |
| 95 |
nextWindow=GUI_WINDOW_NOTHING; |
| 96 |
} |
| 97 |
if (!sampleEditOpen) return; |
| 98 |
if (mobileUI) { |
| 99 |
patWindowPos=(portrait?ImVec2(0.0f,(mobileMenuPos*-0.65*canvasH)):ImVec2((0.16*canvasH)+0.5*canvasW*mobileMenuPos,0.0f)); |
| 100 |
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))); |
| 101 |
ImGui::SetNextWindowPos(patWindowPos); |
| 102 |
ImGui::SetNextWindowSize(patWindowSize); |
| 103 |
} |
| 104 |
if (ImGui::Begin("Sample Editor",&sampleEditOpen,globalWinFlags|(settings.allowEditDocking?0:ImGuiWindowFlags_NoDocking),_("Sample Editor"))) { |
| 105 |
if (curSample<0 || curSample>=(int)e->song.sample.size()) { |
| 106 |
ImGui::SetCursorPosY(ImGui::GetCursorPosY()+(ImGui::GetContentRegionAvail().y-ImGui::GetFrameHeightWithSpacing()*2.0f)*0.5f); |
| 107 |
CENTER_TEXT(_("no sample selected")); |
| 108 |
ImGui::Text(_("no sample selected")); |
| 109 |
if (ImGui::BeginTable("noAssetCenter",3)) { |
| 110 |
ImGui::TableSetupColumn("c0",ImGuiTableColumnFlags_WidthStretch,0.5f); |
| 111 |
ImGui::TableSetupColumn("c1",ImGuiTableColumnFlags_WidthFixed); |
| 112 |
ImGui::TableSetupColumn("c2",ImGuiTableColumnFlags_WidthStretch,0.5f); |
| 113 |
|
| 114 |
ImGui::TableNextRow(); |
| 115 |
ImGui::TableNextColumn(); |
| 116 |
ImGui::TableNextColumn(); |
| 117 |
|
| 118 |
if (e->song.sample.size()>0) { |
| 119 |
if (ImGui::BeginCombo("##SampleSelect",_("select one..."))) { |
| 120 |
if (ImGui::BeginTable("SampleSelCombo",1,ImGuiTableFlags_ScrollY)) { |
| 121 |
actualSampleList(); |
| 122 |
ImGui::EndTable(); |
| 123 |
} |
| 124 |
ImGui::EndCombo(); |
| 125 |
} |
| 126 |
ImGui::SameLine(); |
| 127 |
ImGui::TextUnformatted(_("or")); |
| 128 |
ImGui::SameLine(); |
| 129 |
} |
| 130 |
if (ImGui::Button(_("Open"))) { |
| 131 |
doAction(GUI_ACTION_SAMPLE_LIST_OPEN); |
| 132 |
} |
| 133 |
ImGui::SameLine(); |
| 134 |
ImGui::TextUnformatted(_("or")); |
| 135 |
ImGui::SameLine(); |
| 136 |
if (ImGui::Button(_("Create New"))) { |
| 137 |
doAction(GUI_ACTION_SAMPLE_LIST_ADD); |
| 138 |
} |
| 139 |
|
| 140 |
ImGui::TableNextColumn(); |
| 141 |
ImGui::EndTable(); |
| 142 |
} |
| 143 |
} else { |
| 144 |
DivSample* sample=e->song.sample[curSample]; |
| 145 |
String sampleType=_("Invalid"); |
| 146 |
if (sample->depth<DIV_SAMPLE_DEPTH_MAX) { |
| 147 |
if (sampleDepths[sample->depth]!=NULL) { |
| 148 |
sampleType=sampleDepths[sample->depth]; |
| 149 |
} |
| 150 |
} |
| 151 |
String loopType=_("Invalid"); |
| 152 |
if (sample->loopMode<DIV_SAMPLE_LOOP_MAX) { |
| 153 |
if (sampleLoopModes[sample->loopMode]!=NULL) { |
| 154 |
loopType=_(sampleLoopModes[sample->loopMode]); |
| 155 |
} |
| 156 |
} |
| 157 |
|
| 158 |
String sampleIndex=fmt::sprintf("%d",curSample); |
| 159 |
ImGui::SetNextItemWidth(72.0f*dpiScale); |
| 160 |
if (ImGui::BeginCombo("##SampleSelect",sampleIndex.c_str())) { |
| 161 |
String name; |
| 162 |
for (size_t i=0; i<e->song.sample.size(); i++) { |
| 163 |
name=fmt::sprintf("%d: %s##_SMPS%d",i,e->song.sample[i]->name,i); |
| 164 |
if (ImGui::Selectable(name.c_str(),curSample==(int)i)) { |
| 165 |
curSample=i; |
| 166 |
sample=e->song.sample[curSample]; |
| 167 |
updateSampleTex=true; |
| 168 |
} |
| 169 |
} |
| 170 |
ImGui::EndCombo(); |
| 171 |
} |
| 172 |
|
| 173 |
ImGui::SameLine(); |
| 174 |
|
| 175 |
if (ImGui::Button(ICON_FA_FOLDER_OPEN "##SELoad")) { |
| 176 |
doAction(GUI_ACTION_SAMPLE_LIST_OPEN_REPLACE); |
| 177 |
} |
| 178 |
if (ImGui::IsItemHovered()) { |
| 179 |
ImGui::SetTooltip(_("Open")); |
| 180 |
} |
| 181 |
if (ImGui::BeginPopupContextItem("SampleEOpenOpt")) { |
| 182 |
if (ImGui::MenuItem(_("import raw..."))) { |
| 183 |
doAction((curSample>=0 && curSample<(int)e->song.sample.size())?GUI_ACTION_SAMPLE_LIST_OPEN_REPLACE_RAW:GUI_ACTION_SAMPLE_LIST_OPEN_RAW); |
| 184 |
} |
| 185 |
ImGui::EndPopup(); |
| 186 |
} |
| 187 |
ImGui::SameLine(); |
| 188 |
if (ImGui::Button(ICON_FA_FLOPPY_O "##SESave")) { |
| 189 |
doAction(GUI_ACTION_SAMPLE_LIST_SAVE); |
| 190 |
} |
| 191 |
if (ImGui::IsItemHovered()) { |
| 192 |
ImGui::SetTooltip(_("Save")); |
| 193 |
} |
| 194 |
if (ImGui::BeginPopupContextItem("SampleESaveOpt")) { |
| 195 |
if (ImGui::MenuItem(_("save raw..."))) { |
| 196 |
doAction(GUI_ACTION_SAMPLE_LIST_SAVE_RAW); |
| 197 |
} |
| 198 |
ImGui::EndPopup(); |
| 199 |
} |
| 200 |
|
| 201 |
ImGui::SameLine(); |
| 202 |
|
| 203 |
ImGui::Text(_("Name")); |
| 204 |
ImGui::SameLine(); |
| 205 |
ImGui::SetNextItemWidth(ImGui::GetContentRegionAvail().x); |
| 206 |
ImGui::PushID(2+curSample); |
| 207 |
if (ImGui::InputText("##SampleName",&sample->name)) { |
| 208 |
MARK_MODIFIED; |
| 209 |
} |
| 210 |
ImGui::PopID(); |
| 211 |
|
| 212 |
ImGui::Separator(); |
| 213 |
|
| 214 |
String warnLoop, warnLoopMode, warnLoopPos; |
| 215 |
String warnLoopStart, warnLoopEnd; |
| 216 |
String warnLength, warnRate; |
| 217 |
|
| 218 |
bool isChipVisible[DIV_MAX_CHIPS]; |
| 219 |
bool isTypeVisible[DIV_MAX_SAMPLE_TYPE]; |
| 220 |
bool isMemVisible[DIV_MAX_SAMPLE_TYPE][DIV_MAX_CHIPS]; |
| 221 |
bool isMemWarning[DIV_MAX_SAMPLE_TYPE][DIV_MAX_CHIPS]; |
| 222 |
memset(isChipVisible,0,DIV_MAX_CHIPS*sizeof(bool)); |
| 223 |
memset(isTypeVisible,0,DIV_MAX_SAMPLE_TYPE*sizeof(bool)); |
| 224 |
memset(isMemVisible,0,DIV_MAX_CHIPS*DIV_MAX_SAMPLE_TYPE*sizeof(bool)); |
| 225 |
memset(isMemWarning,0,DIV_MAX_CHIPS*DIV_MAX_SAMPLE_TYPE*sizeof(bool)); |
| 226 |
|
| 227 |
bool displayLoopStartHints=false; |
| 228 |
bool displayLoopEndHints=false; |
| 229 |
|
| 230 |
for (int i=0; i<e->song.systemLen; i++) { |
| 231 |
DivDispatch* dispatch=e->getDispatch(i); |
| 232 |
|
| 233 |
// warnings |
| 234 |
switch (e->song.system[i]) { |
| 235 |
case DIV_SYSTEM_SNES: |
| 236 |
if (sample->loop) { |
| 237 |
if (sample->loopStart&15) { |
| 238 |
int tryWith=(sample->loopStart+8)&(~15); |
| 239 |
if (tryWith>(int)sample->samples) tryWith-=16; |
| 240 |
String alignHint=fmt::sprintf(_("SNES: loop start must be a multiple of 16 (try with %d)"),tryWith); |
| 241 |
SAMPLE_WARN(warnLoopStart,alignHint); |
| 242 |
} |
| 243 |
if (sample->loopEnd&15) { |
| 244 |
int tryWith=(sample->loopEnd+8)&(~15); |
| 245 |
if (tryWith>(int)sample->samples) tryWith-=16; |
| 246 |
String alignHint=fmt::sprintf(_("SNES: loop end must be a multiple of 16 (try with %d)"),tryWith); |
| 247 |
SAMPLE_WARN(warnLoopEnd,alignHint); |
| 248 |
} |
| 249 |
} |
| 250 |
if (sample->samples&15) { |
| 251 |
SAMPLE_WARN(warnLength,_("SNES: sample length will be padded to multiple of 16")); |
| 252 |
} |
| 253 |
if (dispatch!=NULL) { |
| 254 |
MAX_RATE("SNES",dispatch->chipClock/8.0); |
| 255 |
} |
| 256 |
break; |
| 257 |
case DIV_SYSTEM_QSOUND: |
| 258 |
if (sample->loop) { |
| 259 |
if (sample->depth==DIV_SAMPLE_DEPTH_QSOUND_ADPCM) { |
| 260 |
SAMPLE_WARN(warnLoop,_("QSound: ADPCM samples can't loop")); |
| 261 |
} else if (sample->loopEnd-sample->loopStart>32767) { |
| 262 |
SAMPLE_WARN(warnLoopPos,_("QSound: loop cannot be longer than 32767 samples")); |
| 263 |
} |
| 264 |
} |
| 265 |
if (sample->depth==DIV_SAMPLE_DEPTH_QSOUND_ADPCM) { |
| 266 |
if (sample->samples>131070) { |
| 267 |
SAMPLE_WARN(warnLength,"QSound: maximum ADPCM sample length is 131070"); |
| 268 |
} |
| 269 |
if (dispatch!=NULL) { |
| 270 |
EXACT_RATE("QSound (ADPCM)",dispatch->chipClock/7488.0); |
| 271 |
} |
| 272 |
} else if (sample->samples>65535) { |
| 273 |
SAMPLE_WARN(warnLength,"QSound: maximum PCM sample length is 65535"); |
| 274 |
} |
| 275 |
break; |
| 276 |
case DIV_SYSTEM_NES: { |
| 277 |
if (sample->loop) { |
| 278 |
if (sample->loopStart&511) { |
| 279 |
int tryWith=(sample->loopStart)&(~511); |
| 280 |
if (tryWith>(int)sample->samples) tryWith-=512; |
| 281 |
String alignHint=fmt::sprintf(_("NES: loop start must be a multiple of 512 (try with %d)"),tryWith); |
| 282 |
SAMPLE_WARN(warnLoopStart,alignHint); |
| 283 |
} |
| 284 |
if ((sample->loopEnd-8)&127) { |
| 285 |
int tryWith=(sample->loopEnd-8)&(~127); |
| 286 |
if (tryWith>(int)sample->samples) tryWith-=128; |
| 287 |
tryWith+=8; // +1 bc of how sample length is treated: https://www.nesdev.org/wiki/APU_DMC |
| 288 |
String alignHint=fmt::sprintf(_("NES: loop end must be a multiple of 128 + 8 (try with %d)"),tryWith); |
| 289 |
SAMPLE_WARN(warnLoopEnd,alignHint); |
| 290 |
} |
| 291 |
} |
| 292 |
if (sample->samples>32648) { |
| 293 |
SAMPLE_WARN(warnLength,_("NES: maximum DPCM sample length is 32648")); |
| 294 |
} |
| 295 |
break; |
| 296 |
} |
| 297 |
case DIV_SYSTEM_X1_010: |
| 298 |
if (sample->loop) { |
| 299 |
SAMPLE_WARN(warnLoop,_("X1-010: samples can't loop")); |
| 300 |
} |
| 301 |
if (sample->samples>131072) { |
| 302 |
SAMPLE_WARN(warnLength,_("X1-010: maximum bankswitched sample length is 131072")); |
| 303 |
} |
| 304 |
break; |
| 305 |
case DIV_SYSTEM_GA20: |
| 306 |
if (sample->loop) { |
| 307 |
SAMPLE_WARN(warnLoop,_("GA20: samples can't loop")); |
| 308 |
} |
| 309 |
if (dispatch!=NULL) { |
| 310 |
MIN_RATE("GA20",dispatch->chipClock/1024); |
| 311 |
} |
| 312 |
break; |
| 313 |
case DIV_SYSTEM_YM2608: |
| 314 |
case DIV_SYSTEM_YM2608_EXT: |
| 315 |
case DIV_SYSTEM_YM2608_CSM: |
| 316 |
if (sample->loop) { |
| 317 |
if (sample->loopStart!=0 || sample->loopEnd!=(int)(sample->samples)) { |
| 318 |
SAMPLE_WARN(warnLoopPos,_("YM2608: loop point ignored on ADPCM (may only loop entire sample)")); |
| 319 |
} |
| 320 |
if (sample->samples&511) { |
| 321 |
SAMPLE_WARN(warnLength,_("YM2608: sample length will be padded to multiple of 512")); |
| 322 |
} |
| 323 |
} |
| 324 |
if (dispatch!=NULL) { |
| 325 |
MAX_RATE("YM2608",dispatch->chipClock/144); |
| 326 |
} |
| 327 |
break; |
| 328 |
case DIV_SYSTEM_YM2610_FULL: |
| 329 |
case DIV_SYSTEM_YM2610_FULL_EXT: |
| 330 |
case DIV_SYSTEM_YM2610_CSM: |
| 331 |
case DIV_SYSTEM_YM2610B: |
| 332 |
case DIV_SYSTEM_YM2610B_EXT: |
| 333 |
if (sample->loop) { |
| 334 |
if (sample->depth==DIV_SAMPLE_DEPTH_ADPCM_A) { |
| 335 |
SAMPLE_WARN(warnLoop,_("YM2610: ADPCM-A samples can't loop")); |
| 336 |
} else { |
| 337 |
if (sample->loopStart!=0 || sample->loopEnd!=(int)(sample->samples)) { |
| 338 |
SAMPLE_WARN(warnLoopPos,_("YM2610: loop point ignored on ADPCM-B (may only loop entire sample)")); |
| 339 |
} |
| 340 |
} |
| 341 |
if (sample->samples&511) { |
| 342 |
SAMPLE_WARN(warnLength,_("YM2610: sample length will be padded to multiple of 512")); |
| 343 |
} |
| 344 |
} |
| 345 |
if (sample->samples>2097152) { |
| 346 |
SAMPLE_WARN(warnLength,_("YM2610: maximum ADPCM-A sample length is 2097152")); |
| 347 |
} |
| 348 |
if (dispatch!=NULL) { |
| 349 |
if (sample->depth==DIV_SAMPLE_DEPTH_ADPCM_A) { |
| 350 |
EXACT_RATE("YM2610 (ADPCM-A)",dispatch->chipClock/432); |
| 351 |
} else { |
| 352 |
MAX_RATE("YM2610 (ADPCM-B)",dispatch->chipClock/144); |
| 353 |
} |
| 354 |
} |
| 355 |
break; |
| 356 |
case DIV_SYSTEM_Y8950: |
| 357 |
if (sample->loop) { |
| 358 |
if (sample->loopStart!=0 || sample->loopEnd!=(int)(sample->samples)) { |
| 359 |
SAMPLE_WARN(warnLoopPos,_("Y8950: loop point ignored on ADPCM (may only loop entire sample)")); |
| 360 |
} |
| 361 |
if (sample->samples&511) { |
| 362 |
SAMPLE_WARN(warnLength,_("Y8950: sample length will be padded to multiple of 512")); |
| 363 |
} |
| 364 |
} |
| 365 |
if (dispatch!=NULL) { |
| 366 |
MAX_RATE("Y8950",dispatch->chipClock/72); |
| 367 |
} |
| 368 |
break; |
| 369 |
case DIV_SYSTEM_AMIGA: |
| 370 |
if (sample->loop) { |
| 371 |
if (sample->loopStart&1) { |
| 372 |
SAMPLE_WARN(warnLoopStart,_("Amiga: loop start must be a multiple of 2")); |
| 373 |
} |
| 374 |
if (sample->loopEnd&1) { |
| 375 |
SAMPLE_WARN(warnLoopEnd,_("Amiga: loop end must be a multiple of 2")); |
| 376 |
} |
| 377 |
} |
| 378 |
if (sample->samples>131070) { |
| 379 |
SAMPLE_WARN(warnLength,_("Amiga: maximum sample length is 131070")); |
| 380 |
} |
| 381 |
if (dispatch!=NULL) { |
| 382 |
MAX_RATE("Amiga",31250.0); |
| 383 |
} |
| 384 |
break; |
| 385 |
case DIV_SYSTEM_SEGAPCM: |
| 386 |
case DIV_SYSTEM_SEGAPCM_COMPAT: |
| 387 |
if (sample->samples>65280) { |
| 388 |
SAMPLE_WARN(warnLength,_("SegaPCM: maximum sample length is 65280")); |
| 389 |
} |
| 390 |
if (dispatch!=NULL) { |
| 391 |
MAX_RATE("SegaPCM",dispatch->rate); |
| 392 |
} |
| 393 |
break; |
| 394 |
case DIV_SYSTEM_K007232: |
| 395 |
if (sample->samples>131071) { |
| 396 |
SAMPLE_WARN(warnLength,_("K007232: maximum sample length is 131071")); |
| 397 |
} |
| 398 |
break; |
| 399 |
case DIV_SYSTEM_K053260: |
| 400 |
if (sample->loop) { |
| 401 |
if (sample->loopStart!=0 || sample->loopEnd!=(int)(sample->samples)) { |
| 402 |
SAMPLE_WARN(warnLoopPos,_("K053260: loop point ignored (may only loop entire sample)")); |
| 403 |
} |
| 404 |
} |
| 405 |
if (sample->samples>65535) { |
| 406 |
SAMPLE_WARN(warnLength,_("K053260: maximum sample length is 65535")); |
| 407 |
} |
| 408 |
break; |
| 409 |
case DIV_SYSTEM_C140: |
| 410 |
if (sample->samples>65535) { |
| 411 |
SAMPLE_WARN(warnLength,_("C140: maximum sample length is 65535")); |
| 412 |
} |
| 413 |
if (dispatch!=NULL) { |
| 414 |
MAX_RATE("C140",dispatch->rate); |
| 415 |
} |
| 416 |
break; |
| 417 |
case DIV_SYSTEM_C219: |
| 418 |
if (sample->loop) { |
| 419 |
if (sample->loopStart&1) { |
| 420 |
SAMPLE_WARN(warnLoopStart,_("C219: loop start must be a multiple of 2")); |
| 421 |
} |
| 422 |
if (sample->loopEnd&1) { |
| 423 |
SAMPLE_WARN(warnLoopEnd,_("C219: loop end must be a multiple of 2")); |
| 424 |
} |
| 425 |
} |
| 426 |
if (sample->samples>131072) { |
| 427 |
SAMPLE_WARN(warnLength,_("C219: maximum sample length is 131072")); |
| 428 |
} |
| 429 |
if (dispatch!=NULL) { |
| 430 |
MAX_RATE("C219",dispatch->rate); |
| 431 |
} |
| 432 |
break; |
| 433 |
case DIV_SYSTEM_MSM6295: |
| 434 |
if (sample->loop) { |
| 435 |
SAMPLE_WARN(warnLoop,_("MSM6295: samples can't loop")); |
| 436 |
} |
| 437 |
if (sample->samples>129024) { |
| 438 |
SAMPLE_WARN(warnLength,_("MSM6295: maximum bankswitched sample length is 129024")); |
| 439 |
} |
| 440 |
if (dispatch!=NULL) { |
| 441 |
EXACT_2RATES("MSM6295",dispatch->chipClock/165,dispatch->chipClock/132); |
| 442 |
} |
| 443 |
break; |
| 444 |
case DIV_SYSTEM_GBA_DMA: |
| 445 |
if (sample->loop) { |
| 446 |
if (sample->loopStart&3) { |
| 447 |
SAMPLE_WARN(warnLoopStart,_("GBA DMA: loop start must be a multiple of 4")); |
| 448 |
} |
| 449 |
if ((sample->loopEnd-sample->loopStart)&15) { |
| 450 |
SAMPLE_WARN(warnLoopEnd,_("GBA DMA: loop length must be a multiple of 16")); |
| 451 |
} |
| 452 |
} |
| 453 |
if (sample->samples&15) { |
| 454 |
SAMPLE_WARN(warnLength,_("GBA DMA: sample length will be padded to multiple of 16")); |
| 455 |
} |
| 456 |
break; |
| 457 |
case DIV_SYSTEM_OPL4: |
| 458 |
case DIV_SYSTEM_OPL4_DRUMS: |
| 459 |
if (sample->samples>65535) { |
| 460 |
SAMPLE_WARN(warnLength,_("OPL4: maximum sample length is 65535")); |
| 461 |
} |
| 462 |
break; |
| 463 |
case DIV_SYSTEM_SUPERVISION: |
| 464 |
if (sample->loop) { |
| 465 |
if (sample->loopStart!=0 || sample->loopEnd!=(int)(sample->samples)) { |
| 466 |
SAMPLE_WARN(warnLoopPos,_("Supervision: loop point ignored on sample channel")); |
| 467 |
} |
| 468 |
} |
| 469 |
if (sample->samples&31) { |
| 470 |
SAMPLE_WARN(warnLength,_("Supervision: sample length will be padded to multiple of 32")); |
| 471 |
} |
| 472 |
if (sample->samples>8192) { |
| 473 |
SAMPLE_WARN(warnLength,_("Supervision: maximum sample length is 8192")); |
| 474 |
} |
| 475 |
break; |
| 476 |
case DIV_SYSTEM_YMZ280B: |
| 477 |
if (sample->depth==DIV_SAMPLE_DEPTH_YMZ_ADPCM) { |
| 478 |
if (sample->loop) { |
| 479 |
if (sample->loopStart&1) { |
| 480 |
SAMPLE_WARN(warnLoopStart,_("YMZ280B: loop start on ADPCM must be a multiple of 2")); |
| 481 |
} |
| 482 |
if (sample->loopEnd&1) { |
| 483 |
SAMPLE_WARN(warnLoopEnd,_("YMZ280B: loop end on ADPCM must be a multiple of 2")); |
| 484 |
} |
| 485 |
} |
| 486 |
if (dispatch!=NULL) { |
| 487 |
MAX_RATE("YMZ280B (ADPCM)",dispatch->rate); |
| 488 |
} |
| 489 |
} else { |
| 490 |
if (dispatch!=NULL) { |
| 491 |
MAX_RATE("YMZ280B (PCM)",dispatch->chipClock/192); |
| 492 |
} |
| 493 |
} |
| 494 |
break; |
| 495 |
case DIV_SYSTEM_NDS: |
| 496 |
switch (sample->depth) { |
| 497 |
case DIV_SAMPLE_DEPTH_IMA_ADPCM: |
| 498 |
if (sample->loop) { |
| 499 |
if (sample->loopStart&7) { |
| 500 |
SAMPLE_WARN(warnLoopStart,_("NDS: loop start on ADPCM must be a multiple of 8")); |
| 501 |
} |
| 502 |
if (sample->loopEnd&7) { |
| 503 |
SAMPLE_WARN(warnLoopEnd,_("NDS: loop end on ADPCM must be a multiple of 8")); |
| 504 |
} |
| 505 |
if (sample->loopStart>524280) { |
| 506 |
SAMPLE_WARN(warnLoopStart,_("NDS: loop start cannot be longer than 524280 samples on ADPCM")); |
| 507 |
} |
| 508 |
if ((sample->loopEnd-sample->loopStart)>33554424) { |
| 509 |
SAMPLE_WARN(warnLoopPos,_("NDS: maximum ADPCM loop length is 33554424")); |
| 510 |
} |
| 511 |
} else { |
| 512 |
if (sample->samples>33554424) { |
| 513 |
SAMPLE_WARN(warnLength,_("NDS: maximum ADPCM sample length is 33554424")); |
| 514 |
} |
| 515 |
} |
| 516 |
break; |
| 517 |
case DIV_SAMPLE_DEPTH_8BIT: |
| 518 |
if (sample->loop) { |
| 519 |
if (sample->loopStart&3) { |
| 520 |
SAMPLE_WARN(warnLoopStart,_("NDS: loop start on 8 bit PCM must be a multiple of 4")); |
| 521 |
} |
| 522 |
if (sample->loopEnd&3) { |
| 523 |
SAMPLE_WARN(warnLoopEnd,_("NDS: loop end on 8 bit PCM must be a multiple of 4")); |
| 524 |
} |
| 525 |
if (sample->loopStart>262140) { |
| 526 |
SAMPLE_WARN(warnLoopStart,_("NDS: loop start cannot be longer than 262140 samples on 8 bit PCM")); |
| 527 |
} |
| 528 |
if ((sample->loopEnd-sample->loopStart)>16777212) { |
| 529 |
SAMPLE_WARN(warnLoopPos,_("NDS: maximum 8 bit PCM loop length is 16777212")); |
| 530 |
} |
| 531 |
} else { |
| 532 |
if (sample->samples>16777212) { |
| 533 |
SAMPLE_WARN(warnLength,_("NDS: maximum 8 bit PCM sample length is 16777212")); |
| 534 |
} |
| 535 |
} |
| 536 |
break; |
| 537 |
case DIV_SAMPLE_DEPTH_16BIT: |
| 538 |
if (sample->loop) { |
| 539 |
if (sample->loopStart&1) { |
| 540 |
SAMPLE_WARN(warnLoopStart,_("NDS: loop start on 16 bit PCM must be a multiple of 2")); |
| 541 |
} |
| 542 |
if (sample->loopEnd&1) { |
| 543 |
SAMPLE_WARN(warnLoopEnd,_("NDS: loop end on 16 bit PCM must be a multiple of 2")); |
| 544 |
} |
| 545 |
if (sample->loopStart>131070) { |
| 546 |
SAMPLE_WARN(warnLoopStart,_("NDS: loop start cannot be longer than 131070 samples on 16 bit PCM")); |
| 547 |
} |
| 548 |
if ((sample->loopEnd-sample->loopStart)>8388606) { |
| 549 |
SAMPLE_WARN(warnLoopPos,_("NDS: maximum 16 bit PCM loop length is 8388606")); |
| 550 |
} |
| 551 |
} else { |
| 552 |
if (sample->samples>8388606) { |
| 553 |
SAMPLE_WARN(warnLength,_("NDS: maximum 16 bit PCM sample length is 8388606")); |
| 554 |
} |
| 555 |
} |
| 556 |
break; |
| 557 |
default: |
| 558 |
break; |
| 559 |
} |
| 560 |
break; |
| 561 |
case DIV_SYSTEM_ES5506: |
| 562 |
if (sample->samples>2097024) { |
| 563 |
SAMPLE_WARN(warnLength,_("ES5506: maximum sample length is 2097024")); |
| 564 |
} |
| 565 |
break; |
| 566 |
default: |
| 567 |
break; |
| 568 |
} |
| 569 |
if (e->song.system[i]!=DIV_SYSTEM_PCM_DAC) { |
| 570 |
if (e->song.system[i]==DIV_SYSTEM_ES5506) { |
| 571 |
if (sample->loopMode==DIV_SAMPLE_LOOP_BACKWARD) { |
| 572 |
SAMPLE_WARN(warnLoopMode,_("ES5506: backward loop mode isn't supported")); |
| 573 |
} |
| 574 |
} else if (sample->loopMode!=DIV_SAMPLE_LOOP_FORWARD) { |
| 575 |
SAMPLE_WARN(warnLoopMode,_("backward/ping-pong only supported in Generic PCM DAC\nping-pong also on ES5506")); |
| 576 |
} |
| 577 |
} |
| 578 |
|
| 579 |
// chips grid |
| 580 |
if (dispatch==NULL) continue; |
| 581 |
|
| 582 |
for (int j=0; j<DIV_MAX_SAMPLE_TYPE; j++) { |
| 583 |
if (dispatch->getSampleMemCapacity(j)==0) continue; |
| 584 |
isChipVisible[i]=true; |
| 585 |
isTypeVisible[j]=true; |
| 586 |
isMemVisible[j][i]=true; |
| 587 |
if (!dispatch->isSampleLoaded(j,curSample)) isMemWarning[j][i]=true; |
| 588 |
} |
| 589 |
} |
| 590 |
|
| 591 |
int selColumns=1; |
| 592 |
for (int i=0; i<DIV_MAX_CHIPS; i++) { |
| 593 |
if (isChipVisible[i]) selColumns++; |
| 594 |
} |
| 595 |
|
| 596 |
int targetRate=sampleCompatRate?sample->rate:sample->centerRate; |
| 597 |
|
| 598 |
if (ImGui::BeginTable("SampleProps",(selColumns>1)?4:3,ImGuiTableFlags_SizingStretchSame|ImGuiTableFlags_BordersV|ImGuiTableFlags_BordersOuterH)) { |
| 599 |
ImGui::TableNextRow(ImGuiTableRowFlags_Headers); |
| 600 |
ImGui::TableNextColumn(); |
| 601 |
if (ImGui::Button(sampleInfo?(ICON_FA_CHEVRON_UP "##SECollapse"):(ICON_FA_CHEVRON_DOWN "##SECollapse"))) { |
| 602 |
sampleInfo=!sampleInfo; |
| 603 |
} |
| 604 |
ImGui::SameLine(); |
| 605 |
ImGui::Text(_("Info")); |
| 606 |
ImGui::TableNextColumn(); |
| 607 |
pushToggleColors(!sampleCompatRate); |
| 608 |
if (ImGui::Button(_("Rate"))) { |
| 609 |
sampleCompatRate=false; |
| 610 |
} |
| 611 |
popToggleColors(); |
| 612 |
ImGui::SameLine(); |
| 613 |
pushToggleColors(sampleCompatRate); |
| 614 |
if (ImGui::Button(_("Compat Rate"))) { |
| 615 |
sampleCompatRate=true; |
| 616 |
} |
| 617 |
if (ImGui::IsItemHovered()) { |
| 618 |
ImGui::SetTooltip(_("used in DefleMask-compatible sample mode (17xx), in where samples are mapped to an octave.")); |
| 619 |
} |
| 620 |
popToggleColors(); |
| 621 |
ImGui::TableNextColumn(); |
| 622 |
bool doLoop=(sample->loop); |
| 623 |
pushWarningColor(!warnLoop.empty()); |
| 624 |
String loopCheckboxName=(doLoop && (sample->loopEnd-sample->loopStart)>0)?fmt::sprintf(_("Loop (length: %d)##Loop"),sample->loopEnd-sample->loopStart):String(_("Loop")); |
| 625 |
if (ImGui::Checkbox(loopCheckboxName.c_str(),&doLoop)) { MARK_MODIFIED |
| 626 |
if (doLoop) { |
| 627 |
sample->loop=true; |
| 628 |
if (sample->loopStart<0) { |
| 629 |
sample->loopStart=0; |
| 630 |
} |
| 631 |
if (sample->loopEnd<0) { |
| 632 |
sample->loopEnd=sample->samples; |
| 633 |
} |
| 634 |
} else { |
| 635 |
sample->loop=false; |
| 636 |
/* |
| 637 |
sample->loopStart=-1; |
| 638 |
sample->loopEnd=sample->samples;*/ |
| 639 |
} |
| 640 |
updateSampleTex=true; |
| 641 |
if (e->getSampleFormatMask()&(1U<<DIV_SAMPLE_DEPTH_BRR)) { |
| 642 |
e->renderSamplesP(curSample); |
| 643 |
} |
| 644 |
} |
| 645 |
popWarningColor(); |
| 646 |
if (ImGui::IsItemHovered() && (!warnLoop.empty() || sample->depth==DIV_SAMPLE_DEPTH_BRR)) { |
| 647 |
if (sample->depth==DIV_SAMPLE_DEPTH_BRR) { |
| 648 |
SAMPLE_WARN(warnLoop,_("changing the loop in a BRR sample may result in glitches!")); |
| 649 |
} |
| 650 |
ImGui::SetTooltip("%s",warnLoop.c_str()); |
| 651 |
} |
| 652 |
|
| 653 |
if (selColumns>1) { |
| 654 |
ImGui::TableNextColumn(); |
| 655 |
ImGui::Text(_("Chips")); |
| 656 |
} |
| 657 |
|
| 658 |
if (sampleInfo) { |
| 659 |
ImGui::TableNextRow(); |
| 660 |
ImGui::TableNextColumn(); |
| 661 |
ImGui::AlignTextToFramePadding(); |
| 662 |
ImGui::Text(_("Type")); |
| 663 |
ImGui::SameLine(); |
| 664 |
ImGui::SetNextItemWidth(ImGui::GetContentRegionAvail().x); |
| 665 |
if (ImGui::BeginCombo("##SampleType",sampleType.c_str())) { |
| 666 |
for (int i=0; i<DIV_SAMPLE_DEPTH_MAX; i++) { |
| 667 |
if (sampleDepths[i]==NULL) continue; |
| 668 |
if (ImGui::Selectable(sampleDepths[i])) { |
| 669 |
sample->prepareUndo(true); |
| 670 |
e->lockEngine([this,sample,i]() { |
| 671 |
sample->convert((DivSampleDepth)i,e->getSampleFormatMask()); |
| 672 |
e->renderSamples(curSample); |
| 673 |
}); |
| 674 |
updateSampleTex=true; |
| 675 |
MARK_MODIFIED; |
| 676 |
} |
| 677 |
} |
| 678 |
ImGui::EndCombo(); |
| 679 |
} |
| 680 |
|
| 681 |
bool isThereSNES=false; |
| 682 |
for (int i=0; i<e->song.systemLen; i++) { |
| 683 |
if (e->song.system[i]==DIV_SYSTEM_SNES) { |
| 684 |
isThereSNES=true; |
| 685 |
break; |
| 686 |
} |
| 687 |
} |
| 688 |
if (sample->depth==DIV_SAMPLE_DEPTH_BRR || isThereSNES) { |
| 689 |
bool be=sample->brrEmphasis; |
| 690 |
if (ImGui::Checkbox(_("BRR emphasis"),&be)) { |
| 691 |
sample->prepareUndo(true); |
| 692 |
sample->brrEmphasis=be; |
| 693 |
e->renderSamplesP(curSample); |
| 694 |
updateSampleTex=true; |
| 695 |
MARK_MODIFIED; |
| 696 |
} |
| 697 |
if (ImGui::IsItemHovered()) { |
| 698 |
if (sample->depth==DIV_SAMPLE_DEPTH_BRR) { |
| 699 |
ImGui::SetTooltip(_("this is a BRR sample.\nenabling this option will muffle it (only affects non-SNES chips).")); |
| 700 |
} else { |
| 701 |
ImGui::SetTooltip(_("enable this option to slightly boost high frequencies\nto compensate for the SNES' Gaussian filter's muffle.")); |
| 702 |
} |
| 703 |
} |
| 704 |
} |
| 705 |
if (sample->depth!=DIV_SAMPLE_DEPTH_BRR && isThereSNES) { |
| 706 |
bool bf=sample->brrNoFilter; |
| 707 |
if (ImGui::Checkbox(_("no BRR filters"),&bf)) { |
| 708 |
sample->prepareUndo(true); |
| 709 |
sample->brrNoFilter=bf; |
| 710 |
e->renderSamplesP(curSample); |
| 711 |
updateSampleTex=true; |
| 712 |
MARK_MODIFIED; |
| 713 |
} |
| 714 |
if (ImGui::IsItemHovered()) { |
| 715 |
ImGui::SetTooltip(_("enable this option to not use BRR blocks with filters\nand allow sample offset commands to be used safely.")); |
| 716 |
} |
| 717 |
} |
| 718 |
if (sample->depth!=DIV_SAMPLE_DEPTH_8BIT && e->getSampleFormatMask()&(1L<<DIV_SAMPLE_DEPTH_8BIT)) { |
| 719 |
bool di=sample->dither; |
| 720 |
if (ImGui::Checkbox(_("8-bit dither"),&di)) { |
| 721 |
sample->prepareUndo(true); |
| 722 |
sample->dither=di; |
| 723 |
e->renderSamplesP(curSample); |
| 724 |
updateSampleTex=true; |
| 725 |
MARK_MODIFIED; |
| 726 |
} |
| 727 |
if (ImGui::IsItemHovered()) { |
| 728 |
ImGui::SetTooltip(_("dither the sample when used on a chip that only supports 8-bit samples.")); |
| 729 |
} |
| 730 |
} |
| 731 |
|
| 732 |
int sampleNote=round(64.0+(128.0*12.0*log((double)targetRate/e->getCenterRate())/log(2.0))); |
| 733 |
int sampleNoteCoarse=60+(sampleNote>>7); |
| 734 |
int sampleNoteFine=(sampleNote&127)-64; |
| 735 |
|
| 736 |
if (sampleNoteCoarse<0) { |
| 737 |
sampleNoteCoarse=0; |
| 738 |
sampleNoteFine=-64; |
| 739 |
} |
| 740 |
if (sampleNoteCoarse>119) { |
| 741 |
sampleNoteCoarse=119; |
| 742 |
sampleNoteFine=63; |
| 743 |
} |
| 744 |
|
| 745 |
bool coarseChanged=false; |
| 746 |
|
| 747 |
ImGui::TableNextColumn(); |
| 748 |
ImGui::AlignTextToFramePadding(); |
| 749 |
ImGui::Text("Hz"); |
| 750 |
ImGui::SameLine(); |
| 751 |
ImGui::SetNextItemWidth(ImGui::GetContentRegionAvail().x); |
| 752 |
if (ImGui::InputInt("##SampleRate",&targetRate,10,200)) { MARK_MODIFIED |
| 753 |
if (targetRate<100) targetRate=100; |
| 754 |
if (targetRate>384000) targetRate=384000; |
| 755 |
|
| 756 |
if (sampleCompatRate) { |
| 757 |
sample->rate=targetRate; |
| 758 |
} else { |
| 759 |
sample->centerRate=targetRate; |
| 760 |
} |
| 761 |
} |
| 762 |
|
| 763 |
ImGui::AlignTextToFramePadding(); |
| 764 |
ImGui::Text(_("Note")); |
| 765 |
ImGui::SameLine(); |
| 766 |
ImGui::SetNextItemWidth(ImGui::GetContentRegionAvail().x); |
| 767 |
if (ImGui::BeginCombo("##SampleNote",noteNames[sampleNoteCoarse+60])) { |
| 768 |
char temp[1024]; |
| 769 |
for (int i=0; i<120; i++) { |
| 770 |
snprintf(temp,1023,"%s##_SRN%d",noteNames[i+60],i); |
| 771 |
if (ImGui::Selectable(temp,i==sampleNoteCoarse)) { |
| 772 |
sampleNoteCoarse=i; |
| 773 |
coarseChanged=true; |
| 774 |
} |
| 775 |
if (i==sampleNoteCoarse) ImGui::SetItemDefaultFocus(); |
| 776 |
} |
| 777 |
ImGui::EndCombo(); |
| 778 |
} else if (ImGui::IsItemHovered()) { |
| 779 |
if (wheelY!=0) { |
| 780 |
sampleNoteCoarse-=wheelY; |
| 781 |
if (sampleNoteCoarse<0) { |
| 782 |
sampleNoteCoarse=0; |
| 783 |
sampleNoteFine=-64; |
| 784 |
} |
| 785 |
if (sampleNoteCoarse>119) { |
| 786 |
sampleNoteCoarse=119; |
| 787 |
sampleNoteFine=63; |
| 788 |
} |
| 789 |
coarseChanged=true; |
| 790 |
} |
| 791 |
} |
| 792 |
|
| 793 |
if (coarseChanged) { MARK_MODIFIED |
| 794 |
sampleNote=((sampleNoteCoarse-60)<<7)+sampleNoteFine; |
| 795 |
|
| 796 |
targetRate=e->getCenterRate()*pow(2.0,(double)sampleNote/(128.0*12.0)); |
| 797 |
if (targetRate<100) targetRate=100; |
| 798 |
if (targetRate>384000) targetRate=384000; |
| 799 |
|
| 800 |
if (sampleCompatRate) { |
| 801 |
sample->rate=targetRate; |
| 802 |
} else { |
| 803 |
sample->centerRate=targetRate; |
| 804 |
} |
| 805 |
} |
| 806 |
|
| 807 |
ImGui::AlignTextToFramePadding(); |
| 808 |
ImGui::Text("Fine"); |
| 809 |
ImGui::SameLine(); |
| 810 |
ImGui::SetNextItemWidth(ImGui::GetContentRegionAvail().x); |
| 811 |
int prevFine=sampleNoteFine; |
| 812 |
int prevSampleRate=targetRate; |
| 813 |
if (ImGui::InputInt("##SampleFine",&sampleNoteFine,1,10)) { MARK_MODIFIED |
| 814 |
if (sampleNoteFine>63) sampleNoteFine=63; |
| 815 |
if (sampleNoteFine<-64) sampleNoteFine=-64; |
| 816 |
|
| 817 |
sampleNote=((sampleNoteCoarse-60)<<7)+sampleNoteFine; |
| 818 |
|
| 819 |
targetRate=round(e->getCenterRate()*pow(2.0,(double)sampleNote/(128.0*12.0))); |
| 820 |
|
| 821 |
if (targetRate==prevSampleRate) { |
| 822 |
if (prevFine==sampleNoteFine) { |
| 823 |
// do nothing |
| 824 |
} else if (prevFine>sampleNoteFine) { // coarse incr/decr due to precision loss |
| 825 |
targetRate--; |
| 826 |
} else { |
| 827 |
targetRate++; |
| 828 |
} |
| 829 |
} |
| 830 |
|
| 831 |
if (targetRate<100) targetRate=100; |
| 832 |
if (targetRate>384000) targetRate=384000; |
| 833 |
|
| 834 |
if (sampleCompatRate) { |
| 835 |
sample->rate=targetRate; |
| 836 |
} else { |
| 837 |
sample->centerRate=targetRate; |
| 838 |
} |
| 839 |
} |
| 840 |
|
| 841 |
ImGui::TableNextColumn(); |
| 842 |
ImGui::BeginDisabled(!(doLoop || keepLoopAlive)); |
| 843 |
keepLoopAlive=false; |
| 844 |
ImGui::AlignTextToFramePadding(); |
| 845 |
ImGui::Text("Mode"); |
| 846 |
ImGui::SameLine(); |
| 847 |
pushWarningColor(!warnLoopMode.empty()); |
| 848 |
ImGui::SetNextItemWidth(ImGui::GetContentRegionAvail().x); |
| 849 |
if (ImGui::BeginCombo("##SampleLoopMode",loopType.c_str())) { |
| 850 |
for (int i=0; i<DIV_SAMPLE_LOOP_MAX; i++) { |
| 851 |
if (sampleLoopModes[i]==NULL) continue; |
| 852 |
if (ImGui::Selectable(sampleLoopModes[i])) { |
| 853 |
sample->prepareUndo(true); |
| 854 |
sample->loopMode=(DivSampleLoopMode)i; |
| 855 |
e->renderSamplesP(curSample); |
| 856 |
updateSampleTex=true; |
| 857 |
MARK_MODIFIED; |
| 858 |
} |
| 859 |
} |
| 860 |
ImGui::EndCombo(); |
| 861 |
} |
| 862 |
if (ImGui::IsItemHovered() && !warnLoopMode.empty()) { |
| 863 |
ImGui::SetTooltip("%s",warnLoopMode.c_str()); |
| 864 |
} |
| 865 |
popWarningColor(); |
| 866 |
|
| 867 |
pushWarningColor(!warnLoopPos.empty() || (!warnLoopStart.empty() && sampleCheckLoopStart)); |
| 868 |
ImGui::AlignTextToFramePadding(); |
| 869 |
ImGui::Text(_("Start")); |
| 870 |
ImGui::SameLine(); |
| 871 |
ImGui::SetNextItemWidth(ImGui::GetContentRegionAvail().x); |
| 872 |
if (ImGui::InputInt("##LoopStartPosition",&sample->loopStart,1,16)) { MARK_MODIFIED |
| 873 |
if (sample->loopStart<0) { |
| 874 |
sample->loopStart=0; |
| 875 |
} |
| 876 |
if (sample->loopStart>sample->loopEnd) { |
| 877 |
sample->loopStart=sample->loopEnd; |
| 878 |
} |
| 879 |
updateSampleTex=true; |
| 880 |
if (e->getSampleFormatMask()&(1U<<DIV_SAMPLE_DEPTH_BRR)) { |
| 881 |
e->renderSamplesP(curSample); |
| 882 |
} |
| 883 |
} |
| 884 |
if (ImGui::IsItemActive()) { |
| 885 |
keepLoopAlive=true; |
| 886 |
sampleCheckLoopStart=false; |
| 887 |
displayLoopStartHints=true; |
| 888 |
} else { |
| 889 |
sampleCheckLoopStart=true; |
| 890 |
} |
| 891 |
if (ImGui::IsItemHovered()) { |
| 892 |
displayLoopStartHints=true; |
| 893 |
} |
| 894 |
if (ImGui::IsItemHovered() && (!warnLoopPos.empty() || (!warnLoopStart.empty() && sampleCheckLoopStart) || sample->depth==DIV_SAMPLE_DEPTH_BRR)) { |
| 895 |
if (ImGui::BeginTooltip()) { |
| 896 |
if (sample->depth==DIV_SAMPLE_DEPTH_BRR) { |
| 897 |
ImGui::Text(_("changing the loop in a BRR sample may result in glitches!")); |
| 898 |
} |
| 899 |
if (!warnLoopStart.empty()) { |
| 900 |
ImGui::Text("%s",warnLoopStart.c_str()); |
| 901 |
} |
| 902 |
if (!warnLoopPos.empty()) { |
| 903 |
ImGui::Text("%s",warnLoopPos.c_str()); |
| 904 |
} |
| 905 |
ImGui::EndTooltip(); |
| 906 |
} |
| 907 |
} |
| 908 |
popWarningColor(); |
| 909 |
|
| 910 |
pushWarningColor(!warnLoopPos.empty() || (!warnLoopEnd.empty() && sampleCheckLoopEnd)); |
| 911 |
ImGui::AlignTextToFramePadding(); |
| 912 |
ImGui::Text(_("End")); |
| 913 |
ImGui::SameLine(); |
| 914 |
ImGui::SetNextItemWidth(ImGui::GetContentRegionAvail().x); |
| 915 |
if (ImGui::InputInt("##LoopEndPosition",&sample->loopEnd,1,16)) { MARK_MODIFIED |
| 916 |
if (sample->loopEnd<sample->loopStart) { |
| 917 |
sample->loopEnd=sample->loopStart; |
| 918 |
} |
| 919 |
if (sample->loopEnd>=(int)sample->samples) { |
| 920 |
sample->loopEnd=sample->samples; |
| 921 |
} |
| 922 |
updateSampleTex=true; |
| 923 |
if (e->getSampleFormatMask()&(1U<<DIV_SAMPLE_DEPTH_BRR)) { |
| 924 |
e->renderSamplesP(curSample); |
| 925 |
} |
| 926 |
} |
| 927 |
if (ImGui::IsItemActive()) { |
| 928 |
keepLoopAlive=true; |
| 929 |
sampleCheckLoopEnd=false; |
| 930 |
displayLoopEndHints=true; |
| 931 |
} else { |
| 932 |
sampleCheckLoopEnd=true; |
| 933 |
} |
| 934 |
if (ImGui::IsItemHovered()) { |
| 935 |
displayLoopEndHints=true; |
| 936 |
} |
| 937 |
if (ImGui::IsItemHovered() && (!warnLoopPos.empty() || (!warnLoopEnd.empty() && sampleCheckLoopEnd) || sample->depth==DIV_SAMPLE_DEPTH_BRR)) { |
| 938 |
if (ImGui::BeginTooltip()) { |
| 939 |
if (sample->depth==DIV_SAMPLE_DEPTH_BRR) { |
| 940 |
ImGui::Text(_("changing the loop in a BRR sample may result in glitches!")); |
| 941 |
} |
| 942 |
if (!warnLoopEnd.empty()) { |
| 943 |
ImGui::Text("%s",warnLoopEnd.c_str()); |
| 944 |
} |
| 945 |
if (!warnLoopPos.empty()) { |
| 946 |
ImGui::Text("%s",warnLoopPos.c_str()); |
| 947 |
} |
| 948 |
ImGui::EndTooltip(); |
| 949 |
} |
| 950 |
} |
| 951 |
popWarningColor(); |
| 952 |
ImGui::EndDisabled(); |
| 953 |
|
| 954 |
if (selColumns>1) { |
| 955 |
ImGui::TableNextColumn(); |
| 956 |
if (ImGui::BeginTable("SEChipSel",selColumns,ImGuiTableFlags_SizingFixedSame)) { |
| 957 |
ImGui::TableNextRow(); |
| 958 |
ImGui::TableNextColumn(); |
| 959 |
for (int i=0; i<e->song.systemLen; i++) { |
| 960 |
if (!isChipVisible[i]) continue; |
| 961 |
ImGui::TableNextColumn(); |
| 962 |
ImGui::Text("%d",i+1); |
| 963 |
} |
| 964 |
char id[1024]; |
| 965 |
for (int i=0; i<DIV_MAX_SAMPLE_TYPE; i++) { |
| 966 |
if (!isTypeVisible[i]) continue; |
| 967 |
|
| 968 |
ImGui::TableNextRow(); |
| 969 |
ImGui::TableNextColumn(); |
| 970 |
ImGui::Text("%c",'A'+i); |
| 971 |
for (int j=0; j<e->song.systemLen; j++) { |
| 972 |
if (!isChipVisible[j]) continue; |
| 973 |
ImGui::TableNextColumn(); |
| 974 |
|
| 975 |
if (!isMemVisible[i][j]) continue; |
| 976 |
snprintf(id,1023,"##_SEC%d_%d",i,j); |
| 977 |
|
| 978 |
ImVec4 baseColor=sample->renderOn[i][j]?(isMemWarning[i][j]?uiColors[GUI_COLOR_SAMPLE_CHIP_WARNING]:uiColors[GUI_COLOR_SAMPLE_CHIP_ENABLED]):uiColors[GUI_COLOR_SAMPLE_CHIP_DISABLED]; |
| 979 |
ImVec4 color=baseColor; |
| 980 |
ImVec4 colorHovered=baseColor; |
| 981 |
ImVec4 colorActive=baseColor; |
| 982 |
|
| 983 |
if (settings.guiColorsBase) { |
| 984 |
color.x*=0.8f; |
| 985 |
color.y*=0.8f; |
| 986 |
color.z*=0.8f; |
| 987 |
colorHovered.x*=0.65f; |
| 988 |
colorHovered.y*=0.65f; |
| 989 |
colorHovered.z*=0.65f; |
| 990 |
colorActive.x*=0.3f; |
| 991 |
colorActive.y*=0.3f; |
| 992 |
colorActive.z*=0.3f; |
| 993 |
} else { |
| 994 |
color.x*=0.2f; |
| 995 |
color.y*=0.2f; |
| 996 |
color.z*=0.2f; |
| 997 |
colorHovered.x*=0.4f; |
| 998 |
colorHovered.y*=0.4f; |
| 999 |
colorHovered.z*=0.4f; |
| 1000 |
} |
| 1001 |
|
| 1002 |
ImGui::PushStyleColor(ImGuiCol_FrameBg,color); |
| 1003 |
ImGui::PushStyleColor(ImGuiCol_FrameBgHovered,colorHovered); |
| 1004 |
ImGui::PushStyleColor(ImGuiCol_FrameBgActive,colorActive); |
| 1005 |
ImGui::PushStyleColor(ImGuiCol_CheckMark,baseColor); |
| 1006 |
|
| 1007 |
if (ImGui::Checkbox(id,&sample->renderOn[i][j])) { |
| 1008 |
e->renderSamplesP(curSample); |
| 1009 |
} |
| 1010 |
|
| 1011 |
ImGui::PopStyleColor(4); |
| 1012 |
|
| 1013 |
if (ImGui::IsItemHovered()) { |
| 1014 |
const char* memName=NULL; |
| 1015 |
size_t capacity=0; |
| 1016 |
size_t usage=0; |
| 1017 |
int totalFree=0; |
| 1018 |
DivDispatch* dispatch=e->getDispatch(j); |
| 1019 |
if (dispatch!=NULL) { |
| 1020 |
memName=dispatch->getSampleMemName(i); |
| 1021 |
capacity=dispatch->getSampleMemCapacity(i); |
| 1022 |
usage=dispatch->getSampleMemUsage(i); |
| 1023 |
if (usage<capacity) { |
| 1024 |
totalFree=capacity-usage; |
| 1025 |
} |
| 1026 |
} |
| 1027 |
String toolText; |
| 1028 |
if (memName==NULL) { |
| 1029 |
toolText=fmt::sprintf(_("%s\n%d bytes free"),e->getSystemName(e->song.system[j]),totalFree); |
| 1030 |
} else { |
| 1031 |
toolText=fmt::sprintf(_("%s (%s)\n%d bytes free"),e->getSystemName(e->song.system[j]),memName,totalFree); |
| 1032 |
} |
| 1033 |
|
| 1034 |
if (isMemWarning[i][j] && sample->renderOn[i][j]) { |
| 1035 |
toolText+=_("\n\nnot enough memory for this sample!"); |
| 1036 |
} |
| 1037 |
|
| 1038 |
ImGui::SetTooltip("%s",toolText.c_str()); |
| 1039 |
} |
| 1040 |
} |
| 1041 |
} |
| 1042 |
ImGui::EndTable(); |
| 1043 |
} |
| 1044 |
} |
| 1045 |
|
| 1046 |
} |
| 1047 |
|
| 1048 |
ImGui::EndTable(); |
| 1049 |
} |
| 1050 |
|
| 1051 |
ImGui::Separator(); |
| 1052 |
|
| 1053 |
pushToggleColors(!sampleDragMode); |
| 1054 |
if (ImGui::Button(ICON_FA_I_CURSOR "##SSelect")) { |
| 1055 |
sampleDragMode=false; |
| 1056 |
} |
| 1057 |
popToggleColors(); |
| 1058 |
if (ImGui::IsItemHovered()) { |
| 1059 |
ImGui::SetTooltip(_("Edit mode: Select")); |
| 1060 |
} |
| 1061 |
sameLineMaybe(); |
| 1062 |
pushToggleColors(sampleDragMode); |
| 1063 |
if (ImGui::Button(ICON_FA_PENCIL "##SDraw")) { |
| 1064 |
sampleDragMode=true; |
| 1065 |
} |
| 1066 |
popToggleColors(); |
| 1067 |
if (ImGui::IsItemHovered()) { |
| 1068 |
ImGui::SetTooltip(_("Edit mode: Draw")); |
| 1069 |
} |
| 1070 |
ImGui::BeginDisabled(sample->depth!=DIV_SAMPLE_DEPTH_8BIT && sample->depth!=DIV_SAMPLE_DEPTH_16BIT); |
| 1071 |
sameLineMaybe(); |
| 1072 |
ImGui::Dummy(ImVec2(4.0*dpiScale,dpiScale)); |
| 1073 |
sameLineMaybe(); |
| 1074 |
ImGui::Button(ICON_FUR_SAMPLE_RESIZE "##SResize"); |
| 1075 |
if (ImGui::IsItemClicked()) { |
| 1076 |
resizeSize=sample->samples; |
| 1077 |
} |
| 1078 |
if (ImGui::IsItemHovered()) { |
| 1079 |
ImGui::SetTooltip(_("Resize")); |
| 1080 |
} |
| 1081 |
if (openSampleResizeOpt) { |
| 1082 |
openSampleResizeOpt=false; |
| 1083 |
ImGui::OpenPopup("SResizeOpt"); |
| 1084 |
} |
| 1085 |
if (ImGui::BeginPopupContextItem("SResizeOpt",ImGuiPopupFlags_MouseButtonLeft)) { |
| 1086 |
if (ImGui::InputInt(_("Samples"),&resizeSize,1,64)) { |
| 1087 |
if (resizeSize<0) resizeSize=0; |
| 1088 |
if (resizeSize>16777215) resizeSize=16777215; |
| 1089 |
} |
| 1090 |
if (ImGui::Button(_("Resize"))) { |
| 1091 |
sample->prepareUndo(true); |
| 1092 |
e->lockEngine([this,sample]() { |
| 1093 |
if (!sample->resize(resizeSize)) { |
| 1094 |
showError(_("couldn't resize! make sure your sample is 8 or 16-bit.")); |
| 1095 |
} |
| 1096 |
e->renderSamples(curSample); |
| 1097 |
}); |
| 1098 |
updateSampleTex=true; |
| 1099 |
sampleSelStart=-1; |
| 1100 |
sampleSelEnd=-1; |
| 1101 |
MARK_MODIFIED; |
| 1102 |
ImGui::CloseCurrentPopup(); |
| 1103 |
} |
| 1104 |
ImGui::EndPopup(); |
| 1105 |
} else { |
| 1106 |
resizeSize=sample->samples; |
| 1107 |
} |
| 1108 |
sameLineMaybe(); |
| 1109 |
ImGui::Button(ICON_FUR_SAMPLE_RESAMPLE "##SResample"); |
| 1110 |
if (ImGui::IsItemClicked()) { |
| 1111 |
resampleTarget=targetRate; |
| 1112 |
} |
| 1113 |
if (ImGui::IsItemHovered()) { |
| 1114 |
ImGui::SetTooltip(_("Resample")); |
| 1115 |
} |
| 1116 |
if (openSampleResampleOpt) { |
| 1117 |
openSampleResampleOpt=false; |
| 1118 |
ImGui::OpenPopup("SResampleOpt"); |
| 1119 |
} |
| 1120 |
if (ImGui::BeginPopupContextItem("SResampleOpt",ImGuiPopupFlags_MouseButtonLeft)) { |
| 1121 |
if (ImGui::InputDouble("Rate##SRRate",&resampleTarget,1.0,50.0,"%g")) { |
| 1122 |
if (resampleTarget<100) resampleTarget=100; |
| 1123 |
if (resampleTarget>384000) resampleTarget=384000; |
| 1124 |
} |
| 1125 |
double factor=resampleTarget/(double)targetRate; |
| 1126 |
unsigned int targetLength=sample->samples*factor; |
| 1127 |
if (ImGui::InputScalar("Length##SRLen",ImGuiDataType_U32,&targetLength, &_ONE, &_SIXTEEN)) { |
| 1128 |
if (targetLength<1) targetLength=1; |
| 1129 |
resampleTarget=targetRate*targetLength/(double)sample->samples; |
| 1130 |
if (resampleTarget<100) resampleTarget=100; |
| 1131 |
if (resampleTarget>384000) resampleTarget=384000; |
| 1132 |
} |
| 1133 |
if (ImGui::InputDouble(_("Factor"),&factor,0.125,0.5,"%g")) { |
| 1134 |
resampleTarget=(double)targetRate*factor; |
| 1135 |
if (resampleTarget<100) resampleTarget=100; |
| 1136 |
if (resampleTarget>384000) resampleTarget=384000; |
| 1137 |
} |
| 1138 |
if (ImGui::Button("0.5x")) { |
| 1139 |
resampleTarget*=0.5; |
| 1140 |
if (resampleTarget<100) resampleTarget=100; |
| 1141 |
if (resampleTarget>384000) resampleTarget=384000; |
| 1142 |
} |
| 1143 |
ImGui::SameLine(); |
| 1144 |
if (ImGui::Button("==")) { |
| 1145 |
resampleTarget=targetRate; |
| 1146 |
} |
| 1147 |
ImGui::SameLine(); |
| 1148 |
if (ImGui::Button("2.0x")) { |
| 1149 |
resampleTarget*=2.0; |
| 1150 |
if (resampleTarget<100) resampleTarget=100; |
| 1151 |
if (resampleTarget>384000) resampleTarget=384000; |
| 1152 |
} |
| 1153 |
ImGui::Combo(_("Filter"),&resampleStrat,LocalizedComboGetter,resampleStrats,6); |
| 1154 |
if (ImGui::Button(_("Resample"))) { |
| 1155 |
sample->prepareUndo(true); |
| 1156 |
e->lockEngine([this,sample,targetRate]() { |
| 1157 |
if (!sample->resample(targetRate,resampleTarget,resampleStrat)) { |
| 1158 |
showError(_("couldn't resample! make sure your sample is 8 or 16-bit and that the target rate is at least 100Hz.")); |
| 1159 |
} |
| 1160 |
e->renderSamples(curSample); |
| 1161 |
}); |
| 1162 |
updateSampleTex=true; |
| 1163 |
sampleSelStart=-1; |
| 1164 |
sampleSelEnd=-1; |
| 1165 |
MARK_MODIFIED; |
| 1166 |
ImGui::CloseCurrentPopup(); |
| 1167 |
} |
| 1168 |
ImGui::EndPopup(); |
| 1169 |
} else { |
| 1170 |
resampleTarget=targetRate; |
| 1171 |
} |
| 1172 |
ImGui::SameLine(); |
| 1173 |
ImGui::Dummy(ImVec2(4.0*dpiScale,dpiScale)); |
| 1174 |
sameLineMaybe(); |
| 1175 |
if (ImGui::Button(ICON_FA_UNDO "##SUndo")) { |
| 1176 |
doUndoSample(); |
| 1177 |
} |
| 1178 |
if (ImGui::IsItemHovered()) { |
| 1179 |
ImGui::SetTooltip(_("Undo")); |
| 1180 |
} |
| 1181 |
sameLineMaybe(); |
| 1182 |
if (ImGui::Button(ICON_FA_REPEAT "##SRedo")) { |
| 1183 |
doRedoSample(); |
| 1184 |
} |
| 1185 |
if (ImGui::IsItemHovered()) { |
| 1186 |
ImGui::SetTooltip(_("Redo")); |
| 1187 |
} |
| 1188 |
ImGui::SameLine(); |
| 1189 |
ImGui::Dummy(ImVec2(4.0*dpiScale,dpiScale)); |
| 1190 |
sameLineMaybe(); |
| 1191 |
ImGui::Button(ICON_FA_VOLUME_UP "##SAmplify"); |
| 1192 |
if (ImGui::IsItemHovered()) { |
| 1193 |
ImGui::SetTooltip(_("Amplify")); |
| 1194 |
} |
| 1195 |
if (openSampleAmplifyOpt) { |
| 1196 |
openSampleAmplifyOpt=false; |
| 1197 |
ImGui::OpenPopup("SAmplifyOpt"); |
| 1198 |
} |
| 1199 |
if (ImGui::BeginPopupContextItem("SAmplifyOpt",ImGuiPopupFlags_MouseButtonLeft)) { |
| 1200 |
ImGui::Text(_("Volume")); |
| 1201 |
if (ImGui::InputFloat("##SRVolume",&lifyVol,10.0,50.0,"%g%%")) { |
| 1202 |
if (amplifyVol<0) amplifyVol=0; |
| 1203 |
if (amplifyVol>10000) amplifyVol=10000; |
| 1204 |
} |
| 1205 |
ImGui::SameLine(); |
| 1206 |
ImGui::Text("(%.1fdB)",20.0*log10(amplifyVol/100.0f)); |
| 1207 |
if (ImGui::Button(_("Apply"))) { |
| 1208 |
sample->prepareUndo(true); |
| 1209 |
e->lockEngine([this,sample]() { |
| 1210 |
SAMPLE_OP_BEGIN; |
| 1211 |
float vol=amplifyVol/100.0f; |
| 1212 |
|
| 1213 |
if (sample->depth==DIV_SAMPLE_DEPTH_16BIT) { |
| 1214 |
for (unsigned int i=start; i<end; i++) { |
| 1215 |
float val=sample->data16[i]*vol; |
| 1216 |
if (val<-32768) val=-32768; |
| 1217 |
if (val>32767) val=32767; |
| 1218 |
sample->data16[i]=val; |
| 1219 |
} |
| 1220 |
} else if (sample->depth==DIV_SAMPLE_DEPTH_8BIT) { |
| 1221 |
for (unsigned int i=start; i<end; i++) { |
| 1222 |
float val=sample->data8[i]*vol; |
| 1223 |
if (val<-128) val=-128; |
| 1224 |
if (val>127) val=127; |
| 1225 |
sample->data8[i]=val; |
| 1226 |
} |
| 1227 |
} |
| 1228 |
|
| 1229 |
updateSampleTex=true; |
| 1230 |
|
| 1231 |
e->renderSamples(curSample); |
| 1232 |
}); |
| 1233 |
MARK_MODIFIED; |
| 1234 |
ImGui::CloseCurrentPopup(); |
| 1235 |
} |
| 1236 |
ImGui::EndPopup(); |
| 1237 |
} |
| 1238 |
sameLineMaybe(); |
| 1239 |
if (ImGui::Button(ICON_FUR_SAMPLE_NORMALIZE "##SNormalize")) { |
| 1240 |
doAction(GUI_ACTION_SAMPLE_NORMALIZE); |
| 1241 |
} |
| 1242 |
if (ImGui::IsItemHovered()) { |
| 1243 |
ImGui::SetTooltip(_("Normalize")); |
| 1244 |
} |
| 1245 |
sameLineMaybe(); |
| 1246 |
if (ImGui::Button(ICON_FUR_SAMPLE_FADEIN "##SFadeIn")) { |
| 1247 |
doAction(GUI_ACTION_SAMPLE_FADE_IN); |
| 1248 |
} |
| 1249 |
if (ImGui::IsItemHovered()) { |
| 1250 |
ImGui::SetTooltip(_("Fade in")); |
| 1251 |
} |
| 1252 |
sameLineMaybe(); |
| 1253 |
if (ImGui::Button(ICON_FUR_SAMPLE_FADEOUT "##SFadeOut")) { |
| 1254 |
doAction(GUI_ACTION_SAMPLE_FADE_OUT); |
| 1255 |
} |
| 1256 |
if (ImGui::IsItemHovered()) { |
| 1257 |
ImGui::SetTooltip(_("Fade out")); |
| 1258 |
} |
| 1259 |
sameLineMaybe(); |
| 1260 |
ImGui::Button(ICON_FUR_SAMPLE_INSERT_SILENCE "##SInsertSilence"); |
| 1261 |
if (ImGui::IsItemHovered()) { |
| 1262 |
ImGui::SetTooltip(_("Insert silence")); |
| 1263 |
} |
| 1264 |
if (openSampleSilenceOpt) { |
| 1265 |
openSampleSilenceOpt=false; |
| 1266 |
ImGui::OpenPopup("SSilenceOpt"); |
| 1267 |
} |
| 1268 |
if (ImGui::BeginPopupContextItem("SSilenceOpt",ImGuiPopupFlags_MouseButtonLeft)) { |
| 1269 |
if (ImGui::InputInt(_("Samples"),&silenceSize,1,64)) { |
| 1270 |
if (silenceSize<0) silenceSize=0; |
| 1271 |
if (silenceSize>16777215) silenceSize=16777215; |
| 1272 |
} |
| 1273 |
if (ImGui::Button(_("Go"))) { |
| 1274 |
int pos=(sampleSelStart==-1 || sampleSelStart==sampleSelEnd)?sample->samples:sampleSelStart; |
| 1275 |
sample->prepareUndo(true); |
| 1276 |
e->lockEngine([this,sample,pos]() { |
| 1277 |
if (!sample->insert(pos,silenceSize)) { |
| 1278 |
showError(_("couldn't insert! make sure your sample is 8 or 16-bit.")); |
| 1279 |
} |
| 1280 |
e->renderSamples(curSample); |
| 1281 |
}); |
| 1282 |
updateSampleTex=true; |
| 1283 |
sampleSelStart=pos; |
| 1284 |
sampleSelEnd=pos+silenceSize; |
| 1285 |
MARK_MODIFIED; |
| 1286 |
ImGui::CloseCurrentPopup(); |
| 1287 |
} |
| 1288 |
ImGui::EndPopup(); |
| 1289 |
} |
| 1290 |
sameLineMaybe(); |
| 1291 |
if (ImGui::Button(ICON_FUR_SAMPLE_APPLY_SILENCE "##SSilence")) { |
| 1292 |
doAction(GUI_ACTION_SAMPLE_SILENCE); |
| 1293 |
} |
| 1294 |
if (ImGui::IsItemHovered()) { |
| 1295 |
ImGui::SetTooltip(_("Apply silence")); |
| 1296 |
} |
| 1297 |
sameLineMaybe(); |
| 1298 |
if (ImGui::Button(ICON_FA_TIMES "##SDelete")) { |
| 1299 |
doAction(GUI_ACTION_SAMPLE_DELETE); |
| 1300 |
} |
| 1301 |
if (ImGui::IsItemHovered()) { |
| 1302 |
ImGui::SetTooltip(_("Delete")); |
| 1303 |
} |
| 1304 |
sameLineMaybe(); |
| 1305 |
if (ImGui::Button(ICON_FA_CROP "##STrim")) { |
| 1306 |
doAction(GUI_ACTION_SAMPLE_TRIM); |
| 1307 |
} |
| 1308 |
if (ImGui::IsItemHovered()) { |
| 1309 |
ImGui::SetTooltip(_("Trim")); |
| 1310 |
} |
| 1311 |
ImGui::SameLine(); |
| 1312 |
ImGui::Dummy(ImVec2(4.0*dpiScale,dpiScale)); |
| 1313 |
sameLineMaybe(); |
| 1314 |
if (ImGui::Button(ICON_FUR_SAMPLE_REVERSE "##SReverse")) { |
| 1315 |
doAction(GUI_ACTION_SAMPLE_REVERSE); |
| 1316 |
} |
| 1317 |
if (ImGui::IsItemHovered()) { |
| 1318 |
ImGui::SetTooltip(_("Reverse")); |
| 1319 |
} |
| 1320 |
sameLineMaybe(); |
| 1321 |
if (ImGui::Button(ICON_FUR_SAMPLE_INVERT "##SInvert")) { |
| 1322 |
doAction(GUI_ACTION_SAMPLE_INVERT); |
| 1323 |
} |
| 1324 |
if (ImGui::IsItemHovered()) { |
| 1325 |
ImGui::SetTooltip(_("Invert")); |
| 1326 |
} |
| 1327 |
sameLineMaybe(); |
| 1328 |
if (ImGui::Button(ICON_FUR_SAMPLE_SIGN "##SSign")) { |
| 1329 |
doAction(GUI_ACTION_SAMPLE_SIGN); |
| 1330 |
} |
| 1331 |
if (ImGui::IsItemHovered()) { |
| 1332 |
ImGui::SetTooltip(_("Signed/unsigned exchange")); |
| 1333 |
} |
| 1334 |
sameLineMaybe(); |
| 1335 |
ImGui::Button(ICON_FUR_SAMPLE_FILTER "##SFilter"); |
| 1336 |
if (ImGui::IsItemHovered()) { |
| 1337 |
ImGui::SetTooltip(_("Apply filter")); |
| 1338 |
} |
| 1339 |
float minCutoff=10.0f; |
| 1340 |
float maxCutoff=sample->centerRate*0.5f; |
| 1341 |
if (openSampleFilterOpt) { |
| 1342 |
openSampleFilterOpt=false; |
| 1343 |
sampleFilterFirstFrame=true; |
| 1344 |
ImGui::OpenPopup("SFilterOpt"); |
| 1345 |
} |
| 1346 |
if (ImGui::BeginPopupContextItem("SFilterOpt",ImGuiPopupFlags_MouseButtonLeft)) { |
| 1347 |
float lowP=sampleFilterL*100.0f; |
| 1348 |
float bandP=sampleFilterB*100.0f; |
| 1349 |
float highP=sampleFilterH*100.0f; |
| 1350 |
float resP=sampleFilterRes*100.0f; |
| 1351 |
ImGui::Text(_("Cutoff:")); |
| 1352 |
|
| 1353 |
ImGui::Checkbox(_("Sweep (2 frequencies)"),&sampleFilterSweep); |
| 1354 |
if (sampleFilterSweep) { |
| 1355 |
if (ImGui::SliderFloat(_("From"),&sampleFilterCutStart,minCutoff,maxCutoff,"%.0f Hz")) { |
| 1356 |
if (sampleFilterCutStart<minCutoff) sampleFilterCutStart=minCutoff; |
| 1357 |
if (sampleFilterCutStart>maxCutoff) sampleFilterCutStart=maxCutoff; |
| 1358 |
} |
| 1359 |
if (ImGui::SliderFloat(_("To"),&sampleFilterCutEnd,minCutoff,maxCutoff,"%.0f Hz")) { |
| 1360 |
if (sampleFilterCutEnd<minCutoff) sampleFilterCutEnd=minCutoff; |
| 1361 |
if (sampleFilterCutEnd>maxCutoff) sampleFilterCutEnd=maxCutoff; |
| 1362 |
} |
| 1363 |
} else { |
| 1364 |
if (ImGui::SliderFloat(_("Frequency"),&sampleFilterCutStart,minCutoff,maxCutoff,"%.0f Hz")) { |
| 1365 |
if (sampleFilterCutStart<minCutoff) sampleFilterCutStart=minCutoff; |
| 1366 |
if (sampleFilterCutStart>maxCutoff) sampleFilterCutStart=maxCutoff; |
| 1367 |
} |
| 1368 |
} |
| 1369 |
|
| 1370 |
ImGui::Separator(); |
| 1371 |
if (ImGui::SliderFloat(_("Resonance"),&resP,0.0f,99.0f,"%.1f%%")) { |
| 1372 |
sampleFilterRes=resP/100.0f; |
| 1373 |
if (sampleFilterRes<0.0f) sampleFilterRes=0.0f; |
| 1374 |
if (sampleFilterRes>0.99f) sampleFilterRes=0.99f; |
| 1375 |
} |
| 1376 |
ImGui::AlignTextToFramePadding(); |
| 1377 |
ImGui::Text(_("Power")); |
| 1378 |
ImGui::SameLine(); |
| 1379 |
if (ImGui::RadioButton("1x",sampleFilterPower==1)) { |
| 1380 |
sampleFilterPower=1; |
| 1381 |
} |
| 1382 |
ImGui::SameLine(); |
| 1383 |
if (ImGui::RadioButton("2x",sampleFilterPower==2)) { |
| 1384 |
sampleFilterPower=2; |
| 1385 |
} |
| 1386 |
ImGui::SameLine(); |
| 1387 |
if (ImGui::RadioButton("3x",sampleFilterPower==3)) { |
| 1388 |
sampleFilterPower=3; |
| 1389 |
} |
| 1390 |
ImGui::Separator(); |
| 1391 |
if (ImGui::SliderFloat(_("Low-pass"),&lowP,0.0f,100.0f,"%.1f%%")) { |
| 1392 |
sampleFilterL=lowP/100.0f; |
| 1393 |
if (sampleFilterL<0.0f) sampleFilterL=0.0f; |
| 1394 |
if (sampleFilterL>1.0f) sampleFilterL=1.0f; |
| 1395 |
} |
| 1396 |
if (ImGui::SliderFloat(_("Band-pass"),&bandP,0.0f,100.0f,"%.1f%%")) { |
| 1397 |
sampleFilterB=bandP/100.0f; |
| 1398 |
if (sampleFilterB<0.0f) sampleFilterB=0.0f; |
| 1399 |
if (sampleFilterB>1.0f) sampleFilterB=1.0f; |
| 1400 |
} |
| 1401 |
if (ImGui::SliderFloat(_("High-pass"),&highP,0.0f,100.0f,"%.1f%%")) { |
| 1402 |
sampleFilterH=highP/100.0f; |
| 1403 |
if (sampleFilterH<0.0f) sampleFilterH=0.0f; |
| 1404 |
if (sampleFilterH>1.0f) sampleFilterH=1.0f; |
| 1405 |
} |
| 1406 |
|
| 1407 |
if (ImGui::Button(_("Apply"))) { |
| 1408 |
sample->prepareUndo(true); |
| 1409 |
e->lockEngine([this,sample]() { |
| 1410 |
SAMPLE_OP_BEGIN; |
| 1411 |
float res=1.0-pow(sampleFilterRes,0.5f); |
| 1412 |
float low=0; |
| 1413 |
float band=0; |
| 1414 |
float high=0; |
| 1415 |
|
| 1416 |
if (sampleFilterCutStart<0.0) sampleFilterCutStart=0.0; |
| 1417 |
if (sampleFilterCutStart>sample->centerRate*0.5) sampleFilterCutStart=sample->centerRate*0.5; |
| 1418 |
if (sampleFilterCutEnd<0.0) sampleFilterCutEnd=0.0; |
| 1419 |
if (sampleFilterCutEnd>sample->centerRate*0.5) sampleFilterCutEnd=sample->centerRate*0.5; |
| 1420 |
|
| 1421 |
double power=(sampleFilterCutStart>sampleFilterCutEnd)?0.5:2.0; |
| 1422 |
|
| 1423 |
if (sample->depth==DIV_SAMPLE_DEPTH_16BIT) { |
| 1424 |
for (unsigned int i=start; i<end; i++) { |
| 1425 |
double freq=sampleFilterCutStart+(sampleFilterSweep?((sampleFilterCutEnd-sampleFilterCutStart)*pow(double(i-start)/double(end-start),power)):0); |
| 1426 |
double cut=sin((freq/double(sample->centerRate))*M_PI); |
| 1427 |
|
| 1428 |
for (int j=0; j<sampleFilterPower; j++) { |
| 1429 |
low=low+cut*band; |
| 1430 |
high=float(sample->data16[i])-low-(res*band); |
| 1431 |
band=cut*high+band; |
| 1432 |
} |
| 1433 |
|
| 1434 |
float val=low*sampleFilterL+band*sampleFilterB+high*sampleFilterH; |
| 1435 |
if (val<-32768) val=-32768; |
| 1436 |
if (val>32767) val=32767; |
| 1437 |
sample->data16[i]=val; |
| 1438 |
} |
| 1439 |
} else if (sample->depth==DIV_SAMPLE_DEPTH_8BIT) { |
| 1440 |
for (unsigned int i=start; i<end; i++) { |
| 1441 |
double freq=sampleFilterCutStart+(sampleFilterSweep?((sampleFilterCutEnd-sampleFilterCutStart)*pow(double(i-start)/double(end-start),power)):0); |
| 1442 |
double cut=sin((freq/double(sample->centerRate))*M_PI); |
| 1443 |
|
| 1444 |
for (int j=0; j<sampleFilterPower; j++) { |
| 1445 |
low=low+cut*band; |
| 1446 |
high=float(sample->data8[i])-low-(res*band); |
| 1447 |
band=cut*high+band; |
| 1448 |
} |
| 1449 |
|
| 1450 |
float val=low*sampleFilterL+band*sampleFilterB+high*sampleFilterH; |
| 1451 |
if (val<-128) val=-128; |
| 1452 |
if (val>127) val=127; |
| 1453 |
sample->data8[i]=val; |
| 1454 |
} |
| 1455 |
} |
| 1456 |
|
| 1457 |
updateSampleTex=true; |
| 1458 |
|
| 1459 |
e->renderSamples(curSample); |
| 1460 |
}); |
| 1461 |
MARK_MODIFIED; |
| 1462 |
ImGui::CloseCurrentPopup(); |
| 1463 |
} |
| 1464 |
|
| 1465 |
if (sampleFilterFirstFrame) { |
| 1466 |
if (sampleFilterCutStart<minCutoff) sampleFilterCutStart=minCutoff; |
| 1467 |
if (sampleFilterCutStart>maxCutoff) sampleFilterCutStart=maxCutoff; |
| 1468 |
if (sampleFilterCutEnd<minCutoff) sampleFilterCutEnd=minCutoff; |
| 1469 |
if (sampleFilterCutEnd>maxCutoff) sampleFilterCutEnd=maxCutoff; |
| 1470 |
sampleFilterFirstFrame=false; |
| 1471 |
} |
| 1472 |
|
| 1473 |
ImGui::EndPopup(); |
| 1474 |
} |
| 1475 |
ImGui::EndDisabled(); |
| 1476 |
ImGui::SameLine(); |
| 1477 |
ImGui::Dummy(ImVec2(4.0*dpiScale,dpiScale)); |
| 1478 |
sameLineMaybe(); |
| 1479 |
ImGui::Button(ICON_FUR_CROSSFADE "##CrossFade"); |
| 1480 |
if (ImGui::IsItemHovered()) { |
| 1481 |
ImGui::SetTooltip(_("Crossfade loop points")); |
| 1482 |
} |
| 1483 |
if (openSampleCrossFadeOpt) { |
| 1484 |
openSampleCrossFadeOpt=false; |
| 1485 |
ImGui::OpenPopup("SCrossFadeOpt"); |
| 1486 |
} |
| 1487 |
if (ImGui::BeginPopupContextItem("SCrossFadeOpt",ImGuiPopupFlags_MouseButtonLeft)) { |
| 1488 |
if (sampleCrossFadeLoopLength>sample->loopStart) sampleCrossFadeLoopLength=sample->loopStart; |
| 1489 |
if (sampleCrossFadeLoopLength>(sample->loopEnd-sample->loopStart)) sampleCrossFadeLoopLength=sample->loopEnd-sample->loopStart; |
| 1490 |
if (ImGui::SliderInt(_("Number of samples"),&sampleCrossFadeLoopLength,0,100000)) { |
| 1491 |
if (sampleCrossFadeLoopLength<0) sampleCrossFadeLoopLength=0; |
| 1492 |
if (sampleCrossFadeLoopLength>sample->loopStart) sampleCrossFadeLoopLength=sample->loopStart; |
| 1493 |
if (sampleCrossFadeLoopLength>(sample->loopEnd-sample->loopStart)) sampleCrossFadeLoopLength=sample->loopEnd-sample->loopStart; |
| 1494 |
if (sampleCrossFadeLoopLength>100000) sampleCrossFadeLoopLength=100000; |
| 1495 |
} |
| 1496 |
if (ImGui::SliderInt(_("Linear <-> Equal power"),&sampleCrossFadeLoopLaw,0,100)) { |
| 1497 |
if (sampleCrossFadeLoopLaw<0) sampleCrossFadeLoopLaw=0; |
| 1498 |
if (sampleCrossFadeLoopLaw>100) sampleCrossFadeLoopLaw=100; |
| 1499 |
} |
| 1500 |
if (ImGui::Button(_("Apply"))) { |
| 1501 |
if (sampleCrossFadeLoopLength>sample->loopStart) { |
| 1502 |
showError(_("Crossfade: length would go out of bounds. Aborted...")); |
| 1503 |
ImGui::CloseCurrentPopup(); |
| 1504 |
} else if (sampleCrossFadeLoopLength>(sample->loopEnd-sample->loopStart)) { |
| 1505 |
showError(_("Crossfade: length would overflow loopStart. Try a smaller random value.")); |
| 1506 |
ImGui::CloseCurrentPopup(); |
| 1507 |
} else { |
| 1508 |
sample->prepareUndo(true); |
| 1509 |
e->lockEngine([this,sample] { |
| 1510 |
SAMPLE_OP_BEGIN; |
| 1511 |
double l=1.0/(double)sampleCrossFadeLoopLength; |
| 1512 |
double evar=1.0-sampleCrossFadeLoopLaw/200.0; |
| 1513 |
if (sample->depth==DIV_SAMPLE_DEPTH_8BIT) { |
| 1514 |
unsigned int crossFadeInput=sample->loopStart-sampleCrossFadeLoopLength; |
| 1515 |
unsigned int crossFadeOutput=sample->loopEnd-sampleCrossFadeLoopLength; |
| 1516 |
for (int i=0; i<sampleCrossFadeLoopLength; i++) { |
| 1517 |
double f1=pow(i*l,evar); |
| 1518 |
double f2=pow((sampleCrossFadeLoopLength-i)*l,evar); |
| 1519 |
double out=((double)sample->data8[crossFadeInput])*f1+((double)sample->data8[crossFadeOutput])*f2; |
| 1520 |
sample->data8[crossFadeOutput]=(signed char)CLAMP(out,-128,127); |
| 1521 |
crossFadeInput++; |
| 1522 |
crossFadeOutput++; |
| 1523 |
} |
| 1524 |
} else if (sample->depth==DIV_SAMPLE_DEPTH_16BIT) { |
| 1525 |
unsigned int crossFadeInput=sample->loopStart-sampleCrossFadeLoopLength; |
| 1526 |
unsigned int crossFadeOutput=sample->loopEnd-sampleCrossFadeLoopLength; |
| 1527 |
for (int i=0; i<sampleCrossFadeLoopLength; i++) { |
| 1528 |
double f1=std::pow(i*l,evar); |
| 1529 |
double f2=std::pow((sampleCrossFadeLoopLength-i)*l,evar); |
| 1530 |
double out=((double)sample->data16[crossFadeInput])*f1+((double)sample->data16[crossFadeOutput])*f2; |
| 1531 |
sample->data16[crossFadeOutput]=(short)CLAMP(out,-32768,32767); |
| 1532 |
crossFadeInput++; |
| 1533 |
crossFadeOutput++; |
| 1534 |
} |
| 1535 |
} |
| 1536 |
updateSampleTex=true; |
| 1537 |
|
| 1538 |
e->renderSamples(curSample); |
| 1539 |
}); |
| 1540 |
MARK_MODIFIED; |
| 1541 |
ImGui::CloseCurrentPopup(); |
| 1542 |
} |
| 1543 |
} |
| 1544 |
ImGui::EndPopup(); |
| 1545 |
} |
| 1546 |
ImGui::SameLine(); |
| 1547 |
if (ImGui::Button(ICON_FA_PLAY "##PreviewSample")) { |
| 1548 |
e->previewSample(curSample); |
| 1549 |
} |
| 1550 |
if (ImGui::IsItemHovered()) { |
| 1551 |
ImGui::SetTooltip(_("Preview sample")); |
| 1552 |
} |
| 1553 |
sameLineMaybe(); |
| 1554 |
if (ImGui::Button(ICON_FA_PLAY_CIRCLE "##PreviewSampleFromCursor")) { |
| 1555 |
e->previewSample(curSample, -1, sampleSelStart, sampleSelEnd == sampleSelStart ? -1 : sampleSelEnd); |
| 1556 |
} |
| 1557 |
if (ImGui::IsItemHovered()) { |
| 1558 |
ImGui::SetTooltip(_("Preview sample from cursor or selection only")); |
| 1559 |
} |
| 1560 |
sameLineMaybe(); |
| 1561 |
if (ImGui::Button(ICON_FA_STOP "##StopSample")) { |
| 1562 |
e->stopSamplePreview(); |
| 1563 |
} |
| 1564 |
if (ImGui::IsItemHovered()) { |
| 1565 |
ImGui::SetTooltip(_("Stop sample preview")); |
| 1566 |
} |
| 1567 |
sameLineMaybe(); |
| 1568 |
if (ImGui::Button(ICON_FA_UPLOAD "##MakeIns")) { |
| 1569 |
doAction(GUI_ACTION_SAMPLE_MAKE_INS); |
| 1570 |
} |
| 1571 |
if (ImGui::IsItemHovered()) { |
| 1572 |
ImGui::SetTooltip(_("Create instrument from sample")); |
| 1573 |
} |
| 1574 |
|
| 1575 |
sameLineMaybe(ImGui::CalcTextSize("Zoom").x+150.0f*dpiScale+ImGui::CalcTextSize("100%").x); |
| 1576 |
double zoomPercent=100.0/sampleZoom; |
| 1577 |
bool checkZoomLimit=false; |
| 1578 |
ImGui::AlignTextToFramePadding(); |
| 1579 |
ImGui::Text(_("Zoom")); |
| 1580 |
ImGui::SameLine(); |
| 1581 |
ImGui::SetNextItemWidth(150.0f*dpiScale); |
| 1582 |
if (ImGui::InputDouble("##SZoom",&zoomPercent,zoomPercent/8.0,20.0,"%g%%")) { |
| 1583 |
if (zoomPercent>10000.0) zoomPercent=10000.0; |
| 1584 |
if (zoomPercent<0.01) zoomPercent=0.01; |
| 1585 |
sampleZoom=100.0/zoomPercent; |
| 1586 |
sampleZoomAuto=false; |
| 1587 |
checkZoomLimit=true; |
| 1588 |
updateSampleTex=true; |
| 1589 |
} |
| 1590 |
ImGui::SameLine(); |
| 1591 |
if (sampleZoomAuto) { |
| 1592 |
ImGui::BeginDisabled(minSampleZoom<1.0); |
| 1593 |
if (ImGui::Button("100%")) { |
| 1594 |
sampleZoom=1.0; |
| 1595 |
sampleZoomAuto=false; |
| 1596 |
updateSampleTex=true; |
| 1597 |
checkZoomLimit=true; |
| 1598 |
} |
| 1599 |
ImGui::EndDisabled(); |
| 1600 |
} else { |
| 1601 |
if (ImGui::Button("Auto")) { |
| 1602 |
sampleZoomAuto=true; |
| 1603 |
updateSampleTex=true; |
| 1604 |
} |
| 1605 |
} |
| 1606 |
|
| 1607 |
if (mobileUI) { |
| 1608 |
sameLineMaybe(); |
| 1609 |
if (ImGui::Button(ICON_FA_ELLIPSIS_H "##SMobMenu")) { |
| 1610 |
ImGui::OpenPopup("SRightClick"); |
| 1611 |
} |
| 1612 |
} |
| 1613 |
|
| 1614 |
ImGui::Separator(); |
| 1615 |
|
| 1616 |
// time |
| 1617 |
ImDrawList* dl=ImGui::GetWindowDrawList(); |
| 1618 |
ImGuiWindow* window=ImGui::GetCurrentWindow(); |
| 1619 |
|
| 1620 |
ImVec2 size=ImVec2(ImGui::GetContentRegionAvail().x,ImGui::GetFontSize()+2.0*dpiScale); |
| 1621 |
|
| 1622 |
ImVec2 minArea=window->DC.CursorPos; |
| 1623 |
ImVec2 maxArea=ImVec2( |
| 1624 |
minArea.x+size.x, |
| 1625 |
minArea.y+size.y |
| 1626 |
); |
| 1627 |
ImRect rect=ImRect(minArea,maxArea); |
| 1628 |
ImGuiStyle& style=ImGui::GetStyle(); |
| 1629 |
|
| 1630 |
ImGui::ItemSize(size,style.FramePadding.y); |
| 1631 |
if (ImGui::ItemAdd(rect,ImGui::GetID("SETime"))) { |
| 1632 |
int targetRate=sampleCompatRate?sample->rate:sample->centerRate; |
| 1633 |
int curDivisorSel=0; |
| 1634 |
int curMultiplierSel=0; |
| 1635 |
double divisor=1000.0; |
| 1636 |
double multiplier=1.0; |
| 1637 |
while ((((double)targetRate/divisor)/sampleZoom)<60.0*dpiScale) { |
| 1638 |
if (curDivisorSel>=10) break; |
| 1639 |
divisor=timeDivisors[++curDivisorSel]; |
| 1640 |
} |
| 1641 |
if (curDivisorSel>=10) { |
| 1642 |
while ((((double)targetRate*multiplier)/sampleZoom)<60.0*dpiScale) { |
| 1643 |
if (curMultiplierSel>=13) { |
| 1644 |
multiplier+=3600.0; |
| 1645 |
} else { |
| 1646 |
multiplier=timeMultipliers[++curMultiplierSel]; |
| 1647 |
} |
| 1648 |
} |
| 1649 |
} |
| 1650 |
double timeStep=multiplier*((double)targetRate/divisor); |
| 1651 |
double timeMin=-fmod(samplePos,timeStep); |
| 1652 |
double timeMax=size.x*sampleZoom; |
| 1653 |
ImU32 color=ImGui::GetColorU32(uiColors[GUI_COLOR_SAMPLE_TIME_FG]); |
| 1654 |
|
| 1655 |
dl->AddRectFilled(minArea,maxArea,ImGui::GetColorU32(uiColors[GUI_COLOR_SAMPLE_TIME_BG])); |
| 1656 |
|
| 1657 |
for (double i=timeMin; i<timeMax; i+=timeStep) { |
| 1658 |
ImVec2 pos=ImVec2(minArea.x+(i/sampleZoom),minArea.y); |
| 1659 |
int timeMs=(int)((1000*(samplePos+i))/targetRate); |
| 1660 |
String t; |
| 1661 |
if (curDivisorSel>=9) { |
| 1662 |
if (timeMs>=3600000) { |
| 1663 |
t=fmt::sprintf("%d:%02d:%02d",timeMs/3600000,(timeMs/60000)%60,(timeMs/1000)%60); |
| 1664 |
} else if (timeMs>=60000) { |
| 1665 |
t=fmt::sprintf("%d:%02d.%02d",timeMs/60000,(timeMs/1000)%60,(timeMs%1000)/10); |
| 1666 |
} else { |
| 1667 |
t=fmt::sprintf("%d.%03d",timeMs/1000,timeMs%1000); |
| 1668 |
} |
| 1669 |
} else { |
| 1670 |
t=fmt::sprintf("%dms",timeMs); |
| 1671 |
} |
| 1672 |
dl->AddText(pos,color,t.c_str()); |
| 1673 |
} |
| 1674 |
} |
| 1675 |
|
| 1676 |
ImVec2 avail=ImGui::GetContentRegionAvail(); // sample view size determined here |
| 1677 |
// don't do this. reason: mobile. |
| 1678 |
/*if (ImGui::GetContentRegionAvail().y>(ImGui::GetContentRegionAvail().x*0.5f)) { |
| 1679 |
avail=ImVec2(ImGui::GetContentRegionAvail().x,ImGui::GetContentRegionAvail().x*0.5f); |
| 1680 |
}*/ |
| 1681 |
avail.y-=ImGui::GetFrameHeightWithSpacing()+ImGui::GetStyle().ScrollbarSize; |
| 1682 |
if (avail.y<1.0) { // Prevents crash |
| 1683 |
avail.y=1.0; |
| 1684 |
} |
| 1685 |
|
| 1686 |
int availX=avail.x; |
| 1687 |
int availY=avail.y; |
| 1688 |
|
| 1689 |
minSampleZoom=(double)sample->samples/avail.x; |
| 1690 |
|
| 1691 |
if (checkZoomLimit) { |
| 1692 |
logV("sample: %f min: %f",sampleZoom,minSampleZoom); |
| 1693 |
int bounds=((int)sample->samples-round(avail.x*sampleZoom)); |
| 1694 |
if (bounds<0) bounds=0; |
| 1695 |
if (samplePos>bounds) samplePos=bounds; |
| 1696 |
if (sampleZoom>minSampleZoom) { |
| 1697 |
sampleZoomAuto=true; |
| 1698 |
} |
| 1699 |
} |
| 1700 |
|
| 1701 |
if (sampleZoomAuto) { |
| 1702 |
samplePos=0; |
| 1703 |
if (sample->samples<1 || avail.x<=0) { |
| 1704 |
sampleZoom=1.0; |
| 1705 |
} else { |
| 1706 |
sampleZoom=minSampleZoom; |
| 1707 |
} |
| 1708 |
if (sampleZoom!=prevSampleZoom) { |
| 1709 |
prevSampleZoom=sampleZoom; |
| 1710 |
updateSampleTex=true; |
| 1711 |
} |
| 1712 |
} |
| 1713 |
|
| 1714 |
if (sampleTex==NULL || sampleTexW!=avail.x || sampleTexH!=avail.y || !rend->isTextureValid(sampleTex)) { |
| 1715 |
if (sampleTex!=NULL) { |
| 1716 |
rend->destroyTexture(sampleTex); |
| 1717 |
sampleTex=NULL; |
| 1718 |
} |
| 1719 |
if (avail.x>=1 && avail.y>=1) { |
| 1720 |
logD("recreating sample texture."); |
| 1721 |
sampleTex=rend->createTexture(true,avail.x,avail.y,true,bestTexFormat); |
| 1722 |
sampleTexW=avail.x; |
| 1723 |
sampleTexH=avail.y; |
| 1724 |
if (sampleTex==NULL) { |
| 1725 |
logE("error while creating sample texture! %s",SDL_GetError()); |
| 1726 |
} else { |
| 1727 |
updateSampleTex=true; |
| 1728 |
} |
| 1729 |
} |
| 1730 |
} |
| 1731 |
|
| 1732 |
if (sampleTex!=NULL) { |
| 1733 |
if (updateSampleTex) { |
| 1734 |
unsigned int* dataT=NULL; |
| 1735 |
int pitch=0; |
| 1736 |
logD("updating sample texture."); |
| 1737 |
if (!rend->lockTexture(sampleTex,(void**)&dataT,&pitch)) { |
| 1738 |
logE("error while locking sample texture! %s",SDL_GetError()); |
| 1739 |
} else { |
| 1740 |
unsigned int* data=new unsigned int[sampleTexW*sampleTexH]; |
| 1741 |
|
| 1742 |
ImU32 bgColor=ImGui::GetColorU32(uiColors[GUI_COLOR_SAMPLE_BG]); |
| 1743 |
ImU32 bgColorLoop=ImGui::GetColorU32(uiColors[GUI_COLOR_SAMPLE_LOOP]); |
| 1744 |
ImU32 lineColor=ImGui::GetColorU32(uiColors[GUI_COLOR_SAMPLE_FG]); |
| 1745 |
ImU32 centerLineColor=ImGui::GetColorU32(uiColors[GUI_COLOR_SAMPLE_CENTER]); |
| 1746 |
|
| 1747 |
switch (rend->getTextureFormat(sampleTex)) { |
| 1748 |
case GUI_TEXFORMAT_ARGB32: |
| 1749 |
SWAP_COLOR_ARGB(bgColor); |
| 1750 |
SWAP_COLOR_ARGB(bgColorLoop); |
| 1751 |
SWAP_COLOR_ARGB(lineColor); |
| 1752 |
SWAP_COLOR_ARGB(centerLineColor); |
| 1753 |
break; |
| 1754 |
case GUI_TEXFORMAT_BGRA32: |
| 1755 |
SWAP_COLOR_BGRA(bgColor); |
| 1756 |
SWAP_COLOR_BGRA(bgColorLoop); |
| 1757 |
SWAP_COLOR_BGRA(lineColor); |
| 1758 |
SWAP_COLOR_BGRA(centerLineColor); |
| 1759 |
break; |
| 1760 |
case GUI_TEXFORMAT_RGBA32: |
| 1761 |
SWAP_COLOR_RGBA(bgColor); |
| 1762 |
SWAP_COLOR_RGBA(bgColorLoop); |
| 1763 |
SWAP_COLOR_RGBA(lineColor); |
| 1764 |
SWAP_COLOR_RGBA(centerLineColor); |
| 1765 |
break; |
| 1766 |
default: |
| 1767 |
break; |
| 1768 |
} |
| 1769 |
|
| 1770 |
int ij=0; |
| 1771 |
if (availY>0) { |
| 1772 |
for (int j=0; j<availX; j++) { |
| 1773 |
int scaledPos=samplePos+(j*sampleZoom); |
| 1774 |
if (sample->isLoopable() && (scaledPos>=sample->loopStart && scaledPos<sample->loopEnd)) { |
| 1775 |
data[ij++]=bgColorLoop; |
| 1776 |
} else { |
| 1777 |
data[ij++]=bgColor; |
| 1778 |
} |
| 1779 |
} |
| 1780 |
for (int i=1; i<availY; i++) { |
| 1781 |
memcpy(&data[ij],data,availX*sizeof(unsigned int)); |
| 1782 |
ij+=availX; |
| 1783 |
} |
| 1784 |
for (int i=availX*(availY>>1); i<availX*(1+(availY>>1)); i++) { |
| 1785 |
data[i]=centerLineColor; |
| 1786 |
} |
| 1787 |
} |
| 1788 |
|
| 1789 |
unsigned int xCoarse=samplePos; |
| 1790 |
unsigned int xFine=0; |
| 1791 |
unsigned int xAdvanceCoarse=sampleZoom; |
| 1792 |
unsigned int xAdvanceFine=fmod(sampleZoom,1.0)*16777216; |
| 1793 |
for (unsigned int i=0; i<(unsigned int)availX; i++) { |
| 1794 |
if (xCoarse>=sample->samples) break; |
| 1795 |
int y1, y2; |
| 1796 |
int candMin=INT_MAX; |
| 1797 |
int candMax=INT_MIN; |
| 1798 |
int totalAdvance=0; |
| 1799 |
if (sample->depth==DIV_SAMPLE_DEPTH_8BIT) { |
| 1800 |
if (candMin>sample->data8[xCoarse]) candMin=sample->data8[xCoarse]; |
| 1801 |
if (candMax<sample->data8[xCoarse]) candMax=sample->data8[xCoarse]; |
| 1802 |
} else { |
| 1803 |
if (candMin>sample->data16[xCoarse]) candMin=sample->data16[xCoarse]; |
| 1804 |
if (candMax<sample->data16[xCoarse]) candMax=sample->data16[xCoarse]; |
| 1805 |
} |
| 1806 |
xFine+=xAdvanceFine; |
| 1807 |
if (xFine>=16777216) { |
| 1808 |
xFine-=16777216; |
| 1809 |
totalAdvance++; |
| 1810 |
} |
| 1811 |
totalAdvance+=xAdvanceCoarse; |
| 1812 |
if (xCoarse>=sample->samples) break; |
| 1813 |
do { |
| 1814 |
if (xCoarse>=sample->samples) break; |
| 1815 |
if (sample->depth==DIV_SAMPLE_DEPTH_8BIT) { |
| 1816 |
if (candMin>sample->data8[xCoarse]) candMin=sample->data8[xCoarse]; |
| 1817 |
if (candMax<sample->data8[xCoarse]) candMax=sample->data8[xCoarse]; |
| 1818 |
} else { |
| 1819 |
if (candMin>sample->data16[xCoarse]) candMin=sample->data16[xCoarse]; |
| 1820 |
if (candMax<sample->data16[xCoarse]) candMax=sample->data16[xCoarse]; |
| 1821 |
} |
| 1822 |
if (totalAdvance>0) xCoarse++; |
| 1823 |
} while ((totalAdvance--)>0); |
| 1824 |
if (sample->depth==DIV_SAMPLE_DEPTH_8BIT) { |
| 1825 |
y1=(((unsigned char)candMin^0x80)*availY)>>8; |
| 1826 |
y2=(((unsigned char)candMax^0x80)*availY)>>8; |
| 1827 |
} else { |
| 1828 |
y1=(((unsigned short)candMin^0x8000)*availY)>>16; |
| 1829 |
y2=(((unsigned short)candMax^0x8000)*availY)>>16; |
| 1830 |
} |
| 1831 |
if (y1>y2) { |
| 1832 |
y2^=y1; |
| 1833 |
y1^=y2; |
| 1834 |
y2^=y1; |
| 1835 |
} |
| 1836 |
if (y1<0) y1=0; |
| 1837 |
if (y1>=availY) y1=availY-1; |
| 1838 |
if (y2<0) y2=0; |
| 1839 |
if (y2>=availY) y2=availY-1; |
| 1840 |
|
| 1841 |
const int s1=i+availX*(availY-y1-1); |
| 1842 |
const int s2=i+availX*(availY-y2-1); |
| 1843 |
|
| 1844 |
for (int j=s2; j<=s1; j+=availX) { |
| 1845 |
data[j]=lineColor; |
| 1846 |
} |
| 1847 |
} |
| 1848 |
|
| 1849 |
if ((pitch>>2)==sampleTexW) { |
| 1850 |
memcpy(dataT,data,sampleTexW*sampleTexH*sizeof(unsigned int)); |
| 1851 |
} else { |
| 1852 |
int srcY=0; |
| 1853 |
int destY=0; |
| 1854 |
for (int i=0; i<sampleTexH; i++) { |
| 1855 |
memcpy(&dataT[destY],&data[srcY],sampleTexW*sizeof(unsigned int)); |
| 1856 |
srcY+=sampleTexW; |
| 1857 |
destY+=pitch>>2; |
| 1858 |
} |
| 1859 |
} |
| 1860 |
rend->unlockTexture(sampleTex); |
| 1861 |
delete[] data; |
| 1862 |
} |
| 1863 |
updateSampleTex=false; |
| 1864 |
} |
| 1865 |
|
| 1866 |
ImGui::PushStyleVar(ImGuiStyleVar_FramePadding,ImVec2(0,0)); |
| 1867 |
ImGui::ImageButton("SampleView",rend->getTextureID(sampleTex),avail,ImVec2(0,0),ImVec2(rend->getTextureU(sampleTex),rend->getTextureV(sampleTex))); |
| 1868 |
ImGui::PopStyleVar(); |
| 1869 |
|
| 1870 |
ImVec2 rectMin=ImGui::GetItemRectMin(); |
| 1871 |
ImVec2 rectMax=ImGui::GetItemRectMax(); |
| 1872 |
ImVec2 rectSize=ImGui::GetItemRectSize(); |
| 1873 |
|
| 1874 |
unsigned char selectTarget=255; |
| 1875 |
|
| 1876 |
if (ImGui::IsItemHovered()) { |
| 1877 |
int start=sampleSelStart; |
| 1878 |
int end=sampleSelEnd; |
| 1879 |
if (start>end) { |
| 1880 |
start^=end; |
| 1881 |
end^=start; |
| 1882 |
start^=end; |
| 1883 |
} |
| 1884 |
ImVec2 p1=rectMin; |
| 1885 |
p1.x+=(start-samplePos)/sampleZoom; |
| 1886 |
|
| 1887 |
ImVec2 p2=ImVec2(rectMin.x+(end-samplePos)/sampleZoom,rectMax.y); |
| 1888 |
|
| 1889 |
ImVec2 mousePos=ImGui::GetMousePos(); |
| 1890 |
if (p1.x>=rectMin.x && p1.x<=rectMax.x && fabs(mousePos.x-p1.x)<2.0*dpiScale) { |
| 1891 |
ImGui::SetMouseCursor(ImGuiMouseCursor_ResizeEW); |
| 1892 |
selectTarget=0; |
| 1893 |
} else if (p2.x>=rectMin.x && p2.x<=rectMax.x && fabs(mousePos.x-p2.x)<2.0*dpiScale) { |
| 1894 |
ImGui::SetMouseCursor(ImGuiMouseCursor_ResizeEW); |
| 1895 |
selectTarget=1; |
| 1896 |
} |
| 1897 |
} |
| 1898 |
|
| 1899 |
if (ImGui::IsItemClicked()) { |
| 1900 |
nextWindow=GUI_WINDOW_SAMPLE_EDIT; |
| 1901 |
if (ImGui::IsMouseDoubleClicked(ImGuiMouseButton_Left)) { |
| 1902 |
sampleDragActive=false; |
| 1903 |
sampleSelStart=0; |
| 1904 |
sampleSelEnd=sample->samples; |
| 1905 |
} else { |
| 1906 |
if (sample->samples>0) { |
| 1907 |
sampleDragStart=rectMin; |
| 1908 |
sampleDragAreaSize=rectSize; |
| 1909 |
switch (sample->depth) { |
| 1910 |
case DIV_SAMPLE_DEPTH_8BIT: |
| 1911 |
sampleDrag16=false; |
| 1912 |
sampleDragTarget=(void*)sample->data8; |
| 1913 |
break; |
| 1914 |
case DIV_SAMPLE_DEPTH_16BIT: |
| 1915 |
sampleDrag16=true; |
| 1916 |
sampleDragTarget=(void*)sample->data16; |
| 1917 |
break; |
| 1918 |
default: |
| 1919 |
sampleDrag16=true; |
| 1920 |
sampleDragTarget=NULL; |
| 1921 |
break; |
| 1922 |
} |
| 1923 |
sampleDragLen=sample->samples; |
| 1924 |
sampleDragActive=true; |
| 1925 |
if (!sampleDragMode) { |
| 1926 |
switch (selectTarget) { |
| 1927 |
case 0: |
| 1928 |
sampleSelStart^=sampleSelEnd; |
| 1929 |
sampleSelEnd^=sampleSelStart; |
| 1930 |
sampleSelStart^=sampleSelEnd; |
| 1931 |
break; |
| 1932 |
case 1: |
| 1933 |
break; |
| 1934 |
default: |
| 1935 |
sampleSelStart=-1; |
| 1936 |
sampleSelEnd=-1; |
| 1937 |
break; |
| 1938 |
} |
| 1939 |
} else { |
| 1940 |
sample->prepareUndo(true); |
| 1941 |
} |
| 1942 |
processDrags(ImGui::GetMousePos().x,ImGui::GetMousePos().y); |
| 1943 |
} |
| 1944 |
} |
| 1945 |
} |
| 1946 |
|
| 1947 |
if (ImGui::IsItemActive()) { |
| 1948 |
if (ImGui::GetMousePos().x>rectMax.x) { |
| 1949 |
double delta=pow(MAX(1.0,(ImGui::GetMousePos().x-rectMax.x)*0.04),2.0); |
| 1950 |
samplePos+=MAX(1.0,sampleZoom*delta); |
| 1951 |
int bounds=((int)sample->samples-round(avail.x*sampleZoom)); |
| 1952 |
if (bounds<0) bounds=0; |
| 1953 |
if (samplePos>bounds) samplePos=bounds; |
| 1954 |
updateSampleTex=true; |
| 1955 |
processDrags(ImGui::GetMousePos().x,ImGui::GetMousePos().y); |
| 1956 |
WAKE_UP; |
| 1957 |
} |
| 1958 |
if (ImGui::GetMousePos().x<rectMin.x) { |
| 1959 |
double delta=pow(MAX(1.0,(rectMin.x-ImGui::GetMousePos().x)*0.04),2.0); |
| 1960 |
samplePos-=MAX(1.0,sampleZoom*delta); |
| 1961 |
if (samplePos<0) samplePos=0; |
| 1962 |
updateSampleTex=true; |
| 1963 |
processDrags(ImGui::GetMousePos().x,ImGui::GetMousePos().y); |
| 1964 |
WAKE_UP; |
| 1965 |
} |
| 1966 |
} |
| 1967 |
|
| 1968 |
if (!sampleDragMode && ImGui::IsItemClicked(ImGuiMouseButton_Right)) { |
| 1969 |
ImGui::OpenPopup("SRightClick"); |
| 1970 |
} |
| 1971 |
|
| 1972 |
if (ImGui::BeginPopup("SRightClick",ImGuiWindowFlags_NoTitleBar|ImGuiWindowFlags_NoMove|ImGuiWindowFlags_AlwaysAutoResize)) { |
| 1973 |
ImGui::BeginDisabled(sample->depth!=DIV_SAMPLE_DEPTH_8BIT && sample->depth!=DIV_SAMPLE_DEPTH_16BIT); |
| 1974 |
if (ImGui::MenuItem(_("cut"),BIND_FOR(GUI_ACTION_SAMPLE_CUT))) { |
| 1975 |
doAction(GUI_ACTION_SAMPLE_CUT); |
| 1976 |
} |
| 1977 |
ImGui::EndDisabled(); |
| 1978 |
if (ImGui::MenuItem(_("copy"),BIND_FOR(GUI_ACTION_SAMPLE_COPY))) { |
| 1979 |
doAction(GUI_ACTION_SAMPLE_COPY); |
| 1980 |
} |
| 1981 |
ImGui::BeginDisabled(sample->depth!=DIV_SAMPLE_DEPTH_8BIT && sample->depth!=DIV_SAMPLE_DEPTH_16BIT); |
| 1982 |
if (ImGui::MenuItem(_("paste"),BIND_FOR(GUI_ACTION_SAMPLE_PASTE))) { |
| 1983 |
doAction(GUI_ACTION_SAMPLE_PASTE); |
| 1984 |
} |
| 1985 |
if (ImGui::MenuItem(_("paste (replace)"),BIND_FOR(GUI_ACTION_SAMPLE_PASTE_REPLACE))) { |
| 1986 |
doAction(GUI_ACTION_SAMPLE_PASTE_REPLACE); |
| 1987 |
} |
| 1988 |
if (ImGui::MenuItem(_("paste (mix)"),BIND_FOR(GUI_ACTION_SAMPLE_PASTE_MIX))) { |
| 1989 |
doAction(GUI_ACTION_SAMPLE_PASTE_MIX); |
| 1990 |
} |
| 1991 |
ImGui::EndDisabled(); |
| 1992 |
if (ImGui::MenuItem(_("select all"),BIND_FOR(GUI_ACTION_SAMPLE_SELECT_ALL))) { |
| 1993 |
doAction(GUI_ACTION_SAMPLE_SELECT_ALL); |
| 1994 |
} |
| 1995 |
ImGui::Separator(); |
| 1996 |
if (ImGui::MenuItem(_("set loop to selection"),BIND_FOR(GUI_ACTION_SAMPLE_SET_LOOP))) { |
| 1997 |
doAction(GUI_ACTION_SAMPLE_SET_LOOP); |
| 1998 |
} |
| 1999 |
if (ImGui::MenuItem(_("create wavetable from selection"),BIND_FOR(GUI_ACTION_SAMPLE_CREATE_WAVE))) { |
| 2000 |
doAction(GUI_ACTION_SAMPLE_CREATE_WAVE); |
| 2001 |
} |
| 2002 |
ImGui::EndPopup(); |
| 2003 |
} |
| 2004 |
|
| 2005 |
String statusBar=sampleDragMode?_("Draw"):_("Select"); |
| 2006 |
String statusBar2=""; |
| 2007 |
String statusBar3=fmt::sprintf(_("%d samples, %d bytes"),sample->samples,sample->getCurBufLen()); |
| 2008 |
String statusBar4=""; |
| 2009 |
bool drawSelection=false; |
| 2010 |
|
| 2011 |
if (!sampleDragMode) { |
| 2012 |
if (sampleSelStart>=0 && sampleSelEnd>=0) { |
| 2013 |
int start=sampleSelStart; |
| 2014 |
int end=sampleSelEnd; |
| 2015 |
if (start>end) { |
| 2016 |
start^=end; |
| 2017 |
end^=start; |
| 2018 |
start^=end; |
| 2019 |
} |
| 2020 |
if (start!=end) { |
| 2021 |
statusBar4=fmt::sprintf(_("(%d samples)"),end-start); |
| 2022 |
} |
| 2023 |
drawSelection=true; |
| 2024 |
} |
| 2025 |
} |
| 2026 |
|
| 2027 |
if (ImGui::IsItemHovered()) { |
| 2028 |
if (ctrlWheeling) { |
| 2029 |
double zoomPercent=100.0/sampleZoom; |
| 2030 |
if (wheelY>0) { |
| 2031 |
for (int i=0; i<wheelY; i++) { |
| 2032 |
double oldArea=round(rectSize.x*100.0/zoomPercent); |
| 2033 |
zoomPercent+=zoomPercent/8.0; |
| 2034 |
double increment=fabs(oldArea-(rectSize.x*100.0/zoomPercent))*((ImGui::GetMousePos().x-rectMin.x)/rectSize.x); |
| 2035 |
samplePos+=increment; |
| 2036 |
} |
| 2037 |
} else { |
| 2038 |
for (int i=0; i<-wheelY; i++) { |
| 2039 |
double oldArea=round(rectSize.x*100.0/zoomPercent); |
| 2040 |
zoomPercent-=zoomPercent/8.0; |
| 2041 |
double increment=fabs(oldArea-(rectSize.x*100.0/zoomPercent))*((ImGui::GetMousePos().x-rectMin.x)/rectSize.x); |
| 2042 |
samplePos-=increment; |
| 2043 |
if (samplePos<0) samplePos=0; |
| 2044 |
} |
| 2045 |
} |
| 2046 |
if (zoomPercent>10000.0) zoomPercent=10000.0; |
| 2047 |
if (zoomPercent<0.01) zoomPercent=0.01; |
| 2048 |
sampleZoom=100.0/zoomPercent; |
| 2049 |
sampleZoomAuto=false; |
| 2050 |
int bounds=((int)sample->samples-round(rectSize.x*sampleZoom)); |
| 2051 |
if (bounds<0) bounds=0; |
| 2052 |
if (samplePos>bounds) samplePos=bounds; |
| 2053 |
updateSampleTex=true; |
| 2054 |
if (sampleZoom>minSampleZoom) { |
| 2055 |
sampleZoomAuto=true; |
| 2056 |
} |
| 2057 |
} else { |
| 2058 |
if (wheelY!=0) { |
| 2059 |
if (!sampleZoomAuto) { |
| 2060 |
double scrollAmount=MAX(fabs((double)wheelY*sampleZoom*60.0),1.0); |
| 2061 |
if (wheelY>0) { |
| 2062 |
samplePos+=scrollAmount; |
| 2063 |
} else { |
| 2064 |
samplePos-=scrollAmount; |
| 2065 |
} |
| 2066 |
if (samplePos<0) samplePos=0; |
| 2067 |
int bounds=((int)sample->samples-round(rectSize.x*sampleZoom)); |
| 2068 |
if (bounds<0) bounds=0; |
| 2069 |
if (samplePos>bounds) samplePos=bounds; |
| 2070 |
updateSampleTex=true; |
| 2071 |
} |
| 2072 |
} |
| 2073 |
} |
| 2074 |
|
| 2075 |
int posX=-1; |
| 2076 |
int posY=0; |
| 2077 |
ImVec2 pos=ImGui::GetMousePos(); |
| 2078 |
pos.x-=rectMin.x; |
| 2079 |
pos.y-=rectMin.y; |
| 2080 |
|
| 2081 |
if (sampleZoom>0) { |
| 2082 |
posX=samplePos+pos.x*sampleZoom; |
| 2083 |
if (posX>(int)sample->samples) posX=-1; |
| 2084 |
} |
| 2085 |
switch (sample->depth) { |
| 2086 |
case DIV_SAMPLE_DEPTH_8BIT: |
| 2087 |
posY=(0.5-pos.y/rectSize.y)*255; |
| 2088 |
break; |
| 2089 |
case DIV_SAMPLE_DEPTH_4BIT: |
| 2090 |
posY=(1-pos.y/rectSize.y)*15; |
| 2091 |
break; |
| 2092 |
default: |
| 2093 |
posY=(0.5-pos.y/rectSize.y)*65535; |
| 2094 |
break; |
| 2095 |
} |
| 2096 |
|
| 2097 |
if (posX>=0) { |
| 2098 |
statusBar2=fmt::sprintf("(%d, %d)",posX,posY); |
| 2099 |
} |
| 2100 |
} |
| 2101 |
|
| 2102 |
dl->PushClipRect(rectMin,rectMax); |
| 2103 |
if (e->isPreviewingSample() && e->getSamplePreviewSample()==curSample) { |
| 2104 |
if (!statusBar2.empty()) { |
| 2105 |
statusBar2+=" | "; |
| 2106 |
} |
| 2107 |
statusBar2+=fmt::sprintf("%.2fHz",e->getSamplePreviewRate()); |
| 2108 |
|
| 2109 |
int start=sampleSelStart; |
| 2110 |
int end=sampleSelEnd; |
| 2111 |
if (start>end) { |
| 2112 |
start^=end; |
| 2113 |
end^=start; |
| 2114 |
start^=end; |
| 2115 |
} |
| 2116 |
ImVec2 p1=rectMin; |
| 2117 |
p1.x+=(e->getSamplePreviewPos()-samplePos)/sampleZoom; |
| 2118 |
ImVec4 posColor=uiColors[GUI_COLOR_SAMPLE_NEEDLE]; |
| 2119 |
ImVec4 posTrail1=posColor; |
| 2120 |
ImVec4 posTrail2=posColor; |
| 2121 |
posTrail1.w*=0.5f; |
| 2122 |
posTrail2.w=0.0f; |
| 2123 |
float trailDistance=(e->getSamplePreviewRate()/100.0f)/sampleZoom; |
| 2124 |
|
| 2125 |
//if (p1.x<rectMin.x) p1.x=rectMin.x; |
| 2126 |
//if (p1.x>rectMax.x) p1.x=rectMax.x; |
| 2127 |
|
| 2128 |
ImVec2 p2=p1; |
| 2129 |
p2.y=rectMax.y; |
| 2130 |
|
| 2131 |
dl->AddRectFilledMultiColor( |
| 2132 |
ImVec2(p1.x-trailDistance,p1.y), |
| 2133 |
p2, |
| 2134 |
ImGui::GetColorU32(posTrail2), |
| 2135 |
ImGui::GetColorU32(posTrail1), |
| 2136 |
ImGui::GetColorU32(posTrail1), |
| 2137 |
ImGui::GetColorU32(posTrail2) |
| 2138 |
); |
| 2139 |
dl->AddLine(p1,p2,ImGui::GetColorU32(posColor)); |
| 2140 |
} |
| 2141 |
|
| 2142 |
if (e->isRunning()) { |
| 2143 |
for (int i=0; i<e->getTotalChannelCount(); i++) { |
| 2144 |
DivSamplePos chanPos=e->getSamplePos(i); |
| 2145 |
if (chanPos.sample!=curSample) continue; |
| 2146 |
|
| 2147 |
int start=sampleSelStart; |
| 2148 |
int end=sampleSelEnd; |
| 2149 |
if (start>end) { |
| 2150 |
start^=end; |
| 2151 |
end^=start; |
| 2152 |
start^=end; |
| 2153 |
} |
| 2154 |
ImVec2 p1=rectMin; |
| 2155 |
p1.x+=(chanPos.pos-samplePos)/sampleZoom; |
| 2156 |
ImVec4 posColor=uiColors[GUI_COLOR_SAMPLE_NEEDLE_PLAYING]; |
| 2157 |
ImVec4 posTrail1=posColor; |
| 2158 |
ImVec4 posTrail2=posColor; |
| 2159 |
posTrail1.w*=0.5f; |
| 2160 |
posTrail2.w=0.0f; |
| 2161 |
float trailDistance=((float)chanPos.freq/100.0f)/sampleZoom; |
| 2162 |
|
| 2163 |
//if (p1.x<rectMin.x) p1.x=rectMin.x; |
| 2164 |
//if (p1.x>rectMax.x) p1.x=rectMax.x; |
| 2165 |
|
| 2166 |
ImVec2 p2=p1; |
| 2167 |
p2.y=rectMax.y; |
| 2168 |
|
| 2169 |
dl->AddRectFilledMultiColor( |
| 2170 |
ImVec2(p1.x-trailDistance,p1.y), |
| 2171 |
p2, |
| 2172 |
ImGui::GetColorU32(posTrail2), |
| 2173 |
ImGui::GetColorU32(posTrail1), |
| 2174 |
ImGui::GetColorU32(posTrail1), |
| 2175 |
ImGui::GetColorU32(posTrail2) |
| 2176 |
); |
| 2177 |
dl->AddLine(p1,p2,ImGui::GetColorU32(posColor)); |
| 2178 |
} |
| 2179 |
} |
| 2180 |
dl->PopClipRect(); |
| 2181 |
|
| 2182 |
bool displayLoopHintsNES=false; |
| 2183 |
bool displayLoopHintsSNES=false; |
| 2184 |
bool displayLoopHintsNDSA=false; |
| 2185 |
bool displayLoopHintsNDS8=false; |
| 2186 |
bool displayLoopHintsAmiga=false; |
| 2187 |
bool displayLoopHintsGBADMA=false; |
| 2188 |
|
| 2189 |
for (int i=0; i<e->song.systemLen; i++) { |
| 2190 |
if (e->song.system[i]==DIV_SYSTEM_NES) { |
| 2191 |
displayLoopHintsNES=true; |
| 2192 |
} |
| 2193 |
if (e->song.system[i]==DIV_SYSTEM_SNES) { |
| 2194 |
displayLoopHintsSNES=true; |
| 2195 |
} |
| 2196 |
if (((e->song.system[i]==DIV_SYSTEM_NDS) && (sample->depth==DIV_SAMPLE_DEPTH_IMA_ADPCM))) { |
| 2197 |
displayLoopHintsNDSA=true; |
| 2198 |
} |
| 2199 |
if (((e->song.system[i]==DIV_SYSTEM_NDS) && (sample->depth==DIV_SAMPLE_DEPTH_8BIT))) { |
| 2200 |
displayLoopHintsNDS8=true; |
| 2201 |
} |
| 2202 |
if (e->song.system[i]==DIV_SYSTEM_AMIGA || |
| 2203 |
e->song.system[i]==DIV_SYSTEM_C219 || |
| 2204 |
((e->song.system[i]==DIV_SYSTEM_YMZ280B) && (sample->depth==DIV_SAMPLE_DEPTH_YMZ_ADPCM)) || |
| 2205 |
((e->song.system[i]==DIV_SYSTEM_NDS) && (sample->depth==DIV_SAMPLE_DEPTH_16BIT))) { |
| 2206 |
displayLoopHintsAmiga=true; |
| 2207 |
} |
| 2208 |
if (e->song.system[i]==DIV_SYSTEM_GBA_DMA) { |
| 2209 |
displayLoopHintsGBADMA=true; |
| 2210 |
} |
| 2211 |
} |
| 2212 |
|
| 2213 |
if (displayLoopStartHints) { |
| 2214 |
if (displayLoopHintsNES) { |
| 2215 |
if (sampleZoom<3.0) { |
| 2216 |
for (int i=0; i<(int)(sampleZoom*avail.x); i++) { |
| 2217 |
if (((i+samplePos)&511)==0) { |
| 2218 |
ImVec2 p1=ImVec2(rectMin.x+((float)i/sampleZoom),rectMin.y); |
| 2219 |
ImVec2 p2=p1; |
| 2220 |
p2.y=rectMax.y; |
| 2221 |
|
| 2222 |
dl->AddLine(p1,p2,ImGui::GetColorU32(uiColors[GUI_COLOR_SAMPLE_LOOP_HINT])); |
| 2223 |
} |
| 2224 |
} |
| 2225 |
} |
| 2226 |
} |
| 2227 |
if (displayLoopHintsSNES) { |
| 2228 |
if (sampleZoom<0.75) { |
| 2229 |
for (int i=0; i<(int)(sampleZoom*avail.x); i++) { |
| 2230 |
if (((i+samplePos)&15)==0) { |
| 2231 |
ImVec2 p1=ImVec2(rectMin.x+((float)i/sampleZoom),rectMin.y); |
| 2232 |
ImVec2 p2=p1; |
| 2233 |
p2.y=rectMax.y; |
| 2234 |
|
| 2235 |
dl->AddLine(p1,p2,ImGui::GetColorU32(uiColors[GUI_COLOR_SAMPLE_LOOP_HINT])); |
| 2236 |
} |
| 2237 |
} |
| 2238 |
} |
| 2239 |
} |
| 2240 |
if (displayLoopHintsNDSA) { |
| 2241 |
if (sampleZoom<0.5) { |
| 2242 |
for (int i=0; i<(int)(sampleZoom*avail.x); i++) { |
| 2243 |
if (((i+samplePos)&7)==0) { |
| 2244 |
ImVec2 p1=ImVec2(rectMin.x+((float)i/sampleZoom),rectMin.y); |
| 2245 |
ImVec2 p2=p1; |
| 2246 |
p2.y=rectMax.y; |
| 2247 |
|
| 2248 |
dl->AddLine(p1,p2,ImGui::GetColorU32(uiColors[GUI_COLOR_SAMPLE_LOOP_HINT])); |
| 2249 |
} |
| 2250 |
} |
| 2251 |
} |
| 2252 |
} |
| 2253 |
if (displayLoopHintsNDS8) { |
| 2254 |
if (sampleZoom<0.375) { |
| 2255 |
for (int i=0; i<(int)(sampleZoom*avail.x); i++) { |
| 2256 |
if (((i+samplePos)&3)==0) { |
| 2257 |
ImVec2 p1=ImVec2(rectMin.x+((float)i/sampleZoom),rectMin.y); |
| 2258 |
ImVec2 p2=p1; |
| 2259 |
p2.y=rectMax.y; |
| 2260 |
|
| 2261 |
dl->AddLine(p1,p2,ImGui::GetColorU32(uiColors[GUI_COLOR_SAMPLE_LOOP_HINT])); |
| 2262 |
} |
| 2263 |
} |
| 2264 |
} |
| 2265 |
} |
| 2266 |
if (displayLoopHintsAmiga) { |
| 2267 |
if (sampleZoom<0.25) { |
| 2268 |
for (int i=0; i<(int)(sampleZoom*avail.x); i++) { |
| 2269 |
if (((i+samplePos)&1)==0) { |
| 2270 |
ImVec2 p1=ImVec2(rectMin.x+((float)i/sampleZoom),rectMin.y); |
| 2271 |
ImVec2 p2=p1; |
| 2272 |
p2.y=rectMax.y; |
| 2273 |
|
| 2274 |
dl->AddLine(p1,p2,ImGui::GetColorU32(uiColors[GUI_COLOR_SAMPLE_LOOP_HINT])); |
| 2275 |
} |
| 2276 |
} |
| 2277 |
} |
| 2278 |
} |
| 2279 |
if (displayLoopHintsGBADMA) { |
| 2280 |
if (sampleZoom<0.6) { |
| 2281 |
for (int i=0; i<(int)(sampleZoom*avail.x); i++) { |
| 2282 |
if (((i+samplePos)&3)==0) { |
| 2283 |
ImVec2 p1=ImVec2(rectMin.x+((float)i/sampleZoom),rectMin.y); |
| 2284 |
ImVec2 p2=p1; |
| 2285 |
p2.y=rectMax.y; |
| 2286 |
|
| 2287 |
dl->AddLine(p1,p2,ImGui::GetColorU32(uiColors[GUI_COLOR_SAMPLE_LOOP_HINT])); |
| 2288 |
} |
| 2289 |
} |
| 2290 |
} |
| 2291 |
} |
| 2292 |
} |
| 2293 |
|
| 2294 |
if (displayLoopEndHints) { |
| 2295 |
if (displayLoopHintsNES) { |
| 2296 |
if (sampleZoom<3.0) { |
| 2297 |
for (int i=0; i<(int)(sampleZoom*avail.x); i++) { |
| 2298 |
if (((i+samplePos-8)&128)==0) { |
| 2299 |
ImVec2 p1=ImVec2(rectMin.x+((float)i/sampleZoom),rectMin.y); |
| 2300 |
ImVec2 p2=p1; |
| 2301 |
p2.y=rectMax.y; |
| 2302 |
|
| 2303 |
dl->AddLine(p1,p2,ImGui::GetColorU32(uiColors[GUI_COLOR_SAMPLE_LOOP_HINT])); |
| 2304 |
} |
| 2305 |
} |
| 2306 |
} |
| 2307 |
} |
| 2308 |
if (displayLoopHintsSNES) { |
| 2309 |
if (sampleZoom<0.75) { |
| 2310 |
for (int i=0; i<(int)(sampleZoom*avail.x); i++) { |
| 2311 |
if (((i+samplePos)&15)==0) { |
| 2312 |
ImVec2 p1=ImVec2(rectMin.x+((float)i/sampleZoom),rectMin.y); |
| 2313 |
ImVec2 p2=p1; |
| 2314 |
p2.y=rectMax.y; |
| 2315 |
|
| 2316 |
dl->AddLine(p1,p2,ImGui::GetColorU32(uiColors[GUI_COLOR_SAMPLE_LOOP_HINT])); |
| 2317 |
} |
| 2318 |
} |
| 2319 |
} |
| 2320 |
} |
| 2321 |
if (displayLoopHintsNDSA) { |
| 2322 |
if (sampleZoom<0.5) { |
| 2323 |
for (int i=0; i<(int)(sampleZoom*avail.x); i++) { |
| 2324 |
if (((i+samplePos)&7)==0) { |
| 2325 |
ImVec2 p1=ImVec2(rectMin.x+((float)i/sampleZoom),rectMin.y); |
| 2326 |
ImVec2 p2=p1; |
| 2327 |
p2.y=rectMax.y; |
| 2328 |
|
| 2329 |
dl->AddLine(p1,p2,ImGui::GetColorU32(uiColors[GUI_COLOR_SAMPLE_LOOP_HINT])); |
| 2330 |
} |
| 2331 |
} |
| 2332 |
} |
| 2333 |
} |
| 2334 |
if (displayLoopHintsNDS8) { |
| 2335 |
if (sampleZoom<0.375) { |
| 2336 |
for (int i=0; i<(int)(sampleZoom*avail.x); i++) { |
| 2337 |
if (((i+samplePos)&3)==0) { |
| 2338 |
ImVec2 p1=ImVec2(rectMin.x+((float)i/sampleZoom),rectMin.y); |
| 2339 |
ImVec2 p2=p1; |
| 2340 |
p2.y=rectMax.y; |
| 2341 |
|
| 2342 |
dl->AddLine(p1,p2,ImGui::GetColorU32(uiColors[GUI_COLOR_SAMPLE_LOOP_HINT])); |
| 2343 |
} |
| 2344 |
} |
| 2345 |
} |
| 2346 |
} |
| 2347 |
if (displayLoopHintsAmiga) { |
| 2348 |
if (sampleZoom<0.25) { |
| 2349 |
for (int i=0; i<(int)(sampleZoom*avail.x); i++) { |
| 2350 |
if (((i+samplePos)&1)==0) { |
| 2351 |
ImVec2 p1=ImVec2(rectMin.x+((float)i/sampleZoom),rectMin.y); |
| 2352 |
ImVec2 p2=p1; |
| 2353 |
p2.y=rectMax.y; |
| 2354 |
|
| 2355 |
dl->AddLine(p1,p2,ImGui::GetColorU32(uiColors[GUI_COLOR_SAMPLE_LOOP_HINT])); |
| 2356 |
} |
| 2357 |
} |
| 2358 |
} |
| 2359 |
} |
| 2360 |
if (displayLoopHintsGBADMA) { |
| 2361 |
if (sampleZoom<0.6) { |
| 2362 |
for (int i=0; i<(int)(sampleZoom*avail.x); i++) { |
| 2363 |
if (((i+samplePos-sample->loopStart)&15)==0) { |
| 2364 |
ImVec2 p1=ImVec2(rectMin.x+((float)i/sampleZoom),rectMin.y); |
| 2365 |
ImVec2 p2=p1; |
| 2366 |
p2.y=rectMax.y; |
| 2367 |
|
| 2368 |
dl->AddLine(p1,p2,ImGui::GetColorU32(uiColors[GUI_COLOR_SAMPLE_LOOP_HINT])); |
| 2369 |
} |
| 2370 |
} |
| 2371 |
} |
| 2372 |
} |
| 2373 |
} |
| 2374 |
|
| 2375 |
if (drawSelection) { |
| 2376 |
int start=sampleSelStart; |
| 2377 |
int end=sampleSelEnd; |
| 2378 |
if (start>end) { |
| 2379 |
start^=end; |
| 2380 |
end^=start; |
| 2381 |
start^=end; |
| 2382 |
} |
| 2383 |
ImVec2 p1=rectMin; |
| 2384 |
p1.x+=(start-samplePos)/sampleZoom; |
| 2385 |
|
| 2386 |
ImVec2 p2=ImVec2(rectMin.x+(end-samplePos)/sampleZoom,rectMax.y); |
| 2387 |
ImVec4 boundColor=uiColors[GUI_COLOR_SAMPLE_SEL_POINT]; |
| 2388 |
ImVec4 selColor=uiColors[GUI_COLOR_SAMPLE_SEL]; |
| 2389 |
|
| 2390 |
if (p1.x<rectMin.x) p1.x=rectMin.x; |
| 2391 |
if (p1.x>rectMax.x) p1.x=rectMax.x; |
| 2392 |
|
| 2393 |
if (p2.x<rectMin.x) p2.x=rectMin.x; |
| 2394 |
if (p2.x>rectMax.x) p2.x=rectMax.x; |
| 2395 |
|
| 2396 |
dl->AddRectFilled(p1,p2,ImGui::GetColorU32(selColor)); |
| 2397 |
dl->AddLine(ImVec2(p1.x,p1.y),ImVec2(p1.x,p2.y),ImGui::GetColorU32(boundColor)); |
| 2398 |
if (start!=end) { |
| 2399 |
dl->AddLine(ImVec2(p2.x,p1.y),ImVec2(p2.x,p2.y),ImGui::GetColorU32(boundColor)); |
| 2400 |
} |
| 2401 |
} |
| 2402 |
|
| 2403 |
ImS64 scrollV=samplePos; |
| 2404 |
ImS64 availV=round(rectSize.x*sampleZoom); |
| 2405 |
ImS64 contentsV=MAX(sample->samples,MAX(availV,1)); |
| 2406 |
|
| 2407 |
ImGuiID scrollbarID=ImGui::GetID("sampleScroll"); |
| 2408 |
ImGui::KeepAliveID(scrollbarID); |
| 2409 |
if (ImGui::ScrollbarEx(ImRect(ImVec2(rectMin.x,rectMax.y),ImVec2(rectMax.x,rectMax.y+ImGui::GetStyle().ScrollbarSize)),scrollbarID,ImGuiAxis_X,&scrollV,availV,contentsV,0)) { |
| 2410 |
if (!sampleZoomAuto && samplePos!=scrollV) { |
| 2411 |
samplePos=scrollV; |
| 2412 |
updateSampleTex=true; |
| 2413 |
} |
| 2414 |
} |
| 2415 |
|
| 2416 |
if (sample->depth!=DIV_SAMPLE_DEPTH_8BIT && sample->depth!=DIV_SAMPLE_DEPTH_16BIT && sampleDragMode) { |
| 2417 |
statusBar=_("Non-8/16-bit samples cannot be edited without prior conversion."); |
| 2418 |
} |
| 2419 |
|
| 2420 |
ImGui::SetCursorPosY(ImGui::GetCursorPosY()+ImGui::GetStyle().ScrollbarSize); |
| 2421 |
ImGui::PushStyleVar(ImGuiStyleVar_CellPadding,ImVec2(0,0)); |
| 2422 |
if (ImGui::BeginTable("SEStatus",3,ImGuiTableFlags_BordersInnerV)) { |
| 2423 |
ImGui::TableSetupColumn("c0",ImGuiTableColumnFlags_WidthStretch,0.7); |
| 2424 |
ImGui::TableSetupColumn("c1",ImGuiTableColumnFlags_WidthStretch,0.3); |
| 2425 |
ImGui::TableSetupColumn("c2",ImGuiTableColumnFlags_WidthFixed); |
| 2426 |
|
| 2427 |
ImGui::TableNextRow(); |
| 2428 |
ImGui::TableNextColumn(); |
| 2429 |
ImGui::AlignTextToFramePadding(); |
| 2430 |
ImGui::TextUnformatted(statusBar.c_str()); |
| 2431 |
if (!sampleDragMode) { |
| 2432 |
ImGui::SameLine(); |
| 2433 |
ImGui::SetNextItemWidth(140.0f*dpiScale); |
| 2434 |
if (ImGui::InputInt("##SESelStart",&sampleSelStart)) { |
| 2435 |
if (sampleSelStart<0) sampleSelStart=0; |
| 2436 |
if (sampleSelStart>(int)sample->samples) sampleSelStart=sample->samples; |
| 2437 |
if (sampleSelEnd<sampleSelStart) sampleSelEnd=sampleSelStart; |
| 2438 |
} |
| 2439 |
ImGui::SameLine(); |
| 2440 |
ImGui::SetNextItemWidth(140.0f*dpiScale); |
| 2441 |
if (ImGui::InputInt("##SESelEnd",&sampleSelEnd)) { |
| 2442 |
if (sampleSelEnd<0) sampleSelEnd=0; |
| 2443 |
if (sampleSelEnd>(int)sample->samples) sampleSelEnd=sample->samples; |
| 2444 |
if (sampleSelEnd<sampleSelStart) sampleSelEnd=sampleSelStart; |
| 2445 |
} |
| 2446 |
if (!statusBar4.empty()) { |
| 2447 |
ImGui::SameLine(); |
| 2448 |
ImGui::AlignTextToFramePadding(); |
| 2449 |
ImGui::TextUnformatted(statusBar4.c_str()); |
| 2450 |
} |
| 2451 |
} |
| 2452 |
|
| 2453 |
ImGui::TableNextColumn(); |
| 2454 |
if (!warnRate.empty()) { |
| 2455 |
ImGui::PushStyleColor(ImGuiCol_Text,uiColors[GUI_COLOR_WARNING]); |
| 2456 |
ImGui::AlignTextToFramePadding(); |
| 2457 |
ImGui::TextUnformatted(statusBar2.c_str()); |
| 2458 |
ImGui::PopStyleColor(); |
| 2459 |
if (ImGui::IsItemHovered()) { |
| 2460 |
ImGui::SetTooltip("%s",warnRate.c_str()); |
| 2461 |
} |
| 2462 |
} else { |
| 2463 |
ImGui::AlignTextToFramePadding(); |
| 2464 |
ImGui::TextUnformatted(statusBar2.c_str()); |
| 2465 |
} |
| 2466 |
|
| 2467 |
ImGui::TableNextColumn(); |
| 2468 |
if (!warnLength.empty()) { |
| 2469 |
ImGui::PushStyleColor(ImGuiCol_Text,uiColors[GUI_COLOR_WARNING]); |
| 2470 |
ImGui::AlignTextToFramePadding(); |
| 2471 |
ImGui::TextUnformatted(statusBar3.c_str()); |
| 2472 |
ImGui::PopStyleColor(); |
| 2473 |
if (ImGui::IsItemHovered()) { |
| 2474 |
ImGui::SetTooltip("%s",warnLength.c_str()); |
| 2475 |
} |
| 2476 |
} else { |
| 2477 |
ImGui::AlignTextToFramePadding(); |
| 2478 |
ImGui::TextUnformatted(statusBar3.c_str()); |
| 2479 |
} |
| 2480 |
|
| 2481 |
ImGui::EndTable(); |
| 2482 |
} |
| 2483 |
ImGui::PopStyleVar(); |
| 2484 |
} |
| 2485 |
} |
| 2486 |
} |
| 2487 |
if (ImGui::IsWindowFocused(ImGuiFocusedFlags_ChildWindows)) curWindow=GUI_WINDOW_SAMPLE_EDIT; |
| 2488 |
ImGui::End(); |
| 2489 |
} |
| 2490 |
|
| 2491 |
void FurnaceGUI::doUndoSample() { |
| 2492 |
if (!sampleEditOpen) return; |
| 2493 |
if (curSample<0 || curSample>=(int)e->song.sample.size()) return; |
| 2494 |
DivSample* sample=e->song.sample[curSample]; |
| 2495 |
e->lockEngine([this,sample]() { |
| 2496 |
if (sample->undo()==2) { |
| 2497 |
e->renderSamples(curSample); |
| 2498 |
updateSampleTex=true; |
| 2499 |
} |
| 2500 |
}); |
| 2501 |
} |
| 2502 |
|
| 2503 |
void FurnaceGUI::doRedoSample() { |
| 2504 |
if (!sampleEditOpen) return; |
| 2505 |
if (curSample<0 || curSample>=(int)e->song.sample.size()) return; |
| 2506 |
DivSample* sample=e->song.sample[curSample]; |
| 2507 |
e->lockEngine([this,sample]() { |
| 2508 |
if (sample->redo()==2) { |
| 2509 |
e->renderSamples(curSample); |
| 2510 |
updateSampleTex=true; |
| 2511 |
} |
| 2512 |
}); |
| 2513 |
} |