| 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 |
#include "gui.h" |
| 21 |
#include "../ta-log.h" |
| 22 |
#include "guiConst.h" |
| 23 |
#include <fmt/printf.h> |
| 24 |
|
| 25 |
#include "actionUtil.h" |
| 26 |
|
| 27 |
static const char* modPlugFormatHeaders[]={ |
| 28 |
"ModPlug Tracker MOD", |
| 29 |
"ModPlug Tracker S3M", |
| 30 |
"ModPlug Tracker XM", |
| 31 |
"ModPlug Tracker XM", |
| 32 |
"ModPlug Tracker IT", |
| 33 |
"ModPlug Tracker IT", |
| 34 |
"ModPlug Tracker MPT", |
| 35 |
NULL, |
| 36 |
}; |
| 37 |
|
| 38 |
const char* FurnaceGUI::noteNameNormal(short note, short octave) { |
| 39 |
if (note==100) { // note cut |
| 40 |
return "OFF"; |
| 41 |
} else if (note==101) { // note off and envelope release |
| 42 |
return "==="; |
| 43 |
} else if (note==102) { // envelope release only |
| 44 |
return "REL"; |
| 45 |
} else if (octave==0 && note==0) { |
| 46 |
return "..."; |
| 47 |
} |
| 48 |
int seek=(note+(signed char)octave*12)+60; |
| 49 |
if (seek<0 || seek>=180) { |
| 50 |
return "???"; |
| 51 |
} |
| 52 |
return noteNames[seek]; |
| 53 |
} |
| 54 |
|
| 55 |
void FurnaceGUI::prepareUndo(ActionType action, UndoRegion region) { |
| 56 |
undoCursor=cursor; |
| 57 |
undoSelStart=selStart; |
| 58 |
undoSelEnd=selEnd; |
| 59 |
undoOrder=curOrder; |
| 60 |
|
| 61 |
if (region.begin.ord==-1) { |
| 62 |
region.begin.ord=selStart.order; |
| 63 |
region.end.ord=selEnd.order; |
| 64 |
region.begin.x=0; |
| 65 |
region.end.x=e->getTotalChannelCount()-1; |
| 66 |
region.begin.y=0; |
| 67 |
region.end.y=e->curSubSong->patLen-1; |
| 68 |
} else { |
| 69 |
if (region.begin.ord<0) region.begin.ord=0; |
| 70 |
if (region.begin.ord>e->curSubSong->ordersLen) region.begin.ord=e->curSubSong->ordersLen; |
| 71 |
if (region.end.ord<0) region.end.ord=0; |
| 72 |
if (region.end.ord>e->curSubSong->ordersLen) region.end.ord=e->curSubSong->ordersLen; |
| 73 |
if (region.begin.x<0) region.begin.x=0; |
| 74 |
if (region.begin.x>=e->getTotalChannelCount()) region.begin.x=e->getTotalChannelCount()-1; |
| 75 |
if (region.end.x<0) region.end.x=0; |
| 76 |
if (region.end.x>=e->getTotalChannelCount()) region.end.x=e->getTotalChannelCount()-1; |
| 77 |
if (region.begin.y<0) region.begin.y=0; |
| 78 |
if (region.begin.y>=e->curSubSong->patLen) region.begin.y=e->curSubSong->patLen-1; |
| 79 |
if (region.end.y<0) region.end.y=0; |
| 80 |
if (region.end.y>=e->curSubSong->patLen) region.end.y=e->curSubSong->patLen-1; |
| 81 |
} |
| 82 |
|
| 83 |
switch (action) { |
| 84 |
case GUI_UNDO_CHANGE_ORDER: |
| 85 |
memcpy(&oldOrders,e->curOrders,sizeof(DivOrders)); |
| 86 |
oldOrdersLen=e->curSubSong->ordersLen; |
| 87 |
break; |
| 88 |
case GUI_UNDO_PATTERN_EDIT: |
| 89 |
case GUI_UNDO_PATTERN_DELETE: |
| 90 |
case GUI_UNDO_PATTERN_PULL: |
| 91 |
case GUI_UNDO_PATTERN_PUSH: |
| 92 |
case GUI_UNDO_PATTERN_CUT: |
| 93 |
case GUI_UNDO_PATTERN_PASTE: |
| 94 |
case GUI_UNDO_PATTERN_CHANGE_INS: |
| 95 |
case GUI_UNDO_PATTERN_INTERPOLATE: |
| 96 |
case GUI_UNDO_PATTERN_FADE: |
| 97 |
case GUI_UNDO_PATTERN_SCALE: |
| 98 |
case GUI_UNDO_PATTERN_RANDOMIZE: |
| 99 |
case GUI_UNDO_PATTERN_INVERT_VAL: |
| 100 |
case GUI_UNDO_PATTERN_FLIP: |
| 101 |
case GUI_UNDO_PATTERN_COLLAPSE: |
| 102 |
case GUI_UNDO_PATTERN_EXPAND: |
| 103 |
case GUI_UNDO_PATTERN_DRAG: |
| 104 |
for (int h=region.begin.ord; h<=region.end.ord; h++) { |
| 105 |
for (int i=region.begin.x; i<=region.end.x; i++) { |
| 106 |
unsigned short id=h|(i<<8); |
| 107 |
DivPattern* p=NULL; |
| 108 |
|
| 109 |
auto it=oldPatMap.find(id); |
| 110 |
if (it==oldPatMap.end()) { |
| 111 |
p=oldPatMap[id]=new DivPattern; |
| 112 |
//logV("oldPatMap: allocating for %.4x",id); |
| 113 |
} else { |
| 114 |
p=it->second; |
| 115 |
} |
| 116 |
|
| 117 |
e->curPat[i].getPattern(e->curOrders->ord[i][h],false)->copyOn(p); |
| 118 |
} |
| 119 |
} |
| 120 |
break; |
| 121 |
case GUI_UNDO_PATTERN_COLLAPSE_SONG: |
| 122 |
case GUI_UNDO_PATTERN_EXPAND_SONG: // this is handled by doCollapseSong/doExpandSong |
| 123 |
break; |
| 124 |
case GUI_UNDO_REPLACE: // this is handled by doReplace() |
| 125 |
break; |
| 126 |
} |
| 127 |
} |
| 128 |
|
| 129 |
void FurnaceGUI::makeUndo(ActionType action, UndoRegion region) { |
| 130 |
bool doPush=false; |
| 131 |
bool shallWalk=false; |
| 132 |
UndoStep s; |
| 133 |
s.type=action; |
| 134 |
s.oldCursor=undoCursor; |
| 135 |
s.oldSelStart=undoSelStart; |
| 136 |
s.oldSelEnd=undoSelEnd; |
| 137 |
s.oldScroll=patScroll; |
| 138 |
s.oldOrder=undoOrder; |
| 139 |
s.newCursor=cursor; |
| 140 |
s.newSelStart=selStart; |
| 141 |
s.newSelEnd=selEnd; |
| 142 |
s.newScroll=(nextScroll>=0.0f)?nextScroll:patScroll; |
| 143 |
s.newOrder=curOrder; |
| 144 |
s.oldOrdersLen=oldOrdersLen; |
| 145 |
s.newOrdersLen=e->curSubSong->ordersLen; |
| 146 |
s.nibble=curNibble; |
| 147 |
size_t subSong=e->getCurrentSubSong(); |
| 148 |
|
| 149 |
if (region.begin.ord==-1) { |
| 150 |
region.begin.ord=selStart.order; |
| 151 |
region.end.ord=selEnd.order; |
| 152 |
region.begin.x=0; |
| 153 |
region.end.x=e->getTotalChannelCount()-1; |
| 154 |
region.begin.y=0; |
| 155 |
region.end.y=e->curSubSong->patLen-1; |
| 156 |
} else { |
| 157 |
if (region.begin.ord<0) region.begin.ord=0; |
| 158 |
if (region.begin.ord>e->curSubSong->ordersLen) region.begin.ord=e->curSubSong->ordersLen; |
| 159 |
if (region.end.ord<0) region.end.ord=0; |
| 160 |
if (region.end.ord>e->curSubSong->ordersLen) region.end.ord=e->curSubSong->ordersLen; |
| 161 |
if (region.begin.x<0) region.begin.x=0; |
| 162 |
if (region.begin.x>=e->getTotalChannelCount()) region.begin.x=e->getTotalChannelCount()-1; |
| 163 |
if (region.end.x<0) region.end.x=0; |
| 164 |
if (region.end.x>=e->getTotalChannelCount()) region.end.x=e->getTotalChannelCount()-1; |
| 165 |
if (region.begin.y<0) region.begin.y=0; |
| 166 |
if (region.begin.y>=e->curSubSong->patLen) region.begin.y=e->curSubSong->patLen-1; |
| 167 |
if (region.end.y<0) region.end.y=0; |
| 168 |
if (region.end.y>=e->curSubSong->patLen) region.end.y=e->curSubSong->patLen-1; |
| 169 |
} |
| 170 |
|
| 171 |
switch (action) { |
| 172 |
case GUI_UNDO_CHANGE_ORDER: |
| 173 |
for (int i=0; i<DIV_MAX_CHANS; i++) { |
| 174 |
for (int j=0; j<128; j++) { |
| 175 |
if (oldOrders.ord[i][j]!=e->curOrders->ord[i][j]) { |
| 176 |
s.ord.push_back(UndoOrderData(subSong,i,j,oldOrders.ord[i][j],e->curOrders->ord[i][j])); |
| 177 |
} |
| 178 |
} |
| 179 |
} |
| 180 |
if (oldOrdersLen!=e->curSubSong->ordersLen) { |
| 181 |
doPush=true; |
| 182 |
} |
| 183 |
if (!s.ord.empty()) { |
| 184 |
doPush=true; |
| 185 |
} |
| 186 |
break; |
| 187 |
case GUI_UNDO_PATTERN_EDIT: |
| 188 |
case GUI_UNDO_PATTERN_DELETE: |
| 189 |
case GUI_UNDO_PATTERN_PULL: |
| 190 |
case GUI_UNDO_PATTERN_PUSH: |
| 191 |
case GUI_UNDO_PATTERN_CUT: |
| 192 |
case GUI_UNDO_PATTERN_PASTE: |
| 193 |
case GUI_UNDO_PATTERN_CHANGE_INS: |
| 194 |
case GUI_UNDO_PATTERN_INTERPOLATE: |
| 195 |
case GUI_UNDO_PATTERN_FADE: |
| 196 |
case GUI_UNDO_PATTERN_SCALE: |
| 197 |
case GUI_UNDO_PATTERN_RANDOMIZE: |
| 198 |
case GUI_UNDO_PATTERN_INVERT_VAL: |
| 199 |
case GUI_UNDO_PATTERN_FLIP: |
| 200 |
case GUI_UNDO_PATTERN_COLLAPSE: |
| 201 |
case GUI_UNDO_PATTERN_EXPAND: |
| 202 |
case GUI_UNDO_PATTERN_DRAG: |
| 203 |
for (int h=region.begin.ord; h<=region.end.ord; h++) { |
| 204 |
for (int i=region.begin.x; i<=region.end.x; i++) { |
| 205 |
DivPattern* p=e->curPat[i].getPattern(e->curOrders->ord[i][h],false); |
| 206 |
DivPattern* op=NULL; |
| 207 |
unsigned short id=h|(i<<8); |
| 208 |
|
| 209 |
auto it=oldPatMap.find(id); |
| 210 |
if (it==oldPatMap.end()) { |
| 211 |
logW(_("no data in oldPatMap for channel %d!"),i); |
| 212 |
continue; |
| 213 |
} else { |
| 214 |
op=it->second; |
| 215 |
} |
| 216 |
|
| 217 |
int jBegin=0; |
| 218 |
int jEnd=e->curSubSong->patLen-1; |
| 219 |
|
| 220 |
if (h==region.begin.ord) jBegin=region.begin.y; |
| 221 |
if (h==region.end.ord) jEnd=region.end.y; |
| 222 |
|
| 223 |
for (int j=jBegin; j<=jEnd; j++) { |
| 224 |
for (int k=0; k<DIV_MAX_COLS; k++) { |
| 225 |
if (p->data[j][k]!=op->data[j][k]) { |
| 226 |
s.pat.push_back(UndoPatternData(subSong,i,e->curOrders->ord[i][h],j,k,op->data[j][k],p->data[j][k])); |
| 227 |
|
| 228 |
if (k>=4) { |
| 229 |
if (op->data[j][k&(~1)]==0x0b || |
| 230 |
p->data[j][k&(~1)]==0x0b || |
| 231 |
op->data[j][k&(~1)]==0x0d || |
| 232 |
p->data[j][k&(~1)]==0x0d || |
| 233 |
op->data[j][k&(~1)]==0xff || |
| 234 |
p->data[j][k&(~1)]==0xff) { |
| 235 |
shallWalk=true; |
| 236 |
} |
| 237 |
} |
| 238 |
|
| 239 |
} |
| 240 |
} |
| 241 |
} |
| 242 |
} |
| 243 |
} |
| 244 |
if (!s.pat.empty()) { |
| 245 |
doPush=true; |
| 246 |
} |
| 247 |
break; |
| 248 |
case GUI_UNDO_PATTERN_COLLAPSE_SONG: |
| 249 |
case GUI_UNDO_PATTERN_EXPAND_SONG: // this is handled by doCollapseSong/doExpandSong |
| 250 |
break; |
| 251 |
case GUI_UNDO_REPLACE: // this is handled by doReplace() |
| 252 |
break; |
| 253 |
} |
| 254 |
if (doPush) { |
| 255 |
MARK_MODIFIED; |
| 256 |
undoHist.push_back(s); |
| 257 |
redoHist.clear(); |
| 258 |
if (undoHist.size()>settings.maxUndoSteps) undoHist.pop_front(); |
| 259 |
} |
| 260 |
if (shallWalk) { |
| 261 |
e->walkSong(loopOrder,loopRow,loopEnd); |
| 262 |
} |
| 263 |
|
| 264 |
// garbage collection |
| 265 |
for (std::pair<unsigned short,DivPattern*> i: oldPatMap) { |
| 266 |
delete i.second; |
| 267 |
} |
| 268 |
oldPatMap.clear(); |
| 269 |
} |
| 270 |
|
| 271 |
void FurnaceGUI::doSelectAll() { |
| 272 |
finishSelection(); |
| 273 |
curNibble=false; |
| 274 |
if (selStart.xFine==0 && selEnd.xFine==2+e->curPat[selEnd.xCoarse].effectCols*2) { |
| 275 |
if (selStart.y==0 && selEnd.y==e->curSubSong->patLen-1) { // select entire pattern |
| 276 |
selStart.xCoarse=0; |
| 277 |
selStart.xFine=0; |
| 278 |
selEnd.xCoarse=e->getTotalChannelCount()-1; |
| 279 |
selEnd.xFine=2+e->curPat[selEnd.xCoarse].effectCols*2; |
| 280 |
} else { // select entire column |
| 281 |
selStart.y=0; |
| 282 |
selEnd.y=e->curSubSong->patLen-1; |
| 283 |
} |
| 284 |
} else { |
| 285 |
int selStartX=0; |
| 286 |
int selEndX=0; |
| 287 |
int chanCount=e->getTotalChannelCount(); |
| 288 |
// find row position |
| 289 |
for (SelectionPoint i; i.xCoarse!=selStart.xCoarse || i.xFine!=selStart.xFine; selStartX++) { |
| 290 |
i.xFine++; |
| 291 |
if (i.xCoarse>=chanCount) { |
| 292 |
logE("xCoarse of selStart iterator went too far!"); |
| 293 |
showError("you have found a bug. please report it now."); |
| 294 |
i.xCoarse=chanCount-1; |
| 295 |
break; |
| 296 |
} |
| 297 |
if (i.xFine>=3+e->curPat[i.xCoarse].effectCols*2) { |
| 298 |
i.xFine=0; |
| 299 |
i.xCoarse++; |
| 300 |
} |
| 301 |
} |
| 302 |
for (SelectionPoint i; i.xCoarse!=selEnd.xCoarse || i.xFine!=selEnd.xFine; selEndX++) { |
| 303 |
i.xFine++; |
| 304 |
if (i.xCoarse>=chanCount) { |
| 305 |
logE("xCoarse of selEnd iterator went too far!"); |
| 306 |
showError("you have found a bug. please report it now."); |
| 307 |
i.xCoarse=chanCount-1; |
| 308 |
break; |
| 309 |
} |
| 310 |
if (i.xFine>=3+e->curPat[i.xCoarse].effectCols*2) { |
| 311 |
i.xFine=0; |
| 312 |
i.xCoarse++; |
| 313 |
} |
| 314 |
} |
| 315 |
|
| 316 |
float aspect=float(selEndX-selStartX+1)/float(selEnd.y-selStart.y+1); |
| 317 |
if (selStart.order!=selEnd.order) { |
| 318 |
// guarantee vertical aspect ratio |
| 319 |
aspect=0.0f; |
| 320 |
} |
| 321 |
if (aspect<=1.0f && !(selStart.y==0 && selEnd.y==e->curSubSong->patLen-1)) { // up-down |
| 322 |
selStart.y=0; |
| 323 |
selEnd.y=e->curSubSong->patLen-1; |
| 324 |
} else { // left-right |
| 325 |
selStart.xFine=0; |
| 326 |
selEnd.xFine=2+e->curPat[selEnd.xCoarse].effectCols*2; |
| 327 |
} |
| 328 |
} |
| 329 |
} |
| 330 |
|
| 331 |
#define maskOut(m,x) \ |
| 332 |
if (x==0) { \ |
| 333 |
if (!m.note) continue; \ |
| 334 |
} else if (x==1) { \ |
| 335 |
if (!m.ins) continue; \ |
| 336 |
} else if (x==2) { \ |
| 337 |
if (!m.vol) continue; \ |
| 338 |
} else if (((x)&1)==0) { \ |
| 339 |
if (!m.effectVal) continue; \ |
| 340 |
} else if (((x)&1)==1) { \ |
| 341 |
if (!m.effect) continue; \ |
| 342 |
} |
| 343 |
|
| 344 |
#define touch(_order,_y) \ |
| 345 |
if (opTouched[(e->curOrders->ord[iCoarse][_order]<<8)|(_y)]) continue; \ |
| 346 |
opTouched[(e->curOrders->ord[iCoarse][_order]<<8)|(_y)]=true; |
| 347 |
|
| 348 |
#define resetTouches memset(opTouched,0,DIV_MAX_PATTERNS*DIV_MAX_ROWS); |
| 349 |
|
| 350 |
void FurnaceGUI::doDelete() { |
| 351 |
finishSelection(); |
| 352 |
prepareUndo(GUI_UNDO_PATTERN_DELETE); |
| 353 |
curNibble=false; |
| 354 |
|
| 355 |
int iCoarse=selStart.xCoarse; |
| 356 |
int iFine=selStart.xFine; |
| 357 |
for (; iCoarse<=selEnd.xCoarse; iCoarse++) { |
| 358 |
if (!e->curSubSong->chanShow[iCoarse]) continue; |
| 359 |
for (; iFine<3+e->curPat[iCoarse].effectCols*2 && (iCoarse<selEnd.xCoarse || iFine<=selEnd.xFine); iFine++) { |
| 360 |
int jOrder=selStart.order; |
| 361 |
int j=selStart.y; |
| 362 |
maskOut(opMaskDelete,iFine); |
| 363 |
resetTouches; |
| 364 |
for (; jOrder<=selEnd.order; jOrder++) { |
| 365 |
DivPattern* pat=e->curPat[iCoarse].getPattern(e->curOrders->ord[iCoarse][jOrder],true); |
| 366 |
for (; j<e->curSubSong->patLen && (j<=selEnd.y || jOrder<selEnd.order); j++) { |
| 367 |
touch(jOrder,j); |
| 368 |
if (iFine==0) { |
| 369 |
pat->data[j][iFine]=0; |
| 370 |
if (selStart.y==selEnd.y && selStart.order==selEnd.order) pat->data[j][2]=-1; |
| 371 |
} |
| 372 |
pat->data[j][iFine+1]=(iFine<1)?0:-1; |
| 373 |
|
| 374 |
if (selStart.y==selEnd.y && selStart.order==selEnd.order && iFine>2 && iFine&1 && settings.effectDeletionAltersValue) { |
| 375 |
pat->data[j][iFine+2]=-1; |
| 376 |
} |
| 377 |
} |
| 378 |
j=0; |
| 379 |
} |
| 380 |
} |
| 381 |
iFine=0; |
| 382 |
} |
| 383 |
|
| 384 |
makeUndo(GUI_UNDO_PATTERN_DELETE); |
| 385 |
} |
| 386 |
|
| 387 |
void FurnaceGUI::doPullDelete() { |
| 388 |
finishSelection(); |
| 389 |
|
| 390 |
if (selStart.order!=selEnd.order) { |
| 391 |
showError(_("you can only pull delete within the same order.")); |
| 392 |
return; |
| 393 |
} |
| 394 |
|
| 395 |
prepareUndo(GUI_UNDO_PATTERN_PULL); |
| 396 |
curNibble=false; |
| 397 |
|
| 398 |
if (settings.pullDeleteBehavior) { |
| 399 |
if (--selStart.y<0) { |
| 400 |
if (--selStart.order<0) { |
| 401 |
selStart.order=0; |
| 402 |
selStart.y=0; |
| 403 |
} else { |
| 404 |
selStart.y+=e->curSubSong->patLen; |
| 405 |
} |
| 406 |
} |
| 407 |
if (--selEnd.y<0) { |
| 408 |
if (--selEnd.order<0) { |
| 409 |
selEnd.order=0; |
| 410 |
selEnd.y=0; |
| 411 |
} else { |
| 412 |
selEnd.y+=e->curSubSong->patLen; |
| 413 |
} |
| 414 |
} |
| 415 |
if (--cursor.y<0) { |
| 416 |
if (--cursor.order<0) { |
| 417 |
cursor.order=0; |
| 418 |
cursor.y=0; |
| 419 |
} else { |
| 420 |
cursor.y+=e->curSubSong->patLen; |
| 421 |
} |
| 422 |
} |
| 423 |
updateScroll(cursor.y); |
| 424 |
} |
| 425 |
|
| 426 |
SelectionPoint sStart=selStart; |
| 427 |
SelectionPoint sEnd=selEnd; |
| 428 |
|
| 429 |
if (selStart.xCoarse==selEnd.xCoarse && selStart.xFine==selEnd.xFine && selStart.y==selEnd.y && selStart.order==selEnd.order && settings.pullDeleteRow) { |
| 430 |
sStart.xFine=0; |
| 431 |
sEnd.xFine=2+e->curPat[sEnd.xCoarse].effectCols*2; |
| 432 |
} |
| 433 |
|
| 434 |
int iCoarse=sStart.xCoarse; |
| 435 |
int iFine=sStart.xFine; |
| 436 |
for (; iCoarse<=sEnd.xCoarse; iCoarse++) { |
| 437 |
if (!e->curSubSong->chanShow[iCoarse]) continue; |
| 438 |
DivPattern* pat=e->curPat[iCoarse].getPattern(e->curOrders->ord[iCoarse][curOrder],true); |
| 439 |
for (; iFine<3+e->curPat[iCoarse].effectCols*2 && (iCoarse<sEnd.xCoarse || iFine<=sEnd.xFine); iFine++) { |
| 440 |
maskOut(opMaskPullDelete,iFine); |
| 441 |
for (int j=sStart.y; j<e->curSubSong->patLen; j++) { |
| 442 |
if (j<e->curSubSong->patLen-1) { |
| 443 |
if (iFine==0) { |
| 444 |
pat->data[j][iFine]=pat->data[j+1][iFine]; |
| 445 |
} |
| 446 |
pat->data[j][iFine+1]=pat->data[j+1][iFine+1]; |
| 447 |
} else { |
| 448 |
if (iFine==0) { |
| 449 |
pat->data[j][iFine]=0; |
| 450 |
} |
| 451 |
pat->data[j][iFine+1]=(iFine<1)?0:-1; |
| 452 |
} |
| 453 |
} |
| 454 |
} |
| 455 |
iFine=0; |
| 456 |
} |
| 457 |
|
| 458 |
makeUndo(GUI_UNDO_PATTERN_PULL); |
| 459 |
} |
| 460 |
|
| 461 |
void FurnaceGUI::doInsert() { |
| 462 |
finishSelection(); |
| 463 |
|
| 464 |
if (selStart.order!=selEnd.order) { |
| 465 |
showError(_("you can only insert/push within the same order.")); |
| 466 |
return; |
| 467 |
} |
| 468 |
|
| 469 |
prepareUndo(GUI_UNDO_PATTERN_PUSH); |
| 470 |
curNibble=false; |
| 471 |
|
| 472 |
SelectionPoint sStart=selStart; |
| 473 |
SelectionPoint sEnd=selEnd; |
| 474 |
|
| 475 |
if (selStart.xCoarse==selEnd.xCoarse && selStart.xFine==selEnd.xFine && selStart.y==selEnd.y && selStart.order==selEnd.order && settings.insertBehavior) { |
| 476 |
sStart.xFine=0; |
| 477 |
sEnd.xFine=2+e->curPat[sEnd.xCoarse].effectCols*2; |
| 478 |
} |
| 479 |
|
| 480 |
int iCoarse=sStart.xCoarse; |
| 481 |
int iFine=sStart.xFine; |
| 482 |
for (; iCoarse<=sEnd.xCoarse; iCoarse++) { |
| 483 |
if (!e->curSubSong->chanShow[iCoarse]) continue; |
| 484 |
DivPattern* pat=e->curPat[iCoarse].getPattern(e->curOrders->ord[iCoarse][curOrder],true); |
| 485 |
for (; iFine<3+e->curPat[iCoarse].effectCols*2 && (iCoarse<sEnd.xCoarse || iFine<=sEnd.xFine); iFine++) { |
| 486 |
maskOut(opMaskInsert,iFine); |
| 487 |
for (int j=e->curSubSong->patLen-1; j>=sStart.y; j--) { |
| 488 |
if (j==sStart.y) { |
| 489 |
if (iFine==0) { |
| 490 |
pat->data[j][iFine]=0; |
| 491 |
} |
| 492 |
pat->data[j][iFine+1]=(iFine<1)?0:-1; |
| 493 |
} else { |
| 494 |
if (iFine==0) { |
| 495 |
pat->data[j][iFine]=pat->data[j-1][iFine]; |
| 496 |
} |
| 497 |
pat->data[j][iFine+1]=pat->data[j-1][iFine+1]; |
| 498 |
} |
| 499 |
} |
| 500 |
} |
| 501 |
iFine=0; |
| 502 |
} |
| 503 |
|
| 504 |
makeUndo(GUI_UNDO_PATTERN_PUSH); |
| 505 |
} |
| 506 |
|
| 507 |
void FurnaceGUI::doTranspose(int amount, OperationMask& mask) { |
| 508 |
finishSelection(); |
| 509 |
prepareUndo(GUI_UNDO_PATTERN_DELETE); |
| 510 |
curNibble=false; |
| 511 |
|
| 512 |
int iCoarse=selStart.xCoarse; |
| 513 |
int iFine=selStart.xFine; |
| 514 |
for (; iCoarse<=selEnd.xCoarse; iCoarse++) { |
| 515 |
if (!e->curSubSong->chanShow[iCoarse]) continue; |
| 516 |
for (; iFine<3+e->curPat[iCoarse].effectCols*2 && (iCoarse<selEnd.xCoarse || iFine<=selEnd.xFine); iFine++) { |
| 517 |
int jOrder=selStart.order; |
| 518 |
int j=selStart.y; |
| 519 |
maskOut(mask,iFine); |
| 520 |
resetTouches; |
| 521 |
for (; jOrder<=selEnd.order; jOrder++) { |
| 522 |
DivPattern* pat=e->curPat[iCoarse].getPattern(e->curOrders->ord[iCoarse][jOrder],true); |
| 523 |
for (; j<e->curSubSong->patLen && (j<=selEnd.y || jOrder<selEnd.order); j++) { |
| 524 |
touch(jOrder,j); |
| 525 |
if (iFine==0) { |
| 526 |
int origNote=pat->data[j][0]; |
| 527 |
int origOctave=(signed char)pat->data[j][1]; |
| 528 |
if (origNote!=0 && origNote!=100 && origNote!=101 && origNote!=102) { |
| 529 |
origNote+=amount; |
| 530 |
while (origNote>12) { |
| 531 |
origNote-=12; |
| 532 |
origOctave++; |
| 533 |
} |
| 534 |
while (origNote<1) { |
| 535 |
origNote+=12; |
| 536 |
origOctave--; |
| 537 |
} |
| 538 |
if (origOctave==9 && origNote>11) { |
| 539 |
origNote=11; |
| 540 |
origOctave=9; |
| 541 |
} |
| 542 |
if (origOctave>9) { |
| 543 |
origNote=11; |
| 544 |
origOctave=9; |
| 545 |
} |
| 546 |
if (origOctave<-5) { |
| 547 |
origNote=1; |
| 548 |
origOctave=-5; |
| 549 |
} |
| 550 |
pat->data[j][0]=origNote; |
| 551 |
pat->data[j][1]=(unsigned char)origOctave; |
| 552 |
} |
| 553 |
} else { |
| 554 |
int top=255; |
| 555 |
if (iFine==1) { |
| 556 |
if (e->song.ins.empty()) continue; |
| 557 |
top=e->song.ins.size()-1; |
| 558 |
} else if (iFine==2) { // volume |
| 559 |
top=e->getMaxVolumeChan(iCoarse); |
| 560 |
} |
| 561 |
if (pat->data[j][iFine+1]==-1) continue; |
| 562 |
pat->data[j][iFine+1]=MIN(top,MAX(0,pat->data[j][iFine+1]+amount)); |
| 563 |
} |
| 564 |
} |
| 565 |
j=0; |
| 566 |
} |
| 567 |
} |
| 568 |
iFine=0; |
| 569 |
} |
| 570 |
|
| 571 |
makeUndo(GUI_UNDO_PATTERN_DELETE); |
| 572 |
} |
| 573 |
|
| 574 |
String FurnaceGUI::doCopy(bool cut, bool writeClipboard, const SelectionPoint& sStart, const SelectionPoint& sEnd) { |
| 575 |
if (writeClipboard) { |
| 576 |
finishSelection(); |
| 577 |
if (cut) { |
| 578 |
curNibble=false; |
| 579 |
prepareUndo(GUI_UNDO_PATTERN_CUT); |
| 580 |
} |
| 581 |
} |
| 582 |
String clipb=fmt::sprintf("org.tildearrow.furnace - Pattern Data (%d)\n%d",DIV_ENGINE_VERSION,sStart.xFine); |
| 583 |
int jOrder=sStart.order; |
| 584 |
int j=sStart.y; |
| 585 |
|
| 586 |
for (; jOrder<=sEnd.order; jOrder++) { |
| 587 |
for (; j<e->curSubSong->patLen && (j<=sEnd.y || jOrder<sEnd.order); j++) { |
| 588 |
int iCoarse=sStart.xCoarse; |
| 589 |
int iFine=sStart.xFine; |
| 590 |
if (iFine>3 && !(iFine&1)) { |
| 591 |
iFine--; |
| 592 |
} |
| 593 |
clipb+='\n'; |
| 594 |
for (; iCoarse<=sEnd.xCoarse; iCoarse++) { |
| 595 |
if (!e->curSubSong->chanShow[iCoarse]) continue; |
| 596 |
DivPattern* pat=e->curPat[iCoarse].getPattern(e->curOrders->ord[iCoarse][jOrder],true); |
| 597 |
for (; iFine<3+e->curPat[iCoarse].effectCols*2 && (iCoarse<sEnd.xCoarse || iFine<=sEnd.xFine); iFine++) { |
| 598 |
if (iFine==0) { |
| 599 |
clipb+=noteNameNormal(pat->data[j][0],pat->data[j][1]); |
| 600 |
if (cut) { |
| 601 |
pat->data[j][0]=0; |
| 602 |
pat->data[j][1]=0; |
| 603 |
} |
| 604 |
} else { |
| 605 |
if (pat->data[j][iFine+1]==-1) { |
| 606 |
clipb+=".."; |
| 607 |
} else { |
| 608 |
clipb+=fmt::sprintf("%.2X",pat->data[j][iFine+1]); |
| 609 |
} |
| 610 |
if (cut) { |
| 611 |
pat->data[j][iFine+1]=-1; |
| 612 |
} |
| 613 |
} |
| 614 |
} |
| 615 |
clipb+='|'; |
| 616 |
iFine=0; |
| 617 |
} |
| 618 |
} |
| 619 |
j=0; |
| 620 |
} |
| 621 |
|
| 622 |
if (writeClipboard) { |
| 623 |
SDL_SetClipboardText(clipb.c_str()); |
| 624 |
if (cut) { |
| 625 |
makeUndo(GUI_UNDO_PATTERN_CUT); |
| 626 |
} |
| 627 |
clipboard=clipb; |
| 628 |
} |
| 629 |
return clipb; |
| 630 |
} |
| 631 |
|
| 632 |
void FurnaceGUI::doPasteFurnace(PasteMode mode, int arg, bool readClipboard, String clipb, std::vector<String> data, int startOff, bool invalidData, UndoRegion ur) |
| 633 |
{ |
| 634 |
if (sscanf(data[1].c_str(),"%d",&startOff)!=1) return; |
| 635 |
if (startOff<0) return; |
| 636 |
|
| 637 |
DETERMINE_LAST; |
| 638 |
|
| 639 |
int j=cursor.y; |
| 640 |
int jOrder=cursor.order; |
| 641 |
char note[4]; |
| 642 |
for (size_t i=2; i<data.size() && j<e->curSubSong->patLen; i++) { |
| 643 |
size_t charPos=0; |
| 644 |
int iCoarse=cursor.xCoarse; |
| 645 |
int iFine=(startOff>2 && cursor.xFine>2)?(((cursor.xFine-1)&(~1))|1):startOff; |
| 646 |
|
| 647 |
String& line=data[i]; |
| 648 |
|
| 649 |
while (charPos<line.size() && iCoarse<lastChannel) { |
| 650 |
DivPattern* pat=e->curPat[iCoarse].getPattern(e->curOrders->ord[iCoarse][jOrder],true); |
| 651 |
if (line[charPos]=='|') { |
| 652 |
iCoarse++; |
| 653 |
if (iCoarse<lastChannel) while (!e->curSubSong->chanShow[iCoarse]) { |
| 654 |
iCoarse++; |
| 655 |
if (iCoarse>=lastChannel) break; |
| 656 |
} |
| 657 |
iFine=0; |
| 658 |
charPos++; |
| 659 |
continue; |
| 660 |
} |
| 661 |
if (iFine==0) { |
| 662 |
if (charPos>=line.size()) { |
| 663 |
invalidData=true; |
| 664 |
break; |
| 665 |
} |
| 666 |
note[0]=line[charPos++]; |
| 667 |
if (charPos>=line.size()) { |
| 668 |
invalidData=true; |
| 669 |
break; |
| 670 |
} |
| 671 |
note[1]=line[charPos++]; |
| 672 |
if (charPos>=line.size()) { |
| 673 |
invalidData=true; |
| 674 |
break; |
| 675 |
} |
| 676 |
note[2]=line[charPos++]; |
| 677 |
note[3]=0; |
| 678 |
|
| 679 |
if (iFine==0 && !opMaskPaste.note) { |
| 680 |
iFine++; |
| 681 |
continue; |
| 682 |
} |
| 683 |
|
| 684 |
if ((mode==GUI_PASTE_MODE_MIX_BG || mode==GUI_PASTE_MODE_MIX_FG || |
| 685 |
mode==GUI_PASTE_MODE_INS_BG || mode==GUI_PASTE_MODE_INS_FG) && strcmp(note,"...")==0) { |
| 686 |
// do nothing. |
| 687 |
} else { |
| 688 |
if (!(mode==GUI_PASTE_MODE_MIX_BG || mode==GUI_PASTE_MODE_INS_BG) || (pat->data[j][0]==0 && pat->data[j][1]==0)) { |
| 689 |
if (!decodeNote(note,pat->data[j][0],pat->data[j][1])) { |
| 690 |
invalidData=true; |
| 691 |
break; |
| 692 |
} |
| 693 |
if (mode==GUI_PASTE_MODE_INS_BG || mode==GUI_PASTE_MODE_INS_FG) pat->data[j][2]=arg; |
| 694 |
} |
| 695 |
} |
| 696 |
} else { |
| 697 |
if (charPos>=line.size()) { |
| 698 |
invalidData=true; |
| 699 |
break; |
| 700 |
} |
| 701 |
note[0]=line[charPos++]; |
| 702 |
if (charPos>=line.size()) { |
| 703 |
invalidData=true; |
| 704 |
break; |
| 705 |
} |
| 706 |
note[1]=line[charPos++]; |
| 707 |
note[2]=0; |
| 708 |
|
| 709 |
if (iFine==1) { |
| 710 |
if (!opMaskPaste.ins || mode==GUI_PASTE_MODE_INS_BG || mode==GUI_PASTE_MODE_INS_FG) { |
| 711 |
iFine++; |
| 712 |
continue; |
| 713 |
} |
| 714 |
} else if (iFine==2) { |
| 715 |
if (!opMaskPaste.vol) { |
| 716 |
iFine++; |
| 717 |
continue; |
| 718 |
} |
| 719 |
} else if ((iFine&1)==0) { |
| 720 |
if (!opMaskPaste.effectVal) { |
| 721 |
iFine++; |
| 722 |
continue; |
| 723 |
} |
| 724 |
} else if ((iFine&1)==1) { |
| 725 |
if (!opMaskPaste.effect) { |
| 726 |
iFine++; |
| 727 |
continue; |
| 728 |
} |
| 729 |
} |
| 730 |
|
| 731 |
if (strcmp(note,"..")==0) { |
| 732 |
if (!(mode==GUI_PASTE_MODE_MIX_BG || mode==GUI_PASTE_MODE_MIX_FG || |
| 733 |
mode==GUI_PASTE_MODE_INS_BG || mode==GUI_PASTE_MODE_INS_FG)) { |
| 734 |
pat->data[j][iFine+1]=-1; |
| 735 |
} |
| 736 |
} else { |
| 737 |
unsigned int val=0; |
| 738 |
if (sscanf(note,"%2X",&val)!=1) { |
| 739 |
invalidData=true; |
| 740 |
break; |
| 741 |
} |
| 742 |
if (!(mode==GUI_PASTE_MODE_MIX_BG || mode==GUI_PASTE_MODE_INS_BG) || pat->data[j][iFine+1]==-1) { |
| 743 |
if (iFine<(3+e->curPat[iCoarse].effectCols*2)) pat->data[j][iFine+1]=val; |
| 744 |
} |
| 745 |
} |
| 746 |
} |
| 747 |
iFine++; |
| 748 |
} |
| 749 |
|
| 750 |
if (invalidData) { |
| 751 |
logW(_("invalid clipboard data! failed at line %d char %d"),i,charPos); |
| 752 |
logW("%s",line.c_str()); |
| 753 |
break; |
| 754 |
} |
| 755 |
j++; |
| 756 |
if (mode==GUI_PASTE_MODE_OVERFLOW && j>=e->curSubSong->patLen && jOrder<e->curSubSong->ordersLen-1) { |
| 757 |
j=0; |
| 758 |
jOrder++; |
| 759 |
} |
| 760 |
|
| 761 |
if (mode==GUI_PASTE_MODE_FLOOD && i==data.size()-1) { |
| 762 |
i=1; |
| 763 |
} |
| 764 |
} |
| 765 |
|
| 766 |
curOrder=jOrder; |
| 767 |
if (mode==GUI_PASTE_MODE_OVERFLOW && !e->isPlaying()) { |
| 768 |
setOrder(jOrder); |
| 769 |
} |
| 770 |
|
| 771 |
if (readClipboard) { |
| 772 |
if (settings.cursorPastePos) { |
| 773 |
makeCursorUndo(); |
| 774 |
cursor.y=j; |
| 775 |
cursor.order=curOrder; |
| 776 |
if (cursor.y>=e->curSubSong->patLen) cursor.y=e->curSubSong->patLen-1; |
| 777 |
selStart=cursor; |
| 778 |
selEnd=cursor; |
| 779 |
updateScroll(cursor.y); |
| 780 |
} |
| 781 |
|
| 782 |
makeUndo(GUI_UNDO_PATTERN_PASTE,ur); |
| 783 |
} |
| 784 |
} |
| 785 |
|
| 786 |
unsigned int convertEffectMPT_MOD(unsigned char symbol, unsigned int val) { |
| 787 |
switch (symbol) { |
| 788 |
case '0': |
| 789 |
return (0x00<<8)|val; |
| 790 |
break; |
| 791 |
case '1': |
| 792 |
return (0x01<<8)|val; |
| 793 |
break; |
| 794 |
case '2': |
| 795 |
return (0x02<<8)|val; |
| 796 |
break; |
| 797 |
case '3': |
| 798 |
return (0x03<<8)|val; |
| 799 |
break; |
| 800 |
case '4': |
| 801 |
return (0x04<<8)|val; |
| 802 |
break; |
| 803 |
case '5': |
| 804 |
return (0x0a<<8)|val|(0x03<<24); // Axy+300 |
| 805 |
break; |
| 806 |
case '6': |
| 807 |
return (0x0a<<8)|val|(0x04<<24); // Axy+400 |
| 808 |
break; |
| 809 |
case '7': |
| 810 |
return (0x07<<8)|val; |
| 811 |
break; |
| 812 |
case '8': |
| 813 |
return (0x80<<8)|val; |
| 814 |
break; |
| 815 |
case '9': |
| 816 |
return (0x90<<8)|val; |
| 817 |
break; |
| 818 |
case 'A': |
| 819 |
return (0x0A<<8)|val; |
| 820 |
break; |
| 821 |
case 'B': |
| 822 |
return (0x0B<<8)|val; |
| 823 |
break; |
| 824 |
case 'C': |
| 825 |
return (0x0C<<8)|val; // interpreted as volume later |
| 826 |
break; |
| 827 |
case 'D': { |
| 828 |
unsigned char newParam=(val&0xf)+((val&0xff)>>4)*10; // hex to decimal, Protracker (and XM too!) lol |
| 829 |
return (0x0D<<8)|newParam; |
| 830 |
break; |
| 831 |
} |
| 832 |
case 'E': { |
| 833 |
switch (val>>4) { |
| 834 |
case 1: |
| 835 |
return (0xF1<<8)|(val&0xf); |
| 836 |
break; |
| 837 |
case 2: |
| 838 |
return (0xF2<<8)|(val&0xf); |
| 839 |
break; |
| 840 |
// glissando and vib shape not supported in Furnace |
| 841 |
case 5: |
| 842 |
return (0xF5<<8)|((val&0xf)<<4); |
| 843 |
break; |
| 844 |
// pattern loop not supported |
| 845 |
case 8: |
| 846 |
return (0x80<<8)|((val&0xf)<<4); |
| 847 |
break; |
| 848 |
case 9: |
| 849 |
return (0x0C<<8)|(val&0xf); |
| 850 |
break; |
| 851 |
case 0xA: |
| 852 |
return (0xF3<<8)|(val&0xf); |
| 853 |
break; |
| 854 |
case 0xB: |
| 855 |
return (0xF4<<8)|(val&0xf); |
| 856 |
break; |
| 857 |
case 0xC: |
| 858 |
return (0xFC<<8)|(val&0xf); |
| 859 |
break; |
| 860 |
case 0xD: |
| 861 |
return (0xFD<<8)|(val&0xf); |
| 862 |
break; |
| 863 |
default: |
| 864 |
break; |
| 865 |
} |
| 866 |
break; |
| 867 |
} |
| 868 |
case 'F': |
| 869 |
if (val<0x20) { |
| 870 |
return (0x0F<<8)|val; |
| 871 |
} else { |
| 872 |
return (0xF0<<8)|val; |
| 873 |
} |
| 874 |
break; |
| 875 |
} |
| 876 |
|
| 877 |
return 0; |
| 878 |
} |
| 879 |
|
| 880 |
unsigned int convertEffectMPT_S3M(unsigned char symbol, unsigned int val) { |
| 881 |
switch (symbol) { |
| 882 |
case 'A': |
| 883 |
return (0x09<<8)|val; |
| 884 |
break; |
| 885 |
case 'B': |
| 886 |
return (0x0B<<8)|val; |
| 887 |
break; |
| 888 |
case 'C': |
| 889 |
return (0x0D<<8)|val; |
| 890 |
break; |
| 891 |
case 'D': |
| 892 |
if ((val&0xf0)==0xf0) { |
| 893 |
return (0xF4<<8)|(val&0xf); |
| 894 |
} else if ((val&0xf)==0xf) { |
| 895 |
return (0xF3<<8)|((val&0xf0)>>4); |
| 896 |
} else { |
| 897 |
return (0x0A<<8)|val; |
| 898 |
} |
| 899 |
break; |
| 900 |
case 'E': |
| 901 |
if (val<0xe0) { |
| 902 |
return (0x02<<8)|val; |
| 903 |
} else if (val>=0xe0 && val<0xf0) { |
| 904 |
return (0xF2<<8)|(val&0xf); |
| 905 |
} else { |
| 906 |
return (0xF2<<8)|((val&0xf)>>1); |
| 907 |
} |
| 908 |
break; |
| 909 |
case 'F': |
| 910 |
if (val<0xe0) { |
| 911 |
return (0x01<<8)|val; |
| 912 |
} else if (val>=0xe0 && val<0xf0) { |
| 913 |
return (0xF1<<8)|(val&0xf); |
| 914 |
} else { |
| 915 |
return (0xF1<<8)|((val&0xf)>>1); |
| 916 |
} |
| 917 |
break; |
| 918 |
case 'G': |
| 919 |
return (0x03<<8)|val; |
| 920 |
break; |
| 921 |
case 'H': |
| 922 |
return (0x04<<8)|val; |
| 923 |
break; |
| 924 |
case 'J': |
| 925 |
return (0x00<<8)|val; |
| 926 |
break; |
| 927 |
case 'K': |
| 928 |
return (0x0a<<8)|val|(0x04<<24); // Axy+400 |
| 929 |
break; |
| 930 |
case 'L': |
| 931 |
return (0x0a<<8)|val|(0x03<<24); // Axy+300 |
| 932 |
break; |
| 933 |
case 'O': |
| 934 |
return (0x90<<8)|val; |
| 935 |
break; |
| 936 |
case 'Q': |
| 937 |
return (0xC0<<8)|(val&0xf); |
| 938 |
break; |
| 939 |
case 'R': |
| 940 |
return (0x07<<8)|(val&0xf); |
| 941 |
break; |
| 942 |
case 'S': { |
| 943 |
switch (val>>4) { |
| 944 |
case 2: |
| 945 |
return (0xE5<<8)|((val&0xf)<<4); |
| 946 |
break; |
| 947 |
case 8: |
| 948 |
return (0x80<<8)|((val&0xf)<<4); |
| 949 |
break; |
| 950 |
case 0xC: |
| 951 |
return (0xEC<<8)|(val&0xf); |
| 952 |
break; |
| 953 |
case 0xD: |
| 954 |
return (0xED<<8)|(val&0xf); |
| 955 |
break; |
| 956 |
default: |
| 957 |
break; |
| 958 |
} |
| 959 |
break; |
| 960 |
} |
| 961 |
case 'T': |
| 962 |
return (0xF0<<8)|(val&0xf); |
| 963 |
break; |
| 964 |
case 'U': |
| 965 |
return (0x04<<8)|MAX(1,((val&0xf0)>>6)<<4)|MAX(1,(val&0xf)>>2); |
| 966 |
break; |
| 967 |
case 'X': |
| 968 |
return (0x80<<8)|val; |
| 969 |
break; |
| 970 |
default: |
| 971 |
return 0; |
| 972 |
break; |
| 973 |
} |
| 974 |
|
| 975 |
return 0; |
| 976 |
} |
| 977 |
|
| 978 |
unsigned int convertEffectMPT_XM(unsigned char symbol, unsigned int val) { |
| 979 |
if (symbol=='K') { |
| 980 |
return (0xEC<<8)|val; |
| 981 |
} |
| 982 |
|
| 983 |
return convertEffectMPT_MOD(symbol,val); // for now |
| 984 |
} |
| 985 |
|
| 986 |
unsigned int convertEffectMPT_IT(unsigned char symbol, unsigned int val) { |
| 987 |
return convertEffectMPT_S3M(symbol,val); // for now |
| 988 |
} |
| 989 |
|
| 990 |
unsigned int convertEffectMPT_MPTM(unsigned char symbol, unsigned int val) { |
| 991 |
if (symbol==':') { |
| 992 |
return (0xED<<8)|((val&0xf0)>>4)|(0xEC<<24)|((((val&0xf0)>>4)+(val&0xf))<<16); |
| 993 |
} |
| 994 |
|
| 995 |
return convertEffectMPT_IT(symbol,val); |
| 996 |
} |
| 997 |
|
| 998 |
void FurnaceGUI::doPasteMPT(PasteMode mode, int arg, bool readClipboard, String clipb, std::vector<String> data, int mptFormat, UndoRegion ur) { |
| 999 |
DETERMINE_LAST; |
| 1000 |
|
| 1001 |
int j=cursor.y; |
| 1002 |
int jOrder=cursor.order; |
| 1003 |
char note[4]; |
| 1004 |
bool invalidData=false; |
| 1005 |
|
| 1006 |
memset(note,0,4); |
| 1007 |
|
| 1008 |
for (size_t i=1; i<data.size() && j<e->curSubSong->patLen; i++) { |
| 1009 |
size_t charPos=1; |
| 1010 |
int iCoarse=cursor.xCoarse; |
| 1011 |
int iFine=0; |
| 1012 |
String& line=data[i]; |
| 1013 |
while (charPos<line.size() && iCoarse<lastChannel) { |
| 1014 |
DivPattern* pat=e->curPat[iCoarse].getPattern(e->curOrders->ord[iCoarse][jOrder],true); |
| 1015 |
if (line[charPos]=='|' && charPos!=0) { // MPT format starts every pattern line with '|' |
| 1016 |
iCoarse++; |
| 1017 |
if (iCoarse<lastChannel) { |
| 1018 |
while (!e->curSubSong->chanShow[iCoarse]) { |
| 1019 |
iCoarse++; |
| 1020 |
if (iCoarse>=lastChannel) break; |
| 1021 |
} |
| 1022 |
} |
| 1023 |
iFine=0; |
| 1024 |
charPos++; |
| 1025 |
continue; |
| 1026 |
} |
| 1027 |
if (iFine==0) { // note |
| 1028 |
if (charPos>=line.size()) { |
| 1029 |
invalidData=true; |
| 1030 |
break; |
| 1031 |
} |
| 1032 |
note[0]=line[charPos++]; |
| 1033 |
if (charPos>=line.size()) { |
| 1034 |
invalidData=true; |
| 1035 |
break; |
| 1036 |
} |
| 1037 |
note[1]=line[charPos++]; |
| 1038 |
if (charPos>=line.size()) { |
| 1039 |
invalidData=true; |
| 1040 |
break; |
| 1041 |
} |
| 1042 |
note[2]=line[charPos++]; |
| 1043 |
note[3]=0; |
| 1044 |
|
| 1045 |
if (iFine==0 && !opMaskPaste.note) { |
| 1046 |
iFine++; |
| 1047 |
continue; |
| 1048 |
} |
| 1049 |
|
| 1050 |
if (strcmp(note,"...")==0 || strcmp(note," ")==0) { |
| 1051 |
// do nothing. |
| 1052 |
} else { |
| 1053 |
if (!(mode==GUI_PASTE_MODE_MIX_BG || mode==GUI_PASTE_MODE_INS_BG) || (pat->data[j][0]==0 && pat->data[j][1]==0)) { |
| 1054 |
if (!decodeNote(note,pat->data[j][0],pat->data[j][1])) { |
| 1055 |
if (strcmp(note, "^^^")==0) { |
| 1056 |
pat->data[j][0]=100; |
| 1057 |
pat->data[j][1]=0; |
| 1058 |
} else if (strcmp(note, "~~~")==0 || strcmp(note,"===")==0) { |
| 1059 |
pat->data[j][0]=101; |
| 1060 |
pat->data[j][1]=0; |
| 1061 |
} else { |
| 1062 |
invalidData=true; |
| 1063 |
} |
| 1064 |
break; |
| 1065 |
} else { |
| 1066 |
pat->data[j][1]--; // MPT is one octave higher... |
| 1067 |
} |
| 1068 |
if (mode==GUI_PASTE_MODE_INS_BG || mode==GUI_PASTE_MODE_INS_FG) pat->data[j][2]=arg; |
| 1069 |
} |
| 1070 |
} |
| 1071 |
} else if (iFine==1) { // instrument |
| 1072 |
if (charPos>=line.size()) { |
| 1073 |
invalidData=true; |
| 1074 |
break; |
| 1075 |
} |
| 1076 |
note[0]=line[charPos++]; |
| 1077 |
if (charPos>=line.size()) { |
| 1078 |
invalidData=true; |
| 1079 |
break; |
| 1080 |
} |
| 1081 |
note[1]=line[charPos++]; |
| 1082 |
note[2]=0; |
| 1083 |
|
| 1084 |
if (iFine==1) { |
| 1085 |
if (!opMaskPaste.ins || mode==GUI_PASTE_MODE_INS_BG || mode==GUI_PASTE_MODE_INS_FG) { |
| 1086 |
iFine++; |
| 1087 |
continue; |
| 1088 |
} |
| 1089 |
} |
| 1090 |
|
| 1091 |
if (strcmp(note,"..")==0 || strcmp(note," ")==0) { |
| 1092 |
if (!(mode==GUI_PASTE_MODE_MIX_BG || mode==GUI_PASTE_MODE_MIX_FG || |
| 1093 |
mode==GUI_PASTE_MODE_INS_BG || mode==GUI_PASTE_MODE_INS_FG)) { |
| 1094 |
pat->data[j][iFine+1]=-1; |
| 1095 |
} |
| 1096 |
} else { |
| 1097 |
unsigned int val=0; |
| 1098 |
if (sscanf(note,"%2d",&val)!=1) { |
| 1099 |
invalidData=true; |
| 1100 |
break; |
| 1101 |
} |
| 1102 |
|
| 1103 |
if (!(mode==GUI_PASTE_MODE_MIX_BG || mode==GUI_PASTE_MODE_INS_BG) || pat->data[j][iFine+1]==-1) { |
| 1104 |
pat->data[j][iFine+1]=val-1; |
| 1105 |
} |
| 1106 |
} |
| 1107 |
} else { // volume and effects |
| 1108 |
if (charPos>=line.size()) { |
| 1109 |
invalidData=true; |
| 1110 |
break; |
| 1111 |
} |
| 1112 |
note[0]=line[charPos++]; |
| 1113 |
if (charPos>=line.size()) { |
| 1114 |
invalidData=true; |
| 1115 |
break; |
| 1116 |
} |
| 1117 |
note[1]=line[charPos++]; |
| 1118 |
if (charPos>=line.size()) { |
| 1119 |
invalidData=true; |
| 1120 |
break; |
| 1121 |
} |
| 1122 |
note[2]=line[charPos++]; |
| 1123 |
note[3]=0; |
| 1124 |
|
| 1125 |
if (iFine==2) { |
| 1126 |
if (!opMaskPaste.vol) { |
| 1127 |
iFine++; |
| 1128 |
continue; |
| 1129 |
} |
| 1130 |
} |
| 1131 |
|
| 1132 |
else if ((iFine&1)==0) { |
| 1133 |
if (!opMaskPaste.effectVal) { |
| 1134 |
iFine++; |
| 1135 |
continue; |
| 1136 |
} |
| 1137 |
} else if ((iFine&1)==1) { |
| 1138 |
if (!opMaskPaste.effect) { |
| 1139 |
iFine++; |
| 1140 |
continue; |
| 1141 |
} |
| 1142 |
} |
| 1143 |
|
| 1144 |
if (strcmp(note,"...")==0 || strcmp(note," ")==0) { |
| 1145 |
if (!(mode==GUI_PASTE_MODE_MIX_BG || mode==GUI_PASTE_MODE_MIX_FG || |
| 1146 |
mode==GUI_PASTE_MODE_INS_BG || mode==GUI_PASTE_MODE_INS_FG)) |
| 1147 |
{ |
| 1148 |
pat->data[j][iFine+1]=-1; |
| 1149 |
} |
| 1150 |
} else { |
| 1151 |
unsigned int val=0; |
| 1152 |
unsigned char symbol='\0'; |
| 1153 |
|
| 1154 |
symbol=note[0]; |
| 1155 |
|
| 1156 |
if (iFine==2) { |
| 1157 |
sscanf(¬e[1],"%2d",&val); |
| 1158 |
} else { |
| 1159 |
sscanf(¬e[1],"%2X",&val); |
| 1160 |
} |
| 1161 |
|
| 1162 |
if (!(mode==GUI_PASTE_MODE_MIX_BG || mode==GUI_PASTE_MODE_INS_BG) || pat->data[j][iFine+1]==-1) { |
| 1163 |
// if (iFine<(3+e->curPat[iCoarse].effectCols*2)) pat->data[j][iFine+1]=val; |
| 1164 |
if (iFine==2) { // volume |
| 1165 |
switch(symbol) { |
| 1166 |
case 'v': |
| 1167 |
{ |
| 1168 |
pat->data[j][iFine+1]=val; |
| 1169 |
break; |
| 1170 |
} |
| 1171 |
default: |
| 1172 |
break; |
| 1173 |
} |
| 1174 |
} else { // effect |
| 1175 |
unsigned int eff=0; |
| 1176 |
if (mptFormat==0) { |
| 1177 |
eff=convertEffectMPT_MOD(symbol, val); // up to 4 effects stored in one variable |
| 1178 |
if (((eff&0x0f00)>>8)==0x0C) { // set volume |
| 1179 |
pat->data[j][iFine]=eff&0xff; |
| 1180 |
} |
| 1181 |
} |
| 1182 |
|
| 1183 |
if (mptFormat==1) { |
| 1184 |
eff=convertEffectMPT_S3M(symbol, val); |
| 1185 |
} |
| 1186 |
|
| 1187 |
if (mptFormat==2 || mptFormat==3) { // set volume |
| 1188 |
eff=convertEffectMPT_XM(symbol, val); |
| 1189 |
|
| 1190 |
if (((eff&0x0f00)>>8)==0x0C) |
| 1191 |
{ |
| 1192 |
pat->data[j][iFine]=eff&0xff; |
| 1193 |
} |
| 1194 |
} |
| 1195 |
|
| 1196 |
if (mptFormat==4|| mptFormat==5) { |
| 1197 |
eff=convertEffectMPT_IT(symbol, val); |
| 1198 |
} |
| 1199 |
|
| 1200 |
if (mptFormat==6) { |
| 1201 |
eff=convertEffectMPT_MPTM(symbol, val); |
| 1202 |
} |
| 1203 |
|
| 1204 |
pat->data[j][iFine+1]=((eff&0xff00)>>8); |
| 1205 |
pat->data[j][iFine+2]=(eff&0xff); |
| 1206 |
|
| 1207 |
if (eff>0xffff) { |
| 1208 |
pat->data[j][iFine+3]=((eff&0xff000000)>>24); |
| 1209 |
pat->data[j][iFine+4]=((eff&0xff0000)>>16); |
| 1210 |
} |
| 1211 |
} |
| 1212 |
} |
| 1213 |
} |
| 1214 |
} |
| 1215 |
|
| 1216 |
iFine++; |
| 1217 |
|
| 1218 |
if (charPos>=line.size()-1) { |
| 1219 |
invalidData=false; |
| 1220 |
break; |
| 1221 |
} |
| 1222 |
} |
| 1223 |
|
| 1224 |
if (invalidData) { |
| 1225 |
logW(_("invalid clipboard data! failed at line %d char %d"),i,charPos); |
| 1226 |
logW("%s",line.c_str()); |
| 1227 |
break; |
| 1228 |
} |
| 1229 |
|
| 1230 |
j++; |
| 1231 |
if (mode==GUI_PASTE_MODE_OVERFLOW && j>=e->curSubSong->patLen && jOrder<e->curSubSong->ordersLen-1) { |
| 1232 |
j=0; |
| 1233 |
jOrder++; |
| 1234 |
} |
| 1235 |
|
| 1236 |
if (mode==GUI_PASTE_MODE_FLOOD && i==data.size()-1) { |
| 1237 |
i=1; |
| 1238 |
} |
| 1239 |
} |
| 1240 |
|
| 1241 |
curOrder=jOrder; |
| 1242 |
if (mode==GUI_PASTE_MODE_OVERFLOW && !e->isPlaying()) { |
| 1243 |
setOrder(jOrder); |
| 1244 |
} |
| 1245 |
|
| 1246 |
if (readClipboard) { |
| 1247 |
if (settings.cursorPastePos) { |
| 1248 |
makeCursorUndo(); |
| 1249 |
cursor.y=j; |
| 1250 |
cursor.order=curOrder; |
| 1251 |
if (cursor.y>=e->curSubSong->patLen) cursor.y=e->curSubSong->patLen-1; |
| 1252 |
selStart=cursor; |
| 1253 |
selEnd=cursor; |
| 1254 |
updateScroll(cursor.y); |
| 1255 |
} |
| 1256 |
|
| 1257 |
makeUndo(GUI_UNDO_PATTERN_PASTE,ur); |
| 1258 |
} |
| 1259 |
} |
| 1260 |
|
| 1261 |
void FurnaceGUI::doPaste(PasteMode mode, int arg, bool readClipboard, String clipb) { |
| 1262 |
if (readClipboard) { |
| 1263 |
finishSelection(); |
| 1264 |
char* clipText=SDL_GetClipboardText(); |
| 1265 |
if (clipText!=NULL) { |
| 1266 |
if (clipText[0]) { |
| 1267 |
clipboard=clipText; |
| 1268 |
} |
| 1269 |
SDL_free(clipText); |
| 1270 |
} |
| 1271 |
clipb=clipboard; |
| 1272 |
} |
| 1273 |
std::vector<String> data; |
| 1274 |
String tempS; |
| 1275 |
bool foundString=false; |
| 1276 |
bool isFurnace=false; |
| 1277 |
bool isModPlug=false; |
| 1278 |
int mptFormat=0; |
| 1279 |
for (char i: clipb) { |
| 1280 |
if (i=='\r') continue; |
| 1281 |
if (i=='\n') { |
| 1282 |
data.push_back(tempS); |
| 1283 |
tempS=""; |
| 1284 |
continue; |
| 1285 |
} |
| 1286 |
tempS+=i; |
| 1287 |
} |
| 1288 |
data.push_back(tempS); |
| 1289 |
|
| 1290 |
int startOff=-1; |
| 1291 |
bool invalidData=false; |
| 1292 |
if (data.size()<2) return; |
| 1293 |
|
| 1294 |
if (data[0].find("org.tildearrow.furnace - Pattern Data")==0) { |
| 1295 |
foundString=true; |
| 1296 |
isFurnace=true; |
| 1297 |
} else { |
| 1298 |
for (int i=0; modPlugFormatHeaders[i]; i++) { |
| 1299 |
if (data[0].find(modPlugFormatHeaders[i])==0) { |
| 1300 |
foundString=true; |
| 1301 |
isModPlug=true; |
| 1302 |
mptFormat=i; |
| 1303 |
break; |
| 1304 |
} |
| 1305 |
} |
| 1306 |
} |
| 1307 |
|
| 1308 |
if (!foundString) return; |
| 1309 |
|
| 1310 |
UndoRegion ur; |
| 1311 |
if (mode==GUI_PASTE_MODE_OVERFLOW) { |
| 1312 |
int rows=cursor.y; |
| 1313 |
int firstPattern=cursor.order; |
| 1314 |
int lastPattern=cursor.order; |
| 1315 |
rows+=data.size(); |
| 1316 |
while (rows>=e->curSubSong->patLen) { |
| 1317 |
lastPattern++; |
| 1318 |
rows-=e->curSubSong->patLen; |
| 1319 |
} |
| 1320 |
|
| 1321 |
ur=UndoRegion(firstPattern,0,0,lastPattern,e->getTotalChannelCount()-1,e->curSubSong->patLen-1); |
| 1322 |
} |
| 1323 |
|
| 1324 |
if (readClipboard) { |
| 1325 |
prepareUndo(GUI_UNDO_PATTERN_PASTE,ur); |
| 1326 |
} |
| 1327 |
|
| 1328 |
if (isFurnace) { |
| 1329 |
doPasteFurnace(mode,arg,readClipboard,clipb,data,startOff,invalidData,ur); |
| 1330 |
} else if (isModPlug) { |
| 1331 |
doPasteMPT(mode,arg,readClipboard,clipb,data,mptFormat,ur); |
| 1332 |
} |
| 1333 |
} |
| 1334 |
|
| 1335 |
void FurnaceGUI::doChangeIns(int ins) { |
| 1336 |
finishSelection(); |
| 1337 |
prepareUndo(GUI_UNDO_PATTERN_CHANGE_INS); |
| 1338 |
|
| 1339 |
int iCoarse=selStart.xCoarse; |
| 1340 |
for (; iCoarse<=selEnd.xCoarse; iCoarse++) { |
| 1341 |
int jOrder=selStart.order; |
| 1342 |
int j=selStart.y; |
| 1343 |
if (!e->curSubSong->chanShow[iCoarse]) continue; |
| 1344 |
resetTouches; |
| 1345 |
for (; jOrder<=selEnd.order; jOrder++) { |
| 1346 |
DivPattern* pat=e->curPat[iCoarse].getPattern(e->curOrders->ord[iCoarse][jOrder],true); |
| 1347 |
for (; j<e->curSubSong->patLen && (j<=selEnd.y || jOrder<selEnd.order); j++) { |
| 1348 |
touch(jOrder,j); |
| 1349 |
if (pat->data[j][2]!=-1 || !((pat->data[j][0]==0 || pat->data[j][0]==100 || pat->data[j][0]==101 || pat->data[j][0]==102) && pat->data[j][1]==0)) { |
| 1350 |
pat->data[j][2]=ins; |
| 1351 |
} |
| 1352 |
} |
| 1353 |
j=0; |
| 1354 |
} |
| 1355 |
} |
| 1356 |
|
| 1357 |
makeUndo(GUI_UNDO_PATTERN_CHANGE_INS); |
| 1358 |
} |
| 1359 |
|
| 1360 |
void FurnaceGUI::doInterpolate() { |
| 1361 |
finishSelection(); |
| 1362 |
prepareUndo(GUI_UNDO_PATTERN_INTERPOLATE); |
| 1363 |
|
| 1364 |
// first: fixed point, 8-bit order.row |
| 1365 |
// second: value |
| 1366 |
std::vector<std::pair<int,int>> points; |
| 1367 |
int iCoarse=selStart.xCoarse; |
| 1368 |
int iFine=selStart.xFine; |
| 1369 |
for (; iCoarse<=selEnd.xCoarse; iCoarse++) { |
| 1370 |
if (!e->curSubSong->chanShow[iCoarse]) continue; |
| 1371 |
for (; iFine<3+e->curPat[iCoarse].effectCols*2 && (iCoarse<selEnd.xCoarse || iFine<=selEnd.xFine); iFine++) { |
| 1372 |
maskOut(opMaskInterpolate,iFine); |
| 1373 |
points.clear(); |
| 1374 |
resetTouches; |
| 1375 |
if (iFine!=0) { |
| 1376 |
int jOrder=selStart.order; |
| 1377 |
int j=selStart.y; |
| 1378 |
for (; jOrder<=selEnd.order; jOrder++) { |
| 1379 |
DivPattern* pat=e->curPat[iCoarse].getPattern(e->curOrders->ord[iCoarse][jOrder],true); |
| 1380 |
for (; j<e->curSubSong->patLen && (j<=selEnd.y || jOrder<selEnd.order); j++) { |
| 1381 |
touch(jOrder,j); |
| 1382 |
if (pat->data[j][iFine+1]!=-1) { |
| 1383 |
points.emplace(points.end(),j|(jOrder<<8),pat->data[j][iFine+1]); |
| 1384 |
} |
| 1385 |
} |
| 1386 |
j=0; |
| 1387 |
} |
| 1388 |
|
| 1389 |
if (points.size()>1) for (size_t j=0; j<points.size()-1; j++) { |
| 1390 |
std::pair<int,int>& curPoint=points[j]; |
| 1391 |
std::pair<int,int>& nextPoint=points[j+1]; |
| 1392 |
int distance=( |
| 1393 |
((nextPoint.first&0xff)+((nextPoint.first>>8)*e->curSubSong->patLen))- |
| 1394 |
((curPoint.first&0xff)+((curPoint.first>>8)*e->curSubSong->patLen)) |
| 1395 |
); |
| 1396 |
for (int k=0, k_p=curPoint.first; k<distance; k++) { |
| 1397 |
DivPattern* pat=e->curPat[iCoarse].getPattern(e->curOrders->ord[iCoarse][(k_p>>8)&0xff],true); |
| 1398 |
pat->data[k_p&0xff][iFine+1]=curPoint.second+((nextPoint.second-curPoint.second)*(double)k/(double)distance); |
| 1399 |
k_p++; |
| 1400 |
if ((k_p&0xff)>=e->curSubSong->patLen) { |
| 1401 |
k_p&=~0xff; |
| 1402 |
k_p+=0x100; |
| 1403 |
} |
| 1404 |
} |
| 1405 |
} |
| 1406 |
} else { |
| 1407 |
int jOrder=selStart.order; |
| 1408 |
int j=selStart.y; |
| 1409 |
for (; jOrder<=selEnd.order; jOrder++) { |
| 1410 |
DivPattern* pat=e->curPat[iCoarse].getPattern(e->curOrders->ord[iCoarse][jOrder],true); |
| 1411 |
for (; j<e->curSubSong->patLen && (j<=selEnd.y || jOrder<selEnd.order); j++) { |
| 1412 |
touch(jOrder,j); |
| 1413 |
if (pat->data[j][0]!=0 || pat->data[j][1]!=0) { |
| 1414 |
if (pat->data[j][0]!=100 && pat->data[j][0]!=101 && pat->data[j][0]!=102) { |
| 1415 |
points.emplace(points.end(),j|(jOrder<<8),pat->data[j][0]+(signed char)pat->data[j][1]*12); |
| 1416 |
} |
| 1417 |
} |
| 1418 |
} |
| 1419 |
j=0; |
| 1420 |
} |
| 1421 |
|
| 1422 |
if (points.size()>1) for (size_t j=0; j<points.size()-1; j++) { |
| 1423 |
std::pair<int,int>& curPoint=points[j]; |
| 1424 |
std::pair<int,int>& nextPoint=points[j+1]; |
| 1425 |
int distance=( |
| 1426 |
((nextPoint.first&0xff)+((nextPoint.first>>8)*e->curSubSong->patLen))- |
| 1427 |
((curPoint.first&0xff)+((curPoint.first>>8)*e->curSubSong->patLen)) |
| 1428 |
); |
| 1429 |
for (int k=0, k_p=curPoint.first; k<distance; k++) { |
| 1430 |
DivPattern* pat=e->curPat[iCoarse].getPattern(e->curOrders->ord[iCoarse][(k_p>>8)&0xff],true); |
| 1431 |
int val=curPoint.second+((nextPoint.second-curPoint.second)*(double)k/(double)distance); |
| 1432 |
pat->data[k_p&0xff][0]=val%12; |
| 1433 |
pat->data[k_p&0xff][1]=val/12; |
| 1434 |
if (pat->data[k_p&0xff][0]==0) { |
| 1435 |
pat->data[k_p&0xff][0]=12; |
| 1436 |
pat->data[k_p&0xff][1]--; |
| 1437 |
} |
| 1438 |
pat->data[k_p&0xff][1]&=255; |
| 1439 |
k_p++; |
| 1440 |
if ((k_p&0xff)>=e->curSubSong->patLen) { |
| 1441 |
k_p&=~0xff; |
| 1442 |
k_p+=0x100; |
| 1443 |
} |
| 1444 |
} |
| 1445 |
} |
| 1446 |
} |
| 1447 |
} |
| 1448 |
iFine=0; |
| 1449 |
} |
| 1450 |
|
| 1451 |
makeUndo(GUI_UNDO_PATTERN_INTERPOLATE); |
| 1452 |
} |
| 1453 |
|
| 1454 |
void FurnaceGUI::doFade(int p0, int p1, bool mode) { |
| 1455 |
finishSelection(); |
| 1456 |
prepareUndo(GUI_UNDO_PATTERN_FADE); |
| 1457 |
|
| 1458 |
int iCoarse=selStart.xCoarse; |
| 1459 |
int iFine=selStart.xFine; |
| 1460 |
int distance=( |
| 1461 |
(selEnd.y+(selEnd.order*e->curSubSong->patLen))- |
| 1462 |
(selStart.y+(selStart.order*e->curSubSong->patLen)) |
| 1463 |
); |
| 1464 |
for (; iCoarse<=selEnd.xCoarse; iCoarse++) { |
| 1465 |
if (!e->curSubSong->chanShow[iCoarse]) continue; |
| 1466 |
for (; iFine<3+e->curPat[iCoarse].effectCols*2 && (iCoarse<selEnd.xCoarse || iFine<=selEnd.xFine); iFine++) { |
| 1467 |
int jOrder=selStart.order; |
| 1468 |
int j=selStart.y; |
| 1469 |
int j_p=0; |
| 1470 |
maskOut(opMaskFade,iFine); |
| 1471 |
resetTouches; |
| 1472 |
if (iFine!=0) { |
| 1473 |
int absoluteTop=255; |
| 1474 |
if (iFine==1) { |
| 1475 |
if (e->song.ins.empty()) continue; |
| 1476 |
absoluteTop=e->song.ins.size()-1; |
| 1477 |
} else if (iFine==2) { // volume |
| 1478 |
absoluteTop=e->getMaxVolumeChan(iCoarse); |
| 1479 |
} |
| 1480 |
if (distance<1) continue; |
| 1481 |
for (; jOrder<=selEnd.order; jOrder++) { |
| 1482 |
DivPattern* pat=e->curPat[iCoarse].getPattern(e->curOrders->ord[iCoarse][jOrder],true); |
| 1483 |
for (; j<e->curSubSong->patLen && (j<=selEnd.y || jOrder<selEnd.order); j++) { |
| 1484 |
double fraction=double(j_p)/double(distance); |
| 1485 |
int value=p0+double(p1-p0)*fraction; |
| 1486 |
if (mode) { // nibble |
| 1487 |
value&=15; |
| 1488 |
pat->data[j][iFine+1]=MIN(absoluteTop,value|(value<<4)); |
| 1489 |
} else { // byte |
| 1490 |
pat->data[j][iFine+1]=MIN(absoluteTop,value); |
| 1491 |
} |
| 1492 |
j_p++; |
| 1493 |
} |
| 1494 |
j=0; |
| 1495 |
} |
| 1496 |
} |
| 1497 |
} |
| 1498 |
iFine=0; |
| 1499 |
} |
| 1500 |
|
| 1501 |
makeUndo(GUI_UNDO_PATTERN_FADE); |
| 1502 |
} |
| 1503 |
|
| 1504 |
void FurnaceGUI::doInvertValues() { |
| 1505 |
finishSelection(); |
| 1506 |
prepareUndo(GUI_UNDO_PATTERN_INVERT_VAL); |
| 1507 |
|
| 1508 |
int iCoarse=selStart.xCoarse; |
| 1509 |
int iFine=selStart.xFine; |
| 1510 |
for (; iCoarse<=selEnd.xCoarse; iCoarse++) { |
| 1511 |
if (!e->curSubSong->chanShow[iCoarse]) continue; |
| 1512 |
for (; iFine<3+e->curPat[iCoarse].effectCols*2 && (iCoarse<selEnd.xCoarse || iFine<=selEnd.xFine); iFine++) { |
| 1513 |
int jOrder=selStart.order; |
| 1514 |
int j=selStart.y; |
| 1515 |
maskOut(opMaskInvertVal,iFine); |
| 1516 |
resetTouches; |
| 1517 |
if (iFine!=0) { |
| 1518 |
int top=255; |
| 1519 |
if (iFine==1) { |
| 1520 |
if (e->song.ins.empty()) continue; |
| 1521 |
top=e->song.ins.size()-1; |
| 1522 |
} else if (iFine==2) { // volume |
| 1523 |
top=e->getMaxVolumeChan(iCoarse); |
| 1524 |
} |
| 1525 |
for (; jOrder<=selEnd.order; jOrder++) { |
| 1526 |
DivPattern* pat=e->curPat[iCoarse].getPattern(e->curOrders->ord[iCoarse][jOrder],true); |
| 1527 |
for (; j<e->curSubSong->patLen && (j<=selEnd.y || jOrder<selEnd.order); j++) { |
| 1528 |
touch(jOrder,j); |
| 1529 |
if (pat->data[j][iFine+1]==-1) continue; |
| 1530 |
pat->data[j][iFine+1]=top-pat->data[j][iFine+1]; |
| 1531 |
} |
| 1532 |
j=0; |
| 1533 |
} |
| 1534 |
} |
| 1535 |
} |
| 1536 |
iFine=0; |
| 1537 |
} |
| 1538 |
|
| 1539 |
makeUndo(GUI_UNDO_PATTERN_INVERT_VAL); |
| 1540 |
} |
| 1541 |
|
| 1542 |
void FurnaceGUI::doScale(float top) { |
| 1543 |
finishSelection(); |
| 1544 |
prepareUndo(GUI_UNDO_PATTERN_SCALE); |
| 1545 |
|
| 1546 |
int iCoarse=selStart.xCoarse; |
| 1547 |
int iFine=selStart.xFine; |
| 1548 |
for (; iCoarse<=selEnd.xCoarse; iCoarse++) { |
| 1549 |
if (!e->curSubSong->chanShow[iCoarse]) continue; |
| 1550 |
for (; iFine<3+e->curPat[iCoarse].effectCols*2 && (iCoarse<selEnd.xCoarse || iFine<=selEnd.xFine); iFine++) { |
| 1551 |
int jOrder=selStart.order; |
| 1552 |
int j=selStart.y; |
| 1553 |
maskOut(opMaskScale,iFine); |
| 1554 |
resetTouches; |
| 1555 |
if (iFine!=0) { |
| 1556 |
int absoluteTop=255; |
| 1557 |
if (iFine==1) { |
| 1558 |
if (e->song.ins.empty()) continue; |
| 1559 |
absoluteTop=e->song.ins.size()-1; |
| 1560 |
} else if (iFine==2) { // volume |
| 1561 |
absoluteTop=e->getMaxVolumeChan(iCoarse); |
| 1562 |
} |
| 1563 |
for (; jOrder<=selEnd.order; jOrder++) { |
| 1564 |
DivPattern* pat=e->curPat[iCoarse].getPattern(e->curOrders->ord[iCoarse][jOrder],true); |
| 1565 |
for (; j<e->curSubSong->patLen && (j<=selEnd.y || jOrder<selEnd.order); j++) { |
| 1566 |
touch(jOrder,j); |
| 1567 |
if (pat->data[j][iFine+1]==-1) continue; |
| 1568 |
pat->data[j][iFine+1]=MIN(absoluteTop,(double)pat->data[j][iFine+1]*(top/100.0f)); |
| 1569 |
} |
| 1570 |
j=0; |
| 1571 |
} |
| 1572 |
} |
| 1573 |
} |
| 1574 |
iFine=0; |
| 1575 |
} |
| 1576 |
|
| 1577 |
makeUndo(GUI_UNDO_PATTERN_SCALE); |
| 1578 |
} |
| 1579 |
|
| 1580 |
void FurnaceGUI::doRandomize(int bottom, int top, bool mode, bool eff, int effVal) { |
| 1581 |
finishSelection(); |
| 1582 |
prepareUndo(GUI_UNDO_PATTERN_RANDOMIZE); |
| 1583 |
|
| 1584 |
int iCoarse=selStart.xCoarse; |
| 1585 |
int iFine=selStart.xFine; |
| 1586 |
for (; iCoarse<=selEnd.xCoarse; iCoarse++) { |
| 1587 |
if (!e->curSubSong->chanShow[iCoarse]) continue; |
| 1588 |
for (; iFine<3+e->curPat[iCoarse].effectCols*2 && (iCoarse<selEnd.xCoarse || iFine<=selEnd.xFine); iFine++) { |
| 1589 |
int jOrder=selStart.order; |
| 1590 |
int j=selStart.y; |
| 1591 |
maskOut(opMaskRandomize,iFine); |
| 1592 |
resetTouches; |
| 1593 |
if (iFine!=0) { |
| 1594 |
int absoluteTop=255; |
| 1595 |
if (iFine==1) { |
| 1596 |
if (e->song.ins.empty()) continue; |
| 1597 |
absoluteTop=e->song.ins.size()-1; |
| 1598 |
} else if (iFine==2) { // volume |
| 1599 |
absoluteTop=e->getMaxVolumeChan(iCoarse); |
| 1600 |
} |
| 1601 |
for (; jOrder<=selEnd.order; jOrder++) { |
| 1602 |
DivPattern* pat=e->curPat[iCoarse].getPattern(e->curOrders->ord[iCoarse][jOrder],true); |
| 1603 |
for (; j<e->curSubSong->patLen && (j<=selEnd.y || jOrder<selEnd.order); j++) { |
| 1604 |
int value=0; |
| 1605 |
int value2=0; |
| 1606 |
touch(jOrder,j); |
| 1607 |
if (top-bottom<=0) { |
| 1608 |
value=MIN(absoluteTop,bottom); |
| 1609 |
value2=MIN(absoluteTop,bottom); |
| 1610 |
} else { |
| 1611 |
value=MIN(absoluteTop,bottom+(rand()%(top-bottom+1))); |
| 1612 |
value2=MIN(absoluteTop,bottom+(rand()%(top-bottom+1))); |
| 1613 |
} |
| 1614 |
if (mode) { |
| 1615 |
value&=15; |
| 1616 |
value2&=15; |
| 1617 |
pat->data[j][iFine+1]=value|(value2<<4); |
| 1618 |
} else { |
| 1619 |
pat->data[j][iFine+1]=value; |
| 1620 |
} |
| 1621 |
if (eff && iFine>2 && (iFine&1)) { |
| 1622 |
pat->data[j][iFine+1]=effVal; |
| 1623 |
} |
| 1624 |
} |
| 1625 |
j=0; |
| 1626 |
} |
| 1627 |
} |
| 1628 |
} |
| 1629 |
iFine=0; |
| 1630 |
} |
| 1631 |
|
| 1632 |
makeUndo(GUI_UNDO_PATTERN_RANDOMIZE); |
| 1633 |
} |
| 1634 |
|
| 1635 |
struct PatBufferEntry { |
| 1636 |
short data[DIV_MAX_COLS]; |
| 1637 |
}; |
| 1638 |
|
| 1639 |
void FurnaceGUI::doFlip() { |
| 1640 |
finishSelection(); |
| 1641 |
prepareUndo(GUI_UNDO_PATTERN_FLIP); |
| 1642 |
|
| 1643 |
std::vector<PatBufferEntry> patBuffer; |
| 1644 |
int iCoarse=selStart.xCoarse; |
| 1645 |
int iFine=selStart.xFine; |
| 1646 |
for (; iCoarse<=selEnd.xCoarse; iCoarse++) { |
| 1647 |
if (!e->curSubSong->chanShow[iCoarse]) continue; |
| 1648 |
patBuffer.clear(); |
| 1649 |
|
| 1650 |
int jOrder=selStart.order; |
| 1651 |
int j=selStart.y; |
| 1652 |
|
| 1653 |
// collect pattern |
| 1654 |
for (; jOrder<=selEnd.order; jOrder++) { |
| 1655 |
DivPattern* pat=e->curPat[iCoarse].getPattern(e->curOrders->ord[iCoarse][jOrder],true); |
| 1656 |
for (; j<e->curSubSong->patLen && (j<=selEnd.y || jOrder<selEnd.order); j++) { |
| 1657 |
PatBufferEntry put; |
| 1658 |
memcpy(put.data,pat->data[j],DIV_MAX_COLS*sizeof(short)); |
| 1659 |
patBuffer.push_back(put); |
| 1660 |
} |
| 1661 |
j=0; |
| 1662 |
} |
| 1663 |
|
| 1664 |
for (; iFine<3+e->curPat[iCoarse].effectCols*2 && (iCoarse<selEnd.xCoarse || iFine<=selEnd.xFine); iFine++) { |
| 1665 |
maskOut(opMaskFlip,iFine); |
| 1666 |
resetTouches; |
| 1667 |
jOrder=selStart.order; |
| 1668 |
j=selStart.y; |
| 1669 |
int j_i=patBuffer.size(); |
| 1670 |
|
| 1671 |
// insert flipped version |
| 1672 |
for (; jOrder<=selEnd.order; jOrder++) { |
| 1673 |
DivPattern* pat=e->curPat[iCoarse].getPattern(e->curOrders->ord[iCoarse][jOrder],true); |
| 1674 |
for (; j<e->curSubSong->patLen && (j<=selEnd.y || jOrder<selEnd.order); j++) { |
| 1675 |
j_i--; |
| 1676 |
touch(jOrder,j); |
| 1677 |
if (iFine==0) { |
| 1678 |
pat->data[j][0]=patBuffer[j_i].data[0]; |
| 1679 |
} |
| 1680 |
pat->data[j][iFine+1]=patBuffer[j_i].data[iFine+1]; |
| 1681 |
} |
| 1682 |
j=0; |
| 1683 |
} |
| 1684 |
} |
| 1685 |
iFine=0; |
| 1686 |
} |
| 1687 |
|
| 1688 |
makeUndo(GUI_UNDO_PATTERN_FLIP); |
| 1689 |
} |
| 1690 |
|
| 1691 |
void FurnaceGUI::doCollapse(int divider, const SelectionPoint& sStart, const SelectionPoint& sEnd) { |
| 1692 |
if (divider<2) return; |
| 1693 |
if (e->curSubSong->patLen<divider) { |
| 1694 |
showError(_("can't collapse any further!")); |
| 1695 |
return; |
| 1696 |
} |
| 1697 |
if (sStart.order!=sEnd.order) { |
| 1698 |
showError(_("can't collapse across orders.")); |
| 1699 |
return; |
| 1700 |
} |
| 1701 |
|
| 1702 |
finishSelection(); |
| 1703 |
prepareUndo(GUI_UNDO_PATTERN_COLLAPSE); |
| 1704 |
|
| 1705 |
DivPattern patBuffer; |
| 1706 |
int iCoarse=sStart.xCoarse; |
| 1707 |
int iFine=sStart.xFine; |
| 1708 |
for (; iCoarse<=sEnd.xCoarse; iCoarse++) { |
| 1709 |
if (!e->curSubSong->chanShow[iCoarse]) continue; |
| 1710 |
DivPattern* pat=e->curPat[iCoarse].getPattern(e->curOrders->ord[iCoarse][curOrder],true); |
| 1711 |
for (; iFine<3+e->curPat[iCoarse].effectCols*2 && (iCoarse<sEnd.xCoarse || iFine<=sEnd.xFine); iFine++) { |
| 1712 |
maskOut(opMaskCollapseExpand,iFine); |
| 1713 |
for (int j=sStart.y; j<=sEnd.y; j++) { |
| 1714 |
if (iFine==0) { |
| 1715 |
patBuffer.data[j][0]=pat->data[j][0]; |
| 1716 |
} |
| 1717 |
patBuffer.data[j][iFine+1]=pat->data[j][iFine+1]; |
| 1718 |
} |
| 1719 |
for (int j=0; j<=sEnd.y-sStart.y; j++) { |
| 1720 |
if (j*divider>=sEnd.y-sStart.y) { |
| 1721 |
if (iFine==0) { |
| 1722 |
pat->data[j+sStart.y][0]=0; |
| 1723 |
pat->data[j+sStart.y][1]=0; |
| 1724 |
} else { |
| 1725 |
pat->data[j+sStart.y][iFine+1]=-1; |
| 1726 |
} |
| 1727 |
} else { |
| 1728 |
if (iFine==0) { |
| 1729 |
pat->data[j+sStart.y][0]=patBuffer.data[j*divider+sStart.y][0]; |
| 1730 |
} |
| 1731 |
pat->data[j+sStart.y][iFine+1]=patBuffer.data[j*divider+sStart.y][iFine+1]; |
| 1732 |
|
| 1733 |
if (iFine==0) { |
| 1734 |
for (int k=1; k<divider; k++) { |
| 1735 |
if ((j*divider+k)>=sEnd.y-sStart.y) break; |
| 1736 |
if (!(pat->data[j+sStart.y][0]==0 && pat->data[j+sStart.y][1]==0)) break; |
| 1737 |
pat->data[j+sStart.y][0]=patBuffer.data[j*divider+sStart.y+k][0]; |
| 1738 |
pat->data[j+sStart.y][1]=patBuffer.data[j*divider+sStart.y+k][1]; |
| 1739 |
} |
| 1740 |
} else { |
| 1741 |
for (int k=1; k<divider; k++) { |
| 1742 |
if ((j*divider+k)>=sEnd.y-sStart.y) break; |
| 1743 |
if (pat->data[j+sStart.y][iFine+1]!=-1) break; |
| 1744 |
pat->data[j+sStart.y][iFine+1]=patBuffer.data[j*divider+sStart.y+k][iFine+1]; |
| 1745 |
} |
| 1746 |
} |
| 1747 |
} |
| 1748 |
} |
| 1749 |
} |
| 1750 |
iFine=0; |
| 1751 |
} |
| 1752 |
|
| 1753 |
makeUndo(GUI_UNDO_PATTERN_COLLAPSE); |
| 1754 |
} |
| 1755 |
|
| 1756 |
void FurnaceGUI::doExpand(int multiplier, const SelectionPoint& sStart, const SelectionPoint& sEnd) { |
| 1757 |
if (multiplier<2) return; |
| 1758 |
if (sStart.order!=sEnd.order) { |
| 1759 |
showError(_("can't expand across orders.")); |
| 1760 |
return; |
| 1761 |
} |
| 1762 |
|
| 1763 |
finishSelection(); |
| 1764 |
prepareUndo(GUI_UNDO_PATTERN_EXPAND); |
| 1765 |
|
| 1766 |
DivPattern patBuffer; |
| 1767 |
int iCoarse=sStart.xCoarse; |
| 1768 |
int iFine=sStart.xFine; |
| 1769 |
for (; iCoarse<=sEnd.xCoarse; iCoarse++) { |
| 1770 |
if (!e->curSubSong->chanShow[iCoarse]) continue; |
| 1771 |
DivPattern* pat=e->curPat[iCoarse].getPattern(e->curOrders->ord[iCoarse][curOrder],true); |
| 1772 |
for (; iFine<3+e->curPat[iCoarse].effectCols*2 && (iCoarse<sEnd.xCoarse || iFine<=sEnd.xFine); iFine++) { |
| 1773 |
maskOut(opMaskCollapseExpand,iFine); |
| 1774 |
for (int j=sStart.y; j<=sEnd.y; j++) { |
| 1775 |
if (iFine==0) { |
| 1776 |
patBuffer.data[j][0]=pat->data[j][0]; |
| 1777 |
} |
| 1778 |
patBuffer.data[j][iFine+1]=pat->data[j][iFine+1]; |
| 1779 |
} |
| 1780 |
for (int j=0; j<=(sEnd.y-sStart.y)*multiplier; j++) { |
| 1781 |
if ((j+sStart.y)>=e->curSubSong->patLen) break; |
| 1782 |
if ((j%multiplier)!=0) { |
| 1783 |
if (iFine==0) { |
| 1784 |
pat->data[j+sStart.y][0]=0; |
| 1785 |
pat->data[j+sStart.y][1]=0; |
| 1786 |
} else { |
| 1787 |
pat->data[j+sStart.y][iFine+1]=-1; |
| 1788 |
} |
| 1789 |
continue; |
| 1790 |
} |
| 1791 |
if (iFine==0) { |
| 1792 |
pat->data[j+sStart.y][0]=patBuffer.data[j/multiplier+sStart.y][0]; |
| 1793 |
} |
| 1794 |
pat->data[j+sStart.y][iFine+1]=patBuffer.data[j/multiplier+sStart.y][iFine+1]; |
| 1795 |
} |
| 1796 |
} |
| 1797 |
iFine=0; |
| 1798 |
} |
| 1799 |
|
| 1800 |
makeUndo(GUI_UNDO_PATTERN_EXPAND); |
| 1801 |
} |
| 1802 |
|
| 1803 |
void FurnaceGUI::doCollapseSong(int divider) { |
| 1804 |
if (divider<2) return; |
| 1805 |
if (e->curSubSong->patLen<divider) { |
| 1806 |
showError(_("can't collapse any further!")); |
| 1807 |
return; |
| 1808 |
} |
| 1809 |
finishSelection(); |
| 1810 |
|
| 1811 |
UndoStep us; |
| 1812 |
us.type=GUI_UNDO_PATTERN_COLLAPSE_SONG; |
| 1813 |
|
| 1814 |
DivPattern patCopy; |
| 1815 |
|
| 1816 |
size_t subSong=e->getCurrentSubSong(); |
| 1817 |
for (int i=0; i<e->getTotalChannelCount(); i++) { |
| 1818 |
for (int j=0; j<DIV_MAX_PATTERNS; j++) { |
| 1819 |
if (e->curPat[i].data[j]==NULL) continue; |
| 1820 |
|
| 1821 |
DivPattern* pat=e->curPat[i].getPattern(j,true); |
| 1822 |
pat->copyOn(&patCopy); |
| 1823 |
pat->clear(); |
| 1824 |
for (int k=0; k<DIV_MAX_ROWS; k++) { |
| 1825 |
for (int l=0; l<DIV_MAX_COLS; l++) { |
| 1826 |
if (l==0) { |
| 1827 |
if (!(pat->data[k/divider][0]==0 && pat->data[k/divider][1]==0)) continue; |
| 1828 |
} else { |
| 1829 |
if (pat->data[k/divider][l+1]!=-1) continue; |
| 1830 |
} |
| 1831 |
|
| 1832 |
if (l==0) { |
| 1833 |
pat->data[k/divider][l]=patCopy.data[k][l]; |
| 1834 |
} |
| 1835 |
pat->data[k/divider][l+1]=patCopy.data[k][l+1]; |
| 1836 |
|
| 1837 |
if (l>3 && !(l&1)) { // scale effects as needed |
| 1838 |
switch (pat->data[k/divider][l]) { |
| 1839 |
case 0x0d: |
| 1840 |
pat->data[k/divider][l+1]/=divider; |
| 1841 |
break; |
| 1842 |
case 0x0f: |
| 1843 |
pat->data[k/divider][l+1]=CLAMP(pat->data[k/divider][l+1]*divider,1,255); |
| 1844 |
break; |
| 1845 |
} |
| 1846 |
} |
| 1847 |
} |
| 1848 |
} |
| 1849 |
|
| 1850 |
// put undo |
| 1851 |
for (int k=0; k<DIV_MAX_ROWS; k++) { |
| 1852 |
for (int l=0; l<DIV_MAX_COLS; l++) { |
| 1853 |
if (pat->data[k][l]!=patCopy.data[k][l]) { |
| 1854 |
us.pat.push_back(UndoPatternData(subSong,i,j,k,l,patCopy.data[k][l],pat->data[k][l])); |
| 1855 |
} |
| 1856 |
} |
| 1857 |
} |
| 1858 |
} |
| 1859 |
} |
| 1860 |
|
| 1861 |
MARK_MODIFIED; |
| 1862 |
|
| 1863 |
// magic |
| 1864 |
unsigned char* subSongInfoCopy=new unsigned char[1024]; |
| 1865 |
memcpy(subSongInfoCopy,e->curSubSong,1024); |
| 1866 |
e->curSubSong->patLen/=divider; |
| 1867 |
for (int i=0; i<e->curSubSong->speeds.len; i++) { |
| 1868 |
e->curSubSong->speeds.val[i]=CLAMP(e->curSubSong->speeds.val[i]*divider,1,255); |
| 1869 |
} |
| 1870 |
unsigned char* newSubSongInfo=(unsigned char*)e->curSubSong; |
| 1871 |
for (int i=0; i<1024; i++) { |
| 1872 |
if (subSongInfoCopy[i]!=newSubSongInfo[i]) { |
| 1873 |
us.other.push_back(UndoOtherData(GUI_UNDO_TARGET_SUBSONG,subSong,i,subSongInfoCopy[i],newSubSongInfo[i])); |
| 1874 |
} |
| 1875 |
} |
| 1876 |
|
| 1877 |
if (!us.pat.empty()) { |
| 1878 |
undoHist.push_back(us); |
| 1879 |
redoHist.clear(); |
| 1880 |
if (undoHist.size()>settings.maxUndoSteps) undoHist.pop_front(); |
| 1881 |
} |
| 1882 |
|
| 1883 |
if (e->isPlaying()) e->play(); |
| 1884 |
} |
| 1885 |
|
| 1886 |
void FurnaceGUI::doExpandSong(int multiplier) { |
| 1887 |
if (multiplier<2) return; |
| 1888 |
if (e->curSubSong->patLen>(256/multiplier)) { |
| 1889 |
showError(_("can't expand any further!")); |
| 1890 |
return; |
| 1891 |
} |
| 1892 |
finishSelection(); |
| 1893 |
|
| 1894 |
UndoStep us; |
| 1895 |
us.type=GUI_UNDO_PATTERN_EXPAND_SONG; |
| 1896 |
|
| 1897 |
DivPattern patCopy; |
| 1898 |
|
| 1899 |
size_t subSong=e->getCurrentSubSong(); |
| 1900 |
for (int i=0; i<e->getTotalChannelCount(); i++) { |
| 1901 |
for (int j=0; j<DIV_MAX_PATTERNS; j++) { |
| 1902 |
if (e->curPat[i].data[j]==NULL) continue; |
| 1903 |
|
| 1904 |
DivPattern* pat=e->curPat[i].getPattern(j,true); |
| 1905 |
pat->copyOn(&patCopy); |
| 1906 |
pat->clear(); |
| 1907 |
for (int k=0; k<(256/multiplier); k++) { |
| 1908 |
for (int l=0; l<DIV_MAX_COLS; l++) { |
| 1909 |
if (l==0) { |
| 1910 |
if (!(pat->data[k*multiplier][0]==0 && pat->data[k*multiplier][1]==0)) continue; |
| 1911 |
} else { |
| 1912 |
if (pat->data[k*multiplier][l+1]!=-1) continue; |
| 1913 |
} |
| 1914 |
|
| 1915 |
if (l==0) { |
| 1916 |
pat->data[k*multiplier][l]=patCopy.data[k][l]; |
| 1917 |
} |
| 1918 |
pat->data[k*multiplier][l+1]=patCopy.data[k][l+1]; |
| 1919 |
|
| 1920 |
if (l>3 && !(l&1)) { // scale effects as needed |
| 1921 |
switch (pat->data[k*multiplier][l]) { |
| 1922 |
case 0x0d: |
| 1923 |
pat->data[k*multiplier][l+1]/=multiplier; |
| 1924 |
break; |
| 1925 |
case 0x0f: |
| 1926 |
pat->data[k*multiplier][l+1]=CLAMP(pat->data[k*multiplier][l+1]/multiplier,1,255); |
| 1927 |
break; |
| 1928 |
} |
| 1929 |
} |
| 1930 |
} |
| 1931 |
} |
| 1932 |
|
| 1933 |
// put undo |
| 1934 |
for (int k=0; k<DIV_MAX_ROWS; k++) { |
| 1935 |
for (int l=0; l<DIV_MAX_COLS; l++) { |
| 1936 |
if (pat->data[k][l]!=patCopy.data[k][l]) { |
| 1937 |
us.pat.push_back(UndoPatternData(subSong,i,j,k,l,patCopy.data[k][l],pat->data[k][l])); |
| 1938 |
} |
| 1939 |
} |
| 1940 |
} |
| 1941 |
} |
| 1942 |
} |
| 1943 |
|
| 1944 |
MARK_MODIFIED; |
| 1945 |
|
| 1946 |
// magic |
| 1947 |
unsigned char* subSongInfoCopy=new unsigned char[1024]; |
| 1948 |
memcpy(subSongInfoCopy,e->curSubSong,1024); |
| 1949 |
e->curSubSong->patLen*=multiplier; |
| 1950 |
for (int i=0; i<e->curSubSong->speeds.len; i++) { |
| 1951 |
e->curSubSong->speeds.val[i]=CLAMP(e->curSubSong->speeds.val[i]/multiplier,1,255); |
| 1952 |
} |
| 1953 |
unsigned char* newSubSongInfo=(unsigned char*)e->curSubSong; |
| 1954 |
for (int i=0; i<1024; i++) { |
| 1955 |
if (subSongInfoCopy[i]!=newSubSongInfo[i]) { |
| 1956 |
us.other.push_back(UndoOtherData(GUI_UNDO_TARGET_SUBSONG,subSong,i,subSongInfoCopy[i],newSubSongInfo[i])); |
| 1957 |
} |
| 1958 |
} |
| 1959 |
|
| 1960 |
if (!us.pat.empty()) { |
| 1961 |
undoHist.push_back(us); |
| 1962 |
redoHist.clear(); |
| 1963 |
if (undoHist.size()>settings.maxUndoSteps) undoHist.pop_front(); |
| 1964 |
} |
| 1965 |
|
| 1966 |
if (e->isPlaying()) e->play(); |
| 1967 |
} |
| 1968 |
|
| 1969 |
void FurnaceGUI::doAbsorbInstrument() { |
| 1970 |
bool foundIns=false; |
| 1971 |
bool foundOctave=false; |
| 1972 |
auto foundAll = [&]() { return foundIns && foundOctave; }; |
| 1973 |
|
| 1974 |
// search this order and all prior until we find all the data we need |
| 1975 |
int orderIdx=curOrder; |
| 1976 |
for (; orderIdx>=0 && !foundAll(); orderIdx--) { |
| 1977 |
DivPattern* pat=e->curPat[cursor.xCoarse].getPattern(e->curOrders->ord[cursor.xCoarse][orderIdx],false); |
| 1978 |
if (!pat) continue; |
| 1979 |
|
| 1980 |
// start on current row when searching current order, but start from end when searching |
| 1981 |
// prior orders. |
| 1982 |
int searchStartRow=orderIdx==curOrder ? cursor.y : e->curSubSong->patLen-1; |
| 1983 |
for (int i=searchStartRow; i>=0 && !foundAll(); i--) { |
| 1984 |
|
| 1985 |
// absorb most recent instrument |
| 1986 |
if (!foundIns && pat->data[i][2] >= 0) { |
| 1987 |
foundIns=true; |
| 1988 |
curIns=pat->data[i][2]; |
| 1989 |
} |
| 1990 |
|
| 1991 |
// absorb most recent octave (i.e. set curOctave such that the "main row" (QWERTY) of |
| 1992 |
// notes will result in an octave number equal to the previous note). make sure to |
| 1993 |
// skip "special note values" like OFF/REL/=== and "none", since there won't be valid |
| 1994 |
// octave values |
| 1995 |
unsigned char note=pat->data[i][0]; |
| 1996 |
if (!foundOctave && note!=0 && note!=100 && note!=101 && note!=102) { |
| 1997 |
foundOctave=true; |
| 1998 |
|
| 1999 |
// decode octave data (was signed cast to unsigned char) |
| 2000 |
int octave=pat->data[i][1]; |
| 2001 |
if (octave>128) octave-=256; |
| 2002 |
|
| 2003 |
// @NOTE the special handling when note==12, which is really an octave above what's |
| 2004 |
// stored in the octave data. without this handling, if you press Q, then |
| 2005 |
// "ABSORB_INSTRUMENT", then Q again, you'd get a different octave! |
| 2006 |
if (pat->data[i][0]==12) octave++; |
| 2007 |
curOctave=CLAMP(octave-1, GUI_EDIT_OCTAVE_MIN, GUI_EDIT_OCTAVE_MAX); |
| 2008 |
} |
| 2009 |
} |
| 2010 |
} |
| 2011 |
|
| 2012 |
// if no instrument has been set at this point, the only way to match it is to use "none" |
| 2013 |
if (!foundIns) curIns=-1; |
| 2014 |
|
| 2015 |
logD("doAbsorbInstrument -- searched %d orders", curOrder-orderIdx); |
| 2016 |
} |
| 2017 |
|
| 2018 |
void FurnaceGUI::doDrag(bool copy) { |
| 2019 |
int len=dragEnd.xCoarse-dragStart.xCoarse+1; |
| 2020 |
int firstOrder=e->curSubSong->ordersLen; |
| 2021 |
int lastOrder=0; |
| 2022 |
|
| 2023 |
if (dragStart.order<firstOrder) firstOrder=dragStart.order; |
| 2024 |
if (dragEnd.order<firstOrder) firstOrder=dragEnd.order; |
| 2025 |
if (selStart.order<firstOrder) firstOrder=selStart.order; |
| 2026 |
if (dragStart.order>lastOrder) lastOrder=dragStart.order; |
| 2027 |
if (dragEnd.order>lastOrder) lastOrder=dragEnd.order; |
| 2028 |
if (selStart.order>lastOrder) lastOrder=selStart.order; |
| 2029 |
|
| 2030 |
logV("UR: %d - %d",firstOrder,lastOrder); |
| 2031 |
|
| 2032 |
if (len<1) return; |
| 2033 |
|
| 2034 |
prepareUndo(GUI_UNDO_PATTERN_DRAG,UndoRegion(firstOrder,0,0,lastOrder,e->getTotalChannelCount()-1,e->curSubSong->patLen-1)); |
| 2035 |
|
| 2036 |
// copy and clear (if copy is false) |
| 2037 |
String c=doCopy(!copy,false,dragStart,dragEnd); |
| 2038 |
|
| 2039 |
logV(_("copy: %s"),c); |
| 2040 |
|
| 2041 |
// replace |
| 2042 |
cursor=selStart; |
| 2043 |
doPaste(GUI_PASTE_MODE_OVERFLOW,0,false,c); |
| 2044 |
updateScroll(cursor.y); |
| 2045 |
|
| 2046 |
makeUndo(GUI_UNDO_PATTERN_DRAG,UndoRegion(firstOrder,0,0,lastOrder,e->getTotalChannelCount()-1,e->curSubSong->patLen-1)); |
| 2047 |
} |
| 2048 |
|
| 2049 |
void FurnaceGUI::moveSelected(int x, int y) { |
| 2050 |
SelectionPoint selStartOld, selEndOld, selStartNew, selEndNew; |
| 2051 |
selStartOld=selStart; |
| 2052 |
selEndOld=selEnd; |
| 2053 |
|
| 2054 |
// move selection |
| 2055 |
DETERMINE_FIRST_LAST; |
| 2056 |
|
| 2057 |
bool outOfBounds=false; |
| 2058 |
|
| 2059 |
if (x>0) { |
| 2060 |
for (int i=0; i<x; i++) { |
| 2061 |
do { |
| 2062 |
selStart.xCoarse++; |
| 2063 |
if (selStart.xCoarse>=lastChannel) { |
| 2064 |
outOfBounds=true; |
| 2065 |
break; |
| 2066 |
} |
| 2067 |
} while (!e->curSubSong->chanShow[selStart.xCoarse]); |
| 2068 |
|
| 2069 |
do { |
| 2070 |
selEnd.xCoarse++; |
| 2071 |
if (selEnd.xCoarse>=lastChannel) { |
| 2072 |
outOfBounds=true; |
| 2073 |
break; |
| 2074 |
} |
| 2075 |
} while (!e->curSubSong->chanShow[selEnd.xCoarse]); |
| 2076 |
|
| 2077 |
if (outOfBounds) break; |
| 2078 |
} |
| 2079 |
} else if (x<0) { |
| 2080 |
for (int i=0; i<-x; i++) { |
| 2081 |
do { |
| 2082 |
selStart.xCoarse--; |
| 2083 |
if (selStart.xCoarse<firstChannel) { |
| 2084 |
outOfBounds=true; |
| 2085 |
break; |
| 2086 |
} |
| 2087 |
} while (!e->curSubSong->chanShow[selStart.xCoarse]); |
| 2088 |
|
| 2089 |
do { |
| 2090 |
selEnd.xCoarse--; |
| 2091 |
if (selEnd.xCoarse<firstChannel) { |
| 2092 |
outOfBounds=true; |
| 2093 |
break; |
| 2094 |
} |
| 2095 |
} while (!e->curSubSong->chanShow[selEnd.xCoarse]); |
| 2096 |
|
| 2097 |
if (outOfBounds) break; |
| 2098 |
} |
| 2099 |
} |
| 2100 |
|
| 2101 |
selStart.y+=y; |
| 2102 |
selEnd.y+=y; |
| 2103 |
|
| 2104 |
while (selStart.y<0) { |
| 2105 |
selStart.y+=e->curSubSong->patLen; |
| 2106 |
selStart.order--; |
| 2107 |
} |
| 2108 |
while (selEnd.y<0) { |
| 2109 |
selEnd.y+=e->curSubSong->patLen; |
| 2110 |
selEnd.order--; |
| 2111 |
} |
| 2112 |
|
| 2113 |
while (selStart.y>=e->curSubSong->patLen) { |
| 2114 |
selStart.y-=e->curSubSong->patLen; |
| 2115 |
selStart.order++; |
| 2116 |
} |
| 2117 |
while (selEnd.y>=e->curSubSong->patLen) { |
| 2118 |
selEnd.y-=e->curSubSong->patLen; |
| 2119 |
selEnd.order++; |
| 2120 |
} |
| 2121 |
|
| 2122 |
if (selStart.order<0 || selStart.order>=e->curSubSong->ordersLen) outOfBounds=true; |
| 2123 |
if (selEnd.order<0 || selEnd.order>=e->curSubSong->ordersLen) outOfBounds=true; |
| 2124 |
|
| 2125 |
selStartNew=selStart; |
| 2126 |
selEndNew=selEnd; |
| 2127 |
|
| 2128 |
selStart=selStartOld; |
| 2129 |
selEnd=selEndOld; |
| 2130 |
|
| 2131 |
if (outOfBounds) { |
| 2132 |
return; |
| 2133 |
} |
| 2134 |
|
| 2135 |
int firstOrder=e->curSubSong->ordersLen; |
| 2136 |
int lastOrder=0; |
| 2137 |
|
| 2138 |
if (selStartNew.order<firstOrder) firstOrder=selStartNew.order; |
| 2139 |
if (selEndNew.order<firstOrder) firstOrder=selEndNew.order; |
| 2140 |
if (selStart.order<firstOrder) firstOrder=selStart.order; |
| 2141 |
if (selStartNew.order>lastOrder) lastOrder=selStartNew.order; |
| 2142 |
if (selEndNew.order>lastOrder) lastOrder=selEndNew.order; |
| 2143 |
if (selStart.order>lastOrder) lastOrder=selStart.order; |
| 2144 |
|
| 2145 |
logV("UR: %d - %d",firstOrder,lastOrder); |
| 2146 |
|
| 2147 |
prepareUndo(GUI_UNDO_PATTERN_DRAG,UndoRegion(firstOrder,0,0,lastOrder,e->getTotalChannelCount()-1,e->curSubSong->patLen-1)); |
| 2148 |
|
| 2149 |
// copy and clear |
| 2150 |
String c=doCopy(true,false,selStart,selEnd); |
| 2151 |
|
| 2152 |
logV(_("copy: %s"),c); |
| 2153 |
|
| 2154 |
// move |
| 2155 |
selStart=selStartNew; |
| 2156 |
selEnd=selEndNew; |
| 2157 |
|
| 2158 |
// replace |
| 2159 |
cursor=selStart; |
| 2160 |
doPaste(GUI_PASTE_MODE_OVERFLOW,0,false,c); |
| 2161 |
|
| 2162 |
makeUndo(GUI_UNDO_PATTERN_DRAG,UndoRegion(firstOrder,0,0,lastOrder,e->getTotalChannelCount()-1,e->curSubSong->patLen-1)); |
| 2163 |
} |
| 2164 |
|
| 2165 |
void FurnaceGUI::doUndo() { |
| 2166 |
if (undoHist.empty()) return; |
| 2167 |
UndoStep& us=undoHist.back(); |
| 2168 |
redoHist.push_back(us); |
| 2169 |
MARK_MODIFIED; |
| 2170 |
|
| 2171 |
switch (us.type) { |
| 2172 |
case GUI_UNDO_CHANGE_ORDER: |
| 2173 |
e->curSubSong->ordersLen=us.oldOrdersLen; |
| 2174 |
for (UndoOrderData& i: us.ord) { |
| 2175 |
e->changeSongP(i.subSong); |
| 2176 |
e->curOrders->ord[i.chan][i.ord]=i.oldVal; |
| 2177 |
} |
| 2178 |
break; |
| 2179 |
case GUI_UNDO_PATTERN_EDIT: |
| 2180 |
case GUI_UNDO_PATTERN_DELETE: |
| 2181 |
case GUI_UNDO_PATTERN_PULL: |
| 2182 |
case GUI_UNDO_PATTERN_PUSH: |
| 2183 |
case GUI_UNDO_PATTERN_CUT: |
| 2184 |
case GUI_UNDO_PATTERN_PASTE: |
| 2185 |
case GUI_UNDO_PATTERN_CHANGE_INS: |
| 2186 |
case GUI_UNDO_PATTERN_INTERPOLATE: |
| 2187 |
case GUI_UNDO_PATTERN_FADE: |
| 2188 |
case GUI_UNDO_PATTERN_SCALE: |
| 2189 |
case GUI_UNDO_PATTERN_RANDOMIZE: |
| 2190 |
case GUI_UNDO_PATTERN_INVERT_VAL: |
| 2191 |
case GUI_UNDO_PATTERN_FLIP: |
| 2192 |
case GUI_UNDO_PATTERN_COLLAPSE: |
| 2193 |
case GUI_UNDO_PATTERN_EXPAND: |
| 2194 |
case GUI_UNDO_PATTERN_COLLAPSE_SONG: |
| 2195 |
case GUI_UNDO_PATTERN_EXPAND_SONG: |
| 2196 |
case GUI_UNDO_PATTERN_DRAG: |
| 2197 |
case GUI_UNDO_REPLACE: |
| 2198 |
for (UndoPatternData& i: us.pat) { |
| 2199 |
e->changeSongP(i.subSong); |
| 2200 |
DivPattern* p=e->curPat[i.chan].getPattern(i.pat,true); |
| 2201 |
p->data[i.row][i.col]=i.oldVal; |
| 2202 |
} |
| 2203 |
if (us.type!=GUI_UNDO_REPLACE) { |
| 2204 |
if (!e->isPlaying() || !followPattern) { |
| 2205 |
cursor=us.oldCursor; |
| 2206 |
selStart=us.oldSelStart; |
| 2207 |
selEnd=us.oldSelEnd; |
| 2208 |
curNibble=us.nibble; |
| 2209 |
setOrder(us.oldOrder); |
| 2210 |
if (us.oldScroll>=0.0f) { |
| 2211 |
updateScrollRaw(us.oldScroll); |
| 2212 |
} |
| 2213 |
} |
| 2214 |
} |
| 2215 |
e->walkSong(loopOrder,loopRow,loopEnd); |
| 2216 |
break; |
| 2217 |
} |
| 2218 |
|
| 2219 |
bool shallReplay=false; |
| 2220 |
for (UndoOtherData& i: us.other) { |
| 2221 |
switch (i.target) { |
| 2222 |
case GUI_UNDO_TARGET_SONG: |
| 2223 |
((unsigned char*)(&e->song))[i.off]=i.oldVal; |
| 2224 |
shallReplay=true; |
| 2225 |
break; |
| 2226 |
case GUI_UNDO_TARGET_SUBSONG: |
| 2227 |
if (i.subtarget<0 || i.subtarget>=(int)e->song.subsong.size()) break; |
| 2228 |
((unsigned char*)(e->song.subsong[i.subtarget]))[i.off]=i.oldVal; |
| 2229 |
shallReplay=true; |
| 2230 |
break; |
| 2231 |
} |
| 2232 |
} |
| 2233 |
if (shallReplay && e->isPlaying()) play(); |
| 2234 |
|
| 2235 |
if (curOrder>=e->curSubSong->ordersLen) { |
| 2236 |
curOrder=e->curSubSong->ordersLen-1; |
| 2237 |
e->setOrder(curOrder); |
| 2238 |
} |
| 2239 |
|
| 2240 |
undoHist.pop_back(); |
| 2241 |
} |
| 2242 |
|
| 2243 |
void FurnaceGUI::doRedo() { |
| 2244 |
if (redoHist.empty()) return; |
| 2245 |
UndoStep& us=redoHist.back(); |
| 2246 |
undoHist.push_back(us); |
| 2247 |
MARK_MODIFIED; |
| 2248 |
|
| 2249 |
switch (us.type) { |
| 2250 |
case GUI_UNDO_CHANGE_ORDER: |
| 2251 |
e->curSubSong->ordersLen=us.newOrdersLen; |
| 2252 |
for (UndoOrderData& i: us.ord) { |
| 2253 |
e->changeSongP(i.subSong); |
| 2254 |
e->curOrders->ord[i.chan][i.ord]=i.newVal; |
| 2255 |
} |
| 2256 |
break; |
| 2257 |
case GUI_UNDO_PATTERN_EDIT: |
| 2258 |
case GUI_UNDO_PATTERN_DELETE: |
| 2259 |
case GUI_UNDO_PATTERN_PULL: |
| 2260 |
case GUI_UNDO_PATTERN_PUSH: |
| 2261 |
case GUI_UNDO_PATTERN_CUT: |
| 2262 |
case GUI_UNDO_PATTERN_PASTE: |
| 2263 |
case GUI_UNDO_PATTERN_CHANGE_INS: |
| 2264 |
case GUI_UNDO_PATTERN_INTERPOLATE: |
| 2265 |
case GUI_UNDO_PATTERN_FADE: |
| 2266 |
case GUI_UNDO_PATTERN_SCALE: |
| 2267 |
case GUI_UNDO_PATTERN_RANDOMIZE: |
| 2268 |
case GUI_UNDO_PATTERN_INVERT_VAL: |
| 2269 |
case GUI_UNDO_PATTERN_FLIP: |
| 2270 |
case GUI_UNDO_PATTERN_COLLAPSE: |
| 2271 |
case GUI_UNDO_PATTERN_EXPAND: |
| 2272 |
case GUI_UNDO_PATTERN_DRAG: |
| 2273 |
case GUI_UNDO_PATTERN_COLLAPSE_SONG: |
| 2274 |
case GUI_UNDO_PATTERN_EXPAND_SONG: |
| 2275 |
case GUI_UNDO_REPLACE: |
| 2276 |
for (UndoPatternData& i: us.pat) { |
| 2277 |
e->changeSongP(i.subSong); |
| 2278 |
DivPattern* p=e->curPat[i.chan].getPattern(i.pat,true); |
| 2279 |
p->data[i.row][i.col]=i.newVal; |
| 2280 |
} |
| 2281 |
if (us.type!=GUI_UNDO_REPLACE) { |
| 2282 |
if (!e->isPlaying() || !followPattern) { |
| 2283 |
cursor=us.newCursor; |
| 2284 |
selStart=us.newSelStart; |
| 2285 |
selEnd=us.newSelEnd; |
| 2286 |
curNibble=us.nibble; |
| 2287 |
setOrder(us.newOrder); |
| 2288 |
if (us.newScroll>=0.0f) { |
| 2289 |
updateScrollRaw(us.newScroll); |
| 2290 |
} |
| 2291 |
} |
| 2292 |
} |
| 2293 |
e->walkSong(loopOrder,loopRow,loopEnd); |
| 2294 |
break; |
| 2295 |
} |
| 2296 |
|
| 2297 |
bool shallReplay=false; |
| 2298 |
for (UndoOtherData& i: us.other) { |
| 2299 |
switch (i.target) { |
| 2300 |
case GUI_UNDO_TARGET_SONG: |
| 2301 |
((unsigned char*)(&e->song))[i.off]=i.newVal; |
| 2302 |
shallReplay=true; |
| 2303 |
break; |
| 2304 |
case GUI_UNDO_TARGET_SUBSONG: |
| 2305 |
if (i.subtarget<0 || i.subtarget>=(int)e->song.subsong.size()) break; |
| 2306 |
((unsigned char*)(e->song.subsong[i.subtarget]))[i.off]=i.newVal; |
| 2307 |
shallReplay=true; |
| 2308 |
break; |
| 2309 |
} |
| 2310 |
} |
| 2311 |
if (shallReplay && e->isPlaying()) play(); |
| 2312 |
|
| 2313 |
if (curOrder>=e->curSubSong->ordersLen) { |
| 2314 |
curOrder=e->curSubSong->ordersLen-1; |
| 2315 |
e->setOrder(curOrder); |
| 2316 |
} |
| 2317 |
|
| 2318 |
redoHist.pop_back(); |
| 2319 |
} |
| 2320 |
|
| 2321 |
CursorJumpPoint FurnaceGUI::getCurrentCursorJumpPoint() { |
| 2322 |
return CursorJumpPoint(cursor, curOrder, e->getCurrentSubSong()); |
| 2323 |
} |
| 2324 |
|
| 2325 |
void FurnaceGUI::applyCursorJumpPoint(const CursorJumpPoint& spot) { |
| 2326 |
cursor=spot.point; |
| 2327 |
curOrder=MIN(e->curSubSong->ordersLen-1, spot.order); |
| 2328 |
e->setOrder(curOrder); |
| 2329 |
e->changeSongP(spot.subSong); |
| 2330 |
if (!settings.cursorMoveNoScroll) { |
| 2331 |
updateScroll(cursor.y); |
| 2332 |
} |
| 2333 |
} |
| 2334 |
|
| 2335 |
void FurnaceGUI::makeCursorUndo() { |
| 2336 |
CursorJumpPoint spot = getCurrentCursorJumpPoint(); |
| 2337 |
if (!cursorUndoHist.empty() && spot == cursorUndoHist.back()) return; |
| 2338 |
|
| 2339 |
if (cursorUndoHist.size()>=settings.maxUndoSteps) cursorUndoHist.pop_front(); |
| 2340 |
cursorUndoHist.push_back(spot); |
| 2341 |
|
| 2342 |
// redo history no longer relevant, we've changed timeline |
| 2343 |
cursorRedoHist.clear(); |
| 2344 |
} |
| 2345 |
|
| 2346 |
void FurnaceGUI::doCursorUndo() { |
| 2347 |
if (cursorUndoHist.empty()) return; |
| 2348 |
|
| 2349 |
// allow returning to current spot |
| 2350 |
if (cursorRedoHist.size()>=settings.maxUndoSteps) cursorRedoHist.pop_front(); |
| 2351 |
cursorRedoHist.push_back(getCurrentCursorJumpPoint()); |
| 2352 |
|
| 2353 |
// apply spot |
| 2354 |
applyCursorJumpPoint(cursorUndoHist.back()); |
| 2355 |
cursorUndoHist.pop_back(); |
| 2356 |
} |
| 2357 |
|
| 2358 |
void FurnaceGUI::doCursorRedo() { |
| 2359 |
if (cursorRedoHist.empty()) return; |
| 2360 |
|
| 2361 |
// allow returning to current spot |
| 2362 |
if (cursorUndoHist.size()>=settings.maxUndoSteps) cursorUndoHist.pop_front(); |
| 2363 |
cursorUndoHist.push_back(getCurrentCursorJumpPoint()); |
| 2364 |
|
| 2365 |
// apply spot |
| 2366 |
applyCursorJumpPoint(cursorRedoHist.back()); |
| 2367 |
cursorRedoHist.pop_back(); |
| 2368 |
} |