From a7244cf343d75edc4b8e0559e0350048ed9eb307 Mon Sep 17 00:00:00 2001 From: mjbudd77 Date: Sun, 28 Nov 2021 18:56:22 -0500 Subject: [PATCH] Implemented piano roll save/load state functionality for Qt GUI. Fixed periodic autosave for Qt Tas editor. --- icons/taseditor-icon32.png | Bin 0 -> 1204 bytes resources.qrc | 1 + src/drivers/Qt/TasEditor/TasEditorWindow.cpp | 88 +++++++++++++++++- src/drivers/Qt/TasEditor/TasEditorWindow.h | 4 + .../Qt/TasEditor/taseditor_project.cpp | 22 +++-- 5 files changed, 103 insertions(+), 12 deletions(-) create mode 100644 icons/taseditor-icon32.png diff --git a/icons/taseditor-icon32.png b/icons/taseditor-icon32.png new file mode 100644 index 0000000000000000000000000000000000000000..32bc52eeb58a751fa93f917ebc13cd6f7eb71e7b GIT binary patch literal 1204 zcmV;l1WWsgP)004R>004l5008;`004mK004C`008P>0026e000+ooVrmw00006 zVoOIv0RI600RN!9r;`8x1ItN7K~z}7?Uv7L8%Gq!KW}DMvK5j>HaMh79k5UR4}1+K zhx`HUwSgXb$f5M_=|#{(ZaMkpLRv^&r~@s9losrRsjE=p$obJq*6z%_9%ffstCC!d zA&2HI%d)eddGnq3-pr0{Y;0(+*W>v3n943)y2SGGGMk&5v|23yM1&Y4yfM&na#@y5AdChV5lkgyh5#dGE@vjZ8^DT;(&C!UCKz)%0>*$b z7&CSbAZ44e7K=qiQFJb6fLeJIL{J#jfLmBxM2w_C>-ni1ly}l)u-0O&#fV8&&wS37 zQK-z7&&9>Xv4CkcAX0NuinG>Yox?eY!JsHs>=_)V1PEY6#t}%Jrqw{2i4j3c$EFJH zM6~8{lWR<>8Yx+qEiB;68ISUWA&6m~X&C`UIgd3L7Lowx94dm=QlJ7#S}MjlY?<3p zXlpA+k-6NYyy|^aFXxhff%Z;-iF&>wx+rtS$q7y)PUEOCYD85*6%irJGGdH~NNNX! zNGicNmz!nz$w?9rLqHUy)7ZL?RZ$FK>PYpuqF#?R$Lr=n<|QI0x$TRF$C0a4?vbf-*xI)48xH7#2C+d)nLHm=k=U-EQ+@;uu!900dR?;V=pCMUe(mg=zbGOk%wE#PXV&mhws* zGpMR`!F!*w9pfx?Qpd$`m4J%-&pY8+>-xOh+uw@c3HaX&aP4-Rt?jQl_~URYaP`W2 ztloH^m6a8~-TH=S2i>XM<*Qe?zIvUNl@%UuZSm~jU05UK#F)c7NEipG#GBG+dG&(UkEig1X zFfd1cNO}MO03~!qSaf7zbY(hiZ)9m^c>ppnGBGVMGc7SUR5CF-G&DLfIV~_WIxsLc SBk;xm0000icons/find.png icons/cloud.png icons/branch_spritesheet.png + icons/taseditor-icon32.png diff --git a/src/drivers/Qt/TasEditor/TasEditorWindow.cpp b/src/drivers/Qt/TasEditor/TasEditorWindow.cpp index 6e6ddda8..d179854a 100644 --- a/src/drivers/Qt/TasEditor/TasEditorWindow.cpp +++ b/src/drivers/Qt/TasEditor/TasEditorWindow.cpp @@ -86,6 +86,11 @@ enum DRAG_MODES #define GREEN_BLUE_ARROW_IMAGE_ID (BLUE_ARROW_IMAGE_ID | GREEN_ARROW_IMAGE_ID) #define MARKER_DRAG_COUNTDOWN_MAX 14 +#define PIANO_ROLL_ID_LEN 11 + +// resources +static char pianoRollSaveID[PIANO_ROLL_ID_LEN] = "PIANO_ROLL"; +static char pianoRollSkipSaveID[PIANO_ROLL_ID_LEN] = "PIANO_ROLX"; //---------------------------------------------------------------------------- //---- Main TAS Editor Window @@ -173,6 +178,7 @@ TasEditorWindow::TasEditorWindow(QWidget *parent) clipboard = QGuiApplication::clipboard(); setWindowTitle("TAS Editor"); + //setWindowIcon( QIcon(":icons/taseditor-icon32.png") ); resize(512, 512); @@ -3193,6 +3199,69 @@ void QPianoRoll::reset(void) } //---------------------------------------------------------------------------- +void QPianoRoll::save(EMUFILE *os, bool really_save) +{ + if (really_save) + { + updateLinesCount(); + // write "PIANO_ROLL" string + os->fwrite(pianoRollSaveID, PIANO_ROLL_ID_LEN); + // write current top item + int top_item = lineOffset; + write32le(top_item, os); + } + else + { + // write "PIANO_ROLX" string + os->fwrite(pianoRollSkipSaveID, PIANO_ROLL_ID_LEN); + } +} +//---------------------------------------------------------------------------- +// returns true if couldn't load +bool QPianoRoll::load(EMUFILE *is, unsigned int offset) +{ + reset(); + updateLinesCount(); + if (offset) + { + if (is->fseek(offset, SEEK_SET)) goto error; + } + else + { + // scroll to the beginning + //ListView_EnsureVisible(hwndList, 0, FALSE); + lineOffset = 0; + return false; + } + // read "PIANO_ROLL" string + char save_id[PIANO_ROLL_ID_LEN]; + if ((int)is->fread(save_id, PIANO_ROLL_ID_LEN) < PIANO_ROLL_ID_LEN) goto error; + if (!strcmp(pianoRollSkipSaveID, save_id)) + { + // string says to skip loading Piano Roll + FCEU_printf("No Piano Roll data in the file\n"); + // scroll to the beginning + //ListView_EnsureVisible(hwndList, 0, FALSE); + lineOffset = 0; + return false; + } + if (strcmp(pianoRollSaveID, save_id)) goto error; // string is not valid + // read current top item and scroll Piano Roll there + int top_item; + if (!read32le(&top_item, is)) goto error; + //ListView_EnsureVisible(hwndList, currMovieData.getNumRecords() - 1, FALSE); + //ListView_EnsureVisible(hwndList, top_item, FALSE); + ensureTheLineIsVisible( currMovieData.getNumRecords() - 1 ); + ensureTheLineIsVisible( top_item ); + return false; +error: + FCEU_printf("Error loading Piano Roll data\n"); + // scroll to the beginning + //ListView_EnsureVisible(hwndList, 0, FALSE); + lineOffset = 0; + return true; +} +//---------------------------------------------------------------------------- void QPianoRoll::setScrollBars( QScrollBar *h, QScrollBar *v ) { hbar = h; vbar = v; @@ -3431,9 +3500,22 @@ void QPianoRoll::drawArrow( QPainter *painter, int xl, int yl, int value ) } } //---------------------------------------------------------------------------- +void QPianoRoll::updateLinesCount(void) +{ + // update the number of items in the list + int movie_size = currMovieData.getNumRecords(); + + maxLineOffset = movie_size - viewLines + 5; + + if ( maxLineOffset < 0 ) + { + maxLineOffset = 0; + } +} +//---------------------------------------------------------------------------- bool QPianoRoll::lineIsVisible( int lineNum ) { - int lineEnd = lineOffset + viewLines; + int lineEnd = lineOffset + viewLines - 1; return ( (lineNum >= lineOffset) && (lineNum < lineEnd) ); } @@ -3444,7 +3526,9 @@ void QPianoRoll::ensureTheLineIsVisible( int lineNum ) { int scrollOfs; - lineOffset = lineNum - 3; + //printf("Seeking Frame %i\n", lineNum ); + + lineOffset = lineNum; if ( lineOffset < 0 ) { diff --git a/src/drivers/Qt/TasEditor/TasEditorWindow.h b/src/drivers/Qt/TasEditor/TasEditorWindow.h index b5b85ea8..6de5354d 100644 --- a/src/drivers/Qt/TasEditor/TasEditorWindow.h +++ b/src/drivers/Qt/TasEditor/TasEditorWindow.h @@ -135,6 +135,8 @@ class QPianoRoll : public QWidget ~QPianoRoll(void); void reset(void); + void save(EMUFILE *os, bool really_save); + bool load(EMUFILE *is, unsigned int offset); void setScrollBars( QScrollBar *h, QScrollBar *v ); QFont getFont(void){ return font; }; @@ -143,6 +145,7 @@ class QPianoRoll : public QWidget bool lineIsVisible( int lineNum ); + void updateLinesCount(void); void handleColumnSet(int column, bool altPressed); void centerListAroundLine(int rowIndex); void ensureTheLineIsVisible( int lineNum ); @@ -447,6 +450,7 @@ class TasEditorWindow : public QDialog friend class PLAYBACK; friend class HISTORY; friend class MARKERS_MANAGER; + friend class TASEDITOR_PROJECT; friend class QPianoRoll; }; diff --git a/src/drivers/Qt/TasEditor/taseditor_project.cpp b/src/drivers/Qt/TasEditor/taseditor_project.cpp index 98504a9f..b19bc893 100644 --- a/src/drivers/Qt/TasEditor/taseditor_project.cpp +++ b/src/drivers/Qt/TasEditor/taseditor_project.cpp @@ -64,14 +64,14 @@ void TASEDITOR_PROJECT::update() // if it's time to autosave - pop Save As dialog if (changed && /*taseditorWindow.TASEditorIsInFocus &&*/ taseditorConfig->autosaveEnabled && !projectFile.empty() && clock() >= nextSaveShedule /*&& pianoRoll.dragMode == DRAG_MODE_NONE*/) { - //if (taseditorConfig->autosaveSilent) - //{ - // saveProject(); - //} - //else - //{ - // saveProjectAs(); - //} + if (taseditorConfig->autosaveSilent) + { + tasWin->saveProject(); + } + else + { + tasWin->saveProjectAs(); + } // in case user pressed Cancel, postpone saving to next time sheduleNextAutosave(); } @@ -80,8 +80,10 @@ void TASEDITOR_PROJECT::update() bool TASEDITOR_PROJECT::save(const char* differentName, bool inputInBinary, bool saveMarkers, bool saveBookmarks, int saveGreenzone, bool saveHistory, bool savePianoRoll, bool saveSelection) { if (!differentName && getProjectFile().empty()) + { // no different name specified, and there's no current filename of the project return false; + } // check MD5 char md5OfMovie[256]; @@ -160,7 +162,7 @@ bool TASEDITOR_PROJECT::save(const char* differentName, bool inputInBinary, bool unsigned int historyOffset = ofs->ftell(); history->save(ofs, saveHistory); unsigned int pianoRollOffset = ofs->ftell(); - //pianoRoll.save(ofs, savePianoRoll); + tasWin->pianoRoll->save(ofs, savePianoRoll); unsigned int selectionOffset = ofs->ftell(); selection->save(ofs, saveSelection); // now write offsets (pointers) @@ -319,7 +321,7 @@ bool TASEDITOR_PROJECT::load(const char* fullName) pointerOffset += sizeof(unsigned int); else dataOffset = 0; - //pianoRoll.load(&ifs, dataOffset); + tasWin->pianoRoll->load(&ifs, dataOffset); if (numberOfPointers-- && !(ifs.fseek(pointerOffset, SEEK_SET)) && read32le(&dataOffset, &ifs)) pointerOffset += sizeof(unsigned int);