annotate editor/edmain.cpp @ 2294:7f6ba3b32f54

Cleanups.
author Matti Hamalainen <ccr@tnsp.org>
date Wed, 03 Jul 2019 10:28:43 +0300
parents b4992d9f72fe
children 69a5af2eb1ea
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
376
40e33ad0d153 Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1 //
40e33ad0d153 Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
2 // Demo Editor -- Main program
40e33ad0d153 Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
3 // (C) Copyright 2012 Matti 'ccr' Hämäläinen <ccr@tnsp.org>
40e33ad0d153 Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
4 //
40e33ad0d153 Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
5 #include <SDL.h>
40e33ad0d153 Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
6 #include "dmengine.h"
40e33ad0d153 Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
7 #include "edmain.h"
40e33ad0d153 Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
8 #include <QSettings>
40e33ad0d153 Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
9 #include <QGLWidget>
40e33ad0d153 Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
10
40e33ad0d153 Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
11
40e33ad0d153 Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
12 int main(int argc, char *argv[])
40e33ad0d153 Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
13 {
40e33ad0d153 Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
14 dmVerbosity = 5;
40e33ad0d153 Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
15
40e33ad0d153 Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
16 QApplication app(argc, argv);
40e33ad0d153 Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
17
40e33ad0d153 Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
18 app.setOrganizationName("TNSP");
40e33ad0d153 Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
19 app.setOrganizationDomain("tnsp.org");
40e33ad0d153 Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
20 app.setApplicationName(PROGRAM_NAME);
40e33ad0d153 Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
21 app.setApplicationVersion(PROGRAM_VERSION);
40e33ad0d153 Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
22
40e33ad0d153 Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
23 DemoEditor mainWin;
40e33ad0d153 Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
24
40e33ad0d153 Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
25 mainWin.show();
40e33ad0d153 Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
26
40e33ad0d153 Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
27 return app.exec();
40e33ad0d153 Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
28 }
40e33ad0d153 Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
29
40e33ad0d153 Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
30
40e33ad0d153 Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
31 void engineAudioCallback(void *userdata, Uint8 * stream, int len)
40e33ad0d153 Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
32 {
40e33ad0d153 Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
33 DMEngineData *engine = (DMEngineData *) userdata;
40e33ad0d153 Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
34
40e33ad0d153 Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
35 if (engine->paused)
40e33ad0d153 Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
36 {
1170
ef5a9c51569c Use dmMemset().
Matti Hamalainen <ccr@tnsp.org>
parents: 723
diff changeset
37 dmMemset(stream, 0, len);
376
40e33ad0d153 Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
38 }
40e33ad0d153 Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
39 else
40e33ad0d153 Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
40 #ifdef DM_USE_JSS
40e33ad0d153 Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
41 {
1738
b4992d9f72fe Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 1170
diff changeset
42 if (engine->jssDev != NULL)
b4992d9f72fe Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 1170
diff changeset
43 jvmRenderAudio(engine->jssDev, stream,
b4992d9f72fe Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 1170
diff changeset
44 len / jvmGetSampleSize(engine->jssDev));
376
40e33ad0d153 Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
45 }
40e33ad0d153 Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
46 #endif
40e33ad0d153 Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
47 #ifdef DM_USE_TREMOR
723
da39c2255aa2 Update to match API changes.
Matti Hamalainen <ccr@tnsp.org>
parents: 651
diff changeset
48 if (engine->audioPos + len >= engine->audioRes->resSize)
376
40e33ad0d153 Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
49 {
40e33ad0d153 Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
50 engine->exitFlag = true;
40e33ad0d153 Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
51 }
40e33ad0d153 Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
52 else
40e33ad0d153 Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
53 {
723
da39c2255aa2 Update to match API changes.
Matti Hamalainen <ccr@tnsp.org>
parents: 651
diff changeset
54 memcpy(stream, (Uint8 *) engine->audioRes->resData + engine->audioPos, len);
376
40e33ad0d153 Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
55 engine->audioPos += len;
40e33ad0d153 Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
56 }
40e33ad0d153 Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
57 #endif
40e33ad0d153 Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
58 }
40e33ad0d153 Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
59
40e33ad0d153 Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
60
40e33ad0d153 Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
61 int DemoEditor::reopenResources()
40e33ad0d153 Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
62 {
40e33ad0d153 Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
63 int err;
40e33ad0d153 Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
64
723
da39c2255aa2 Update to match API changes.
Matti Hamalainen <ccr@tnsp.org>
parents: 651
diff changeset
65 if ((err = dmResourcesInit(
da39c2255aa2 Update to match API changes.
Matti Hamalainen <ccr@tnsp.org>
parents: 651
diff changeset
66 &engine.resources, engine.optPackFilename, engine.optDataPath,
da39c2255aa2 Update to match API changes.
Matti Hamalainen <ccr@tnsp.org>
parents: 651
diff changeset
67 engine.optResFlags, engineClassifier)) != DMERR_OK)
376
40e33ad0d153 Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
68 {
1738
b4992d9f72fe Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 1170
diff changeset
69 dmErrorMsg("Could not initialize resource manager: %d, %s.\n",
376
40e33ad0d153 Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
70 err, dmErrorStr(err));
40e33ad0d153 Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
71 }
40e33ad0d153 Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
72 return err;
40e33ad0d153 Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
73 }
40e33ad0d153 Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
74
40e33ad0d153 Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
75
40e33ad0d153 Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
76 int DemoEditor::loadResources()
40e33ad0d153 Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
77 {
723
da39c2255aa2 Update to match API changes.
Matti Hamalainen <ccr@tnsp.org>
parents: 651
diff changeset
78 int err, loaded = 0, total = 0;
da39c2255aa2 Update to match API changes.
Matti Hamalainen <ccr@tnsp.org>
parents: 651
diff changeset
79 BOOL first = TRUE;
376
40e33ad0d153 Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
80
723
da39c2255aa2 Update to match API changes.
Matti Hamalainen <ccr@tnsp.org>
parents: 651
diff changeset
81 do
376
40e33ad0d153 Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
82 {
723
da39c2255aa2 Update to match API changes.
Matti Hamalainen <ccr@tnsp.org>
parents: 651
diff changeset
83 /*
376
40e33ad0d153 Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
84 // Show a nice progress bar while loading
723
da39c2255aa2 Update to match API changes.
Matti Hamalainen <ccr@tnsp.org>
parents: 651
diff changeset
85 if ((err = engineShowProgress(loaded, total)) != DMERR_OK)
da39c2255aa2 Update to match API changes.
Matti Hamalainen <ccr@tnsp.org>
parents: 651
diff changeset
86 return err;
376
40e33ad0d153 Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
87 */
723
da39c2255aa2 Update to match API changes.
Matti Hamalainen <ccr@tnsp.org>
parents: 651
diff changeset
88 err = dmResourcesPreload(engine.resources, first, &loaded, &total);
da39c2255aa2 Update to match API changes.
Matti Hamalainen <ccr@tnsp.org>
parents: 651
diff changeset
89 first = FALSE;
376
40e33ad0d153 Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
90 }
723
da39c2255aa2 Update to match API changes.
Matti Hamalainen <ccr@tnsp.org>
parents: 651
diff changeset
91 while (err == DMERR_PROGRESS);
376
40e33ad0d153 Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
92 return DMERR_OK;
40e33ad0d153 Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
93 }
40e33ad0d153 Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
94
40e33ad0d153 Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
95
40e33ad0d153 Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
96 DemoEditor::DemoEditor()
40e33ad0d153 Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
97 {
40e33ad0d153 Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
98 int err;
40e33ad0d153 Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
99
40e33ad0d153 Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
100 resize(1024, 768);
40e33ad0d153 Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
101 setWindowTitle(QCoreApplication::applicationName());
40e33ad0d153 Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
102
1170
ef5a9c51569c Use dmMemset().
Matti Hamalainen <ccr@tnsp.org>
parents: 723
diff changeset
103 dmMemset(&engine, 0, sizeof(engine));
378
feaeec4c6c55 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 376
diff changeset
104 initSDL = FALSE;
393
5137db55f00b More work towards the editor ..
Matti Hamalainen <ccr@tnsp.org>
parents: 391
diff changeset
105 currTimeline = NULL;
376
40e33ad0d153 Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
106
40e33ad0d153 Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
107 // Pre-initialization
40e33ad0d153 Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
108 if ((err = demoPreInit(&engine)) != DMERR_OK)
40e33ad0d153 Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
109 goto error_exit;
40e33ad0d153 Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
110
40e33ad0d153 Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
111 // Initialize SDL components
40e33ad0d153 Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
112 dmPrint(1, "Initializing libSDL.\n");
40e33ad0d153 Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
113 if (SDL_Init(SDL_INIT_VIDEO | SDL_INIT_AUDIO | SDL_INIT_TIMER) != 0)
40e33ad0d153 Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
114 {
1738
b4992d9f72fe Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 1170
diff changeset
115 dmErrorMsg("Could not initialize SDL: %s\n", SDL_GetError());
376
40e33ad0d153 Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
116 goto error_exit;
40e33ad0d153 Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
117 }
40e33ad0d153 Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
118 initSDL = true;
40e33ad0d153 Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
119
40e33ad0d153 Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
120 // Initialize audio parts
40e33ad0d153 Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
121 if (engine.optAfmt.freq == 0 && engine.optAfmt.channels == 0)
40e33ad0d153 Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
122 {
40e33ad0d153 Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
123 // Defaults, if none seem to be set
40e33ad0d153 Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
124 engine.optAfmt.freq = 44100;
40e33ad0d153 Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
125 engine.optAfmt.format = AUDIO_S16SYS;
40e33ad0d153 Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
126 engine.optAfmt.channels = 2;
40e33ad0d153 Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
127 engine.optAfmt.samples = engine.optAfmt.freq / 16;
40e33ad0d153 Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
128 }
40e33ad0d153 Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
129
40e33ad0d153 Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
130 #ifdef DM_USE_JSS
40e33ad0d153 Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
131 jssInit();
40e33ad0d153 Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
132
40e33ad0d153 Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
133 switch (engine.optAfmt.format)
40e33ad0d153 Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
134 {
40e33ad0d153 Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
135 case AUDIO_S16SYS:
1738
b4992d9f72fe Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 1170
diff changeset
136 engine.jssFormat = JSS_AUDIO_S16;
376
40e33ad0d153 Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
137 break;
40e33ad0d153 Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
138 case AUDIO_U16SYS:
1738
b4992d9f72fe Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 1170
diff changeset
139 engine.jssFormat = JSS_AUDIO_U16;
376
40e33ad0d153 Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
140 break;
40e33ad0d153 Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
141 case AUDIO_S8:
1738
b4992d9f72fe Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 1170
diff changeset
142 engine.jssFormat = JSS_AUDIO_S8;
376
40e33ad0d153 Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
143 break;
40e33ad0d153 Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
144 case AUDIO_U8:
1738
b4992d9f72fe Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 1170
diff changeset
145 engine.jssFormat = JSS_AUDIO_U8;
376
40e33ad0d153 Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
146 break;
40e33ad0d153 Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
147 }
40e33ad0d153 Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
148
40e33ad0d153 Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
149 dmPrint(1, "Initializing miniJSS mixer with fmt=%d, chn=%d, freq=%d\n",
1738
b4992d9f72fe Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 1170
diff changeset
150 engine.jssFormat, engine.optAfmt.channels, engine.optAfmt.freq);
376
40e33ad0d153 Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
151
1738
b4992d9f72fe Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 1170
diff changeset
152 if ((engine.jssDev =
b4992d9f72fe Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 1170
diff changeset
153 jvmInit(engine.jssFormat, engine.optAfmt.channels,
376
40e33ad0d153 Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
154 engine.optAfmt.freq, JMIX_AUTO)) == NULL)
40e33ad0d153 Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
155 {
1738
b4992d9f72fe Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 1170
diff changeset
156 dmErrorMsg("jvmInit() returned NULL, voi perkele.\n");
376
40e33ad0d153 Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
157 goto error_exit;
40e33ad0d153 Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
158 }
40e33ad0d153 Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
159
1738
b4992d9f72fe Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 1170
diff changeset
160 if ((engine.jssPlr = jmpInit(engine.jssDev)) == NULL)
376
40e33ad0d153 Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
161 {
1738
b4992d9f72fe Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 1170
diff changeset
162 dmErrorMsg("jmpInit() returned NULL\n");
376
40e33ad0d153 Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
163 goto error_exit;
40e33ad0d153 Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
164 }
40e33ad0d153 Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
165 #endif
40e33ad0d153 Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
166
40e33ad0d153 Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
167 // Initialize SDL audio
40e33ad0d153 Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
168 dmPrint(1, "Trying to init SDL audio with: fmt=%d, chn=%d, freq=%d\n",
40e33ad0d153 Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
169 engine.optAfmt.format, engine.optAfmt.channels,
40e33ad0d153 Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
170 engine.optAfmt.freq);
40e33ad0d153 Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
171
40e33ad0d153 Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
172 engine.optAfmt.callback = engineAudioCallback;
40e33ad0d153 Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
173
40e33ad0d153 Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
174 if (SDL_OpenAudio(&engine.optAfmt, NULL) < 0)
40e33ad0d153 Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
175 {
1738
b4992d9f72fe Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 1170
diff changeset
176 dmErrorMsg("Couldn't open SDL audio: %s\n", SDL_GetError());
376
40e33ad0d153 Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
177 goto error_exit;
40e33ad0d153 Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
178 }
40e33ad0d153 Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
179
40e33ad0d153 Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
180 // Initialize SDL video
40e33ad0d153 Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
181 if (engine.demoInitPreVideo != NULL &&
40e33ad0d153 Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
182 (err = engine.demoInitPreVideo(&engine)) != DMERR_OK)
40e33ad0d153 Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
183 {
1738
b4992d9f72fe Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 1170
diff changeset
184 dmErrorMsg("demoInitPreVideo() failed, %d: %s\n", err, dmErrorStr(err));
376
40e33ad0d153 Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
185 goto error_exit;
40e33ad0d153 Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
186 }
40e33ad0d153 Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
187
40e33ad0d153 Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
188 dmPrint(1, "Initializing SDL video %d x %d x %dbpp, flags=0x%08x\n",
594
935b91d0f508 Fix some renamed variables in editor code side.
Matti Hamalainen <ccr@tnsp.org>
parents: 403
diff changeset
189 engine.optVidWidth, engine.optVidHeight, engine.optVidDepth, engine.optVFlags);
376
40e33ad0d153 Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
190
594
935b91d0f508 Fix some renamed variables in editor code side.
Matti Hamalainen <ccr@tnsp.org>
parents: 403
diff changeset
191 engine.screen = SDL_CreateRGBSurface(SDL_SWSURFACE, engine.optVidWidth, engine.optVidHeight, engine.optVidDepth, 0, 0, 0, 0);
376
40e33ad0d153 Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
192 if (engine.screen == NULL)
40e33ad0d153 Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
193 {
1738
b4992d9f72fe Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 1170
diff changeset
194 dmErrorMsg("Could not allocate video backbuffer surface.\n");
376
40e33ad0d153 Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
195 goto error_exit;
40e33ad0d153 Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
196 }
40e33ad0d153 Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
197
40e33ad0d153 Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
198 if (engine.demoInitPostVideo != NULL &&
40e33ad0d153 Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
199 (err = engine.demoInitPostVideo(&engine)) != DMERR_OK)
40e33ad0d153 Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
200 {
1738
b4992d9f72fe Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 1170
diff changeset
201 dmErrorMsg("demoInitPostVideo() failed, %d: %s\n", err, dmErrorStr(err));
376
40e33ad0d153 Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
202 goto error_exit;
40e33ad0d153 Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
203 }
40e33ad0d153 Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
204
40e33ad0d153 Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
205
40e33ad0d153 Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
206 error_exit:
40e33ad0d153 Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
207
40e33ad0d153 Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
208 // Setup GUI elements
40e33ad0d153 Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
209 createMainGUI();
402
0f290af63fc1 Timeline event drawing prototype works.
Matti Hamalainen <ccr@tnsp.org>
parents: 401
diff changeset
210 createNewFile();
397
9993873ff655 More work towards editor.
Matti Hamalainen <ccr@tnsp.org>
parents: 394
diff changeset
211 timelineView->setTimeline(currTimeline);
376
40e33ad0d153 Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
212 settingsRestore();
384
e5220ff48bc8 Slowly working on the editor.
Matti Hamalainen <ccr@tnsp.org>
parents: 379
diff changeset
213 initEffectsAndResources();
376
40e33ad0d153 Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
214 statusMsg("Application started.");
40e33ad0d153 Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
215 }
40e33ad0d153 Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
216
40e33ad0d153 Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
217
40e33ad0d153 Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
218 DemoEditor::~DemoEditor()
40e33ad0d153 Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
219 {
384
e5220ff48bc8 Slowly working on the editor.
Matti Hamalainen <ccr@tnsp.org>
parents: 379
diff changeset
220 statusMsg("Shutting down.");
376
40e33ad0d153 Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
221
40e33ad0d153 Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
222 settingsSave();
384
e5220ff48bc8 Slowly working on the editor.
Matti Hamalainen <ccr@tnsp.org>
parents: 379
diff changeset
223 delete demoView;
376
40e33ad0d153 Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
224 historyReset();
40e33ad0d153 Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
225
40e33ad0d153 Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
226 if (engine.screen)
40e33ad0d153 Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
227 SDL_FreeSurface(engine.screen);
40e33ad0d153 Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
228
40e33ad0d153 Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
229 SDL_LockAudio();
40e33ad0d153 Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
230 SDL_PauseAudio(1);
40e33ad0d153 Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
231 #ifdef DM_USE_JSS
1738
b4992d9f72fe Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 1170
diff changeset
232 jmpClose(engine.jssPlr);
b4992d9f72fe Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 1170
diff changeset
233 jvmClose(engine.jssDev);
376
40e33ad0d153 Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
234 jssClose();
40e33ad0d153 Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
235 #endif
40e33ad0d153 Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
236 SDL_UnlockAudio();
40e33ad0d153 Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
237
378
feaeec4c6c55 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 376
diff changeset
238 shutdownEffectsAndResources();
feaeec4c6c55 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 376
diff changeset
239
feaeec4c6c55 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 376
diff changeset
240 if (initSDL)
feaeec4c6c55 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 376
diff changeset
241 SDL_Quit();
feaeec4c6c55 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 376
diff changeset
242 }
feaeec4c6c55 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 376
diff changeset
243
feaeec4c6c55 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 376
diff changeset
244
400
f44a89a25c97 Fix waveform display from going over buffer limit.
Matti Hamalainen <ccr@tnsp.org>
parents: 398
diff changeset
245 int DemoEditor::getTimelineDuration()
391
28a74940f2b6 More work on the editor.
Matti Hamalainen <ccr@tnsp.org>
parents: 384
diff changeset
246 {
28a74940f2b6 More work on the editor.
Matti Hamalainen <ccr@tnsp.org>
parents: 384
diff changeset
247 return timelineAudioTrack->getDuration();
28a74940f2b6 More work on the editor.
Matti Hamalainen <ccr@tnsp.org>
parents: 384
diff changeset
248 }
28a74940f2b6 More work on the editor.
Matti Hamalainen <ccr@tnsp.org>
parents: 384
diff changeset
249
28a74940f2b6 More work on the editor.
Matti Hamalainen <ccr@tnsp.org>
parents: 384
diff changeset
250
403
d34922e6a244 Even more work towards the editor.
Matti Hamalainen <ccr@tnsp.org>
parents: 402
diff changeset
251 void DemoEditor::updateResourceView()
d34922e6a244 Even more work towards the editor.
Matti Hamalainen <ccr@tnsp.org>
parents: 402
diff changeset
252 {
d34922e6a244 Even more work towards the editor.
Matti Hamalainen <ccr@tnsp.org>
parents: 402
diff changeset
253 }
d34922e6a244 Even more work towards the editor.
Matti Hamalainen <ccr@tnsp.org>
parents: 402
diff changeset
254
d34922e6a244 Even more work towards the editor.
Matti Hamalainen <ccr@tnsp.org>
parents: 402
diff changeset
255
384
e5220ff48bc8 Slowly working on the editor.
Matti Hamalainen <ccr@tnsp.org>
parents: 379
diff changeset
256 void DemoEditor::updateTimelineView()
e5220ff48bc8 Slowly working on the editor.
Matti Hamalainen <ccr@tnsp.org>
parents: 379
diff changeset
257 {
393
5137db55f00b More work towards the editor ..
Matti Hamalainen <ccr@tnsp.org>
parents: 391
diff changeset
258 demoView->setEngineData(&engine);
5137db55f00b More work towards the editor ..
Matti Hamalainen <ccr@tnsp.org>
parents: 391
diff changeset
259
397
9993873ff655 More work towards editor.
Matti Hamalainen <ccr@tnsp.org>
parents: 394
diff changeset
260 if (engine.audioRes != NULL)
9993873ff655 More work towards editor.
Matti Hamalainen <ccr@tnsp.org>
parents: 394
diff changeset
261 {
9993873ff655 More work towards editor.
Matti Hamalainen <ccr@tnsp.org>
parents: 394
diff changeset
262 timelineAudioTrack->setWaveform(
723
da39c2255aa2 Update to match API changes.
Matti Hamalainen <ccr@tnsp.org>
parents: 651
diff changeset
263 engine.audioRes->resData, engine.audioRes->resSize,
397
9993873ff655 More work towards editor.
Matti Hamalainen <ccr@tnsp.org>
parents: 394
diff changeset
264 engine.optAfmt.format, engine.optAfmt.channels,
9993873ff655 More work towards editor.
Matti Hamalainen <ccr@tnsp.org>
parents: 394
diff changeset
265 engine.optAfmt.freq);
9993873ff655 More work towards editor.
Matti Hamalainen <ccr@tnsp.org>
parents: 394
diff changeset
266 }
393
5137db55f00b More work towards the editor ..
Matti Hamalainen <ccr@tnsp.org>
parents: 391
diff changeset
267
391
28a74940f2b6 More work on the editor.
Matti Hamalainen <ccr@tnsp.org>
parents: 384
diff changeset
268 timelineAudioTrack->setOffset(currViewOffset);
28a74940f2b6 More work on the editor.
Matti Hamalainen <ccr@tnsp.org>
parents: 384
diff changeset
269 timelineAudioTrack->setScale(currViewScale);
393
5137db55f00b More work towards the editor ..
Matti Hamalainen <ccr@tnsp.org>
parents: 391
diff changeset
270
5137db55f00b More work towards the editor ..
Matti Hamalainen <ccr@tnsp.org>
parents: 391
diff changeset
271
5137db55f00b More work towards the editor ..
Matti Hamalainen <ccr@tnsp.org>
parents: 391
diff changeset
272 timelineView->setTime(currFrameTime);
5137db55f00b More work towards the editor ..
Matti Hamalainen <ccr@tnsp.org>
parents: 391
diff changeset
273 timelineView->setOffset(currViewOffset);
5137db55f00b More work towards the editor ..
Matti Hamalainen <ccr@tnsp.org>
parents: 391
diff changeset
274 timelineView->setScale(currViewScale);
391
28a74940f2b6 More work on the editor.
Matti Hamalainen <ccr@tnsp.org>
parents: 384
diff changeset
275
400
f44a89a25c97 Fix waveform display from going over buffer limit.
Matti Hamalainen <ccr@tnsp.org>
parents: 398
diff changeset
276 timelineScrollBar->setRange(0, getTimelineDuration());
391
28a74940f2b6 More work on the editor.
Matti Hamalainen <ccr@tnsp.org>
parents: 384
diff changeset
277 timelineScrollBar->setValue(currViewOffset);
28a74940f2b6 More work on the editor.
Matti Hamalainen <ccr@tnsp.org>
parents: 384
diff changeset
278 }
28a74940f2b6 More work on the editor.
Matti Hamalainen <ccr@tnsp.org>
parents: 384
diff changeset
279
28a74940f2b6 More work on the editor.
Matti Hamalainen <ccr@tnsp.org>
parents: 384
diff changeset
280
28a74940f2b6 More work on the editor.
Matti Hamalainen <ccr@tnsp.org>
parents: 384
diff changeset
281 void DemoEditor::actionTimelineScrollChanged(int value)
28a74940f2b6 More work on the editor.
Matti Hamalainen <ccr@tnsp.org>
parents: 384
diff changeset
282 {
28a74940f2b6 More work on the editor.
Matti Hamalainen <ccr@tnsp.org>
parents: 384
diff changeset
283 currViewOffset = value;
28a74940f2b6 More work on the editor.
Matti Hamalainen <ccr@tnsp.org>
parents: 384
diff changeset
284 updateTimelineView();
28a74940f2b6 More work on the editor.
Matti Hamalainen <ccr@tnsp.org>
parents: 384
diff changeset
285 }
28a74940f2b6 More work on the editor.
Matti Hamalainen <ccr@tnsp.org>
parents: 384
diff changeset
286
28a74940f2b6 More work on the editor.
Matti Hamalainen <ccr@tnsp.org>
parents: 384
diff changeset
287
28a74940f2b6 More work on the editor.
Matti Hamalainen <ccr@tnsp.org>
parents: 384
diff changeset
288 void DemoEditor::actionOffsetChanged(float value)
28a74940f2b6 More work on the editor.
Matti Hamalainen <ccr@tnsp.org>
parents: 384
diff changeset
289 {
28a74940f2b6 More work on the editor.
Matti Hamalainen <ccr@tnsp.org>
parents: 384
diff changeset
290 currViewOffset = value;
28a74940f2b6 More work on the editor.
Matti Hamalainen <ccr@tnsp.org>
parents: 384
diff changeset
291 updateTimelineView();
28a74940f2b6 More work on the editor.
Matti Hamalainen <ccr@tnsp.org>
parents: 384
diff changeset
292 }
28a74940f2b6 More work on the editor.
Matti Hamalainen <ccr@tnsp.org>
parents: 384
diff changeset
293
28a74940f2b6 More work on the editor.
Matti Hamalainen <ccr@tnsp.org>
parents: 384
diff changeset
294
28a74940f2b6 More work on the editor.
Matti Hamalainen <ccr@tnsp.org>
parents: 384
diff changeset
295 void DemoEditor::actionTimeChanged(float value)
28a74940f2b6 More work on the editor.
Matti Hamalainen <ccr@tnsp.org>
parents: 384
diff changeset
296 {
28a74940f2b6 More work on the editor.
Matti Hamalainen <ccr@tnsp.org>
parents: 384
diff changeset
297 currFrameTime = value;
28a74940f2b6 More work on the editor.
Matti Hamalainen <ccr@tnsp.org>
parents: 384
diff changeset
298 updateTimelineView();
384
e5220ff48bc8 Slowly working on the editor.
Matti Hamalainen <ccr@tnsp.org>
parents: 379
diff changeset
299 }
e5220ff48bc8 Slowly working on the editor.
Matti Hamalainen <ccr@tnsp.org>
parents: 379
diff changeset
300
e5220ff48bc8 Slowly working on the editor.
Matti Hamalainen <ccr@tnsp.org>
parents: 379
diff changeset
301
397
9993873ff655 More work towards editor.
Matti Hamalainen <ccr@tnsp.org>
parents: 394
diff changeset
302 void DemoEditor::actionTimelineChanged()
9993873ff655 More work towards editor.
Matti Hamalainen <ccr@tnsp.org>
parents: 394
diff changeset
303 {
9993873ff655 More work towards editor.
Matti Hamalainen <ccr@tnsp.org>
parents: 394
diff changeset
304 updateMenuStates();
9993873ff655 More work towards editor.
Matti Hamalainen <ccr@tnsp.org>
parents: 394
diff changeset
305 update();
9993873ff655 More work towards editor.
Matti Hamalainen <ccr@tnsp.org>
parents: 394
diff changeset
306 }
9993873ff655 More work towards editor.
Matti Hamalainen <ccr@tnsp.org>
parents: 394
diff changeset
307
9993873ff655 More work towards editor.
Matti Hamalainen <ccr@tnsp.org>
parents: 394
diff changeset
308
378
feaeec4c6c55 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 376
diff changeset
309 int DemoEditor::initEffectsAndResources()
feaeec4c6c55 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 376
diff changeset
310 {
feaeec4c6c55 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 376
diff changeset
311 int err;
feaeec4c6c55 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 376
diff changeset
312
391
28a74940f2b6 More work on the editor.
Matti Hamalainen <ccr@tnsp.org>
parents: 384
diff changeset
313 currViewOffset = 0;
28a74940f2b6 More work on the editor.
Matti Hamalainen <ccr@tnsp.org>
parents: 384
diff changeset
314 currFrameTime = 0;
28a74940f2b6 More work on the editor.
Matti Hamalainen <ccr@tnsp.org>
parents: 384
diff changeset
315 currViewScale = 1.0f;
28a74940f2b6 More work on the editor.
Matti Hamalainen <ccr@tnsp.org>
parents: 384
diff changeset
316
378
feaeec4c6c55 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 376
diff changeset
317 // Initialize resource subsystem
384
e5220ff48bc8 Slowly working on the editor.
Matti Hamalainen <ccr@tnsp.org>
parents: 379
diff changeset
318 statusMsg("Initializing resources subsystem.");
378
feaeec4c6c55 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 376
diff changeset
319 if ((err = reopenResources()) != DMERR_OK)
feaeec4c6c55 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 376
diff changeset
320 return err;
feaeec4c6c55 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 376
diff changeset
321
feaeec4c6c55 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 376
diff changeset
322 // Load resources
384
e5220ff48bc8 Slowly working on the editor.
Matti Hamalainen <ccr@tnsp.org>
parents: 379
diff changeset
323 statusMsg("Loading resources, please wait...");
378
feaeec4c6c55 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 376
diff changeset
324 if ((err = loadResources()) != DMERR_OK)
feaeec4c6c55 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 376
diff changeset
325 {
1738
b4992d9f72fe Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 1170
diff changeset
326 dmErrorMsg("Error loading resources, %d: %s.\n", err, dmErrorStr(err));
378
feaeec4c6c55 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 376
diff changeset
327 return err;
feaeec4c6c55 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 376
diff changeset
328 }
feaeec4c6c55 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 376
diff changeset
329
feaeec4c6c55 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 376
diff changeset
330
feaeec4c6c55 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 376
diff changeset
331 // Final initializations
384
e5220ff48bc8 Slowly working on the editor.
Matti Hamalainen <ccr@tnsp.org>
parents: 379
diff changeset
332 statusMsg("Initializing custom demo data.");
378
feaeec4c6c55 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 376
diff changeset
333 if ((err = engine.demoInit(&engine)) != DMERR_OK)
feaeec4c6c55 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 376
diff changeset
334 {
1738
b4992d9f72fe Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 1170
diff changeset
335 dmErrorMsg("Failure in demoInit(), %d: %s\n",
378
feaeec4c6c55 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 376
diff changeset
336 err, dmErrorStr(err));
feaeec4c6c55 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 376
diff changeset
337 return err;
feaeec4c6c55 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 376
diff changeset
338 }
feaeec4c6c55 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 376
diff changeset
339
feaeec4c6c55 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 376
diff changeset
340 // Initialize effects
384
e5220ff48bc8 Slowly working on the editor.
Matti Hamalainen <ccr@tnsp.org>
parents: 379
diff changeset
341 statusMsg("Initializing effects ...");
378
feaeec4c6c55 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 376
diff changeset
342 if ((err = engineInitializeEffects(&engine)) != DMERR_OK)
feaeec4c6c55 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 376
diff changeset
343 {
1738
b4992d9f72fe Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 1170
diff changeset
344 dmErrorMsg("Effects initialization failed, %d: %s\n",
378
feaeec4c6c55 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 376
diff changeset
345 err, dmErrorStr(err));
feaeec4c6c55 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 376
diff changeset
346 return err;
feaeec4c6c55 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 376
diff changeset
347 }
feaeec4c6c55 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 376
diff changeset
348
384
e5220ff48bc8 Slowly working on the editor.
Matti Hamalainen <ccr@tnsp.org>
parents: 379
diff changeset
349 // Etc.
403
d34922e6a244 Even more work towards the editor.
Matti Hamalainen <ccr@tnsp.org>
parents: 402
diff changeset
350 rehash();
378
feaeec4c6c55 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 376
diff changeset
351 return DMERR_OK;
feaeec4c6c55 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 376
diff changeset
352 }
feaeec4c6c55 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 376
diff changeset
353
feaeec4c6c55 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 376
diff changeset
354
feaeec4c6c55 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 376
diff changeset
355 void DemoEditor::shutdownEffectsAndResources()
feaeec4c6c55 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 376
diff changeset
356 {
397
9993873ff655 More work towards editor.
Matti Hamalainen <ccr@tnsp.org>
parents: 394
diff changeset
357 delete currTimeline;
376
40e33ad0d153 Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
358 dmFreePreparedTimelineData(engine.ptl);
40e33ad0d153 Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
359 engineShutdownEffects(&engine);
723
da39c2255aa2 Update to match API changes.
Matti Hamalainen <ccr@tnsp.org>
parents: 651
diff changeset
360 dmResourcesClose(engine.resources);
376
40e33ad0d153 Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
361
40e33ad0d153 Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
362 if (engine.demoShutdown != NULL)
40e33ad0d153 Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
363 engine.demoShutdown(&engine);
40e33ad0d153 Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
364 }
40e33ad0d153 Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
365
40e33ad0d153 Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
366
403
d34922e6a244 Even more work towards the editor.
Matti Hamalainen <ccr@tnsp.org>
parents: 402
diff changeset
367 void DemoEditor::rehash()
d34922e6a244 Even more work towards the editor.
Matti Hamalainen <ccr@tnsp.org>
parents: 402
diff changeset
368 {
d34922e6a244 Even more work towards the editor.
Matti Hamalainen <ccr@tnsp.org>
parents: 402
diff changeset
369 timelineView->setTimeline(currTimeline);
d34922e6a244 Even more work towards the editor.
Matti Hamalainen <ccr@tnsp.org>
parents: 402
diff changeset
370 updateResourceView();
d34922e6a244 Even more work towards the editor.
Matti Hamalainen <ccr@tnsp.org>
parents: 402
diff changeset
371 updateTimelineView();
d34922e6a244 Even more work towards the editor.
Matti Hamalainen <ccr@tnsp.org>
parents: 402
diff changeset
372 updateMenuStates();
d34922e6a244 Even more work towards the editor.
Matti Hamalainen <ccr@tnsp.org>
parents: 402
diff changeset
373 update();
d34922e6a244 Even more work towards the editor.
Matti Hamalainen <ccr@tnsp.org>
parents: 402
diff changeset
374 }
d34922e6a244 Even more work towards the editor.
Matti Hamalainen <ccr@tnsp.org>
parents: 402
diff changeset
375
d34922e6a244 Even more work towards the editor.
Matti Hamalainen <ccr@tnsp.org>
parents: 402
diff changeset
376
378
feaeec4c6c55 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 376
diff changeset
377 void DemoEditor::createNewFile()
376
40e33ad0d153 Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
378 {
394
412082d5babc Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 393
diff changeset
379 delete currTimeline;
403
d34922e6a244 Even more work towards the editor.
Matti Hamalainen <ccr@tnsp.org>
parents: 402
diff changeset
380 currTimeline = new EDTimelineObject();
378
feaeec4c6c55 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 376
diff changeset
381
402
0f290af63fc1 Timeline event drawing prototype works.
Matti Hamalainen <ccr@tnsp.org>
parents: 401
diff changeset
382 DMTimelineTrack *tr;
0f290af63fc1 Timeline event drawing prototype works.
Matti Hamalainen <ccr@tnsp.org>
parents: 401
diff changeset
383 dmTimelineAddTrack(currTimeline->tl, &tr, "Penis");
0f290af63fc1 Timeline event drawing prototype works.
Matti Hamalainen <ccr@tnsp.org>
parents: 401
diff changeset
384
0f290af63fc1 Timeline event drawing prototype works.
Matti Hamalainen <ccr@tnsp.org>
parents: 401
diff changeset
385 DMTimelineEvent *ev;
0f290af63fc1 Timeline event drawing prototype works.
Matti Hamalainen <ccr@tnsp.org>
parents: 401
diff changeset
386 dmTimelineTrackAddEvent(tr, 500, 100, &ev);
0f290af63fc1 Timeline event drawing prototype works.
Matti Hamalainen <ccr@tnsp.org>
parents: 401
diff changeset
387
0f290af63fc1 Timeline event drawing prototype works.
Matti Hamalainen <ccr@tnsp.org>
parents: 401
diff changeset
388 dmTimelineEventSetEffectByIndex(ev, 0);
0f290af63fc1 Timeline event drawing prototype works.
Matti Hamalainen <ccr@tnsp.org>
parents: 401
diff changeset
389
376
40e33ad0d153 Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
390 historyReset();
40e33ad0d153 Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
391 updateMenuStates();
403
d34922e6a244 Even more work towards the editor.
Matti Hamalainen <ccr@tnsp.org>
parents: 402
diff changeset
392 update();
376
40e33ad0d153 Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
393 }
40e33ad0d153 Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
394
40e33ad0d153 Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
395
40e33ad0d153 Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
396 void DemoEditor::readFromFile(QString filename)
40e33ad0d153 Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
397 {
403
d34922e6a244 Even more work towards the editor.
Matti Hamalainen <ccr@tnsp.org>
parents: 402
diff changeset
398 EDTimelineObject *tmp = new EDTimelineObject();
376
40e33ad0d153 Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
399 int ret = tmp->load(filename);
40e33ad0d153 Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
400 if (ret != DMERR_OK)
40e33ad0d153 Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
401 {
378
feaeec4c6c55 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 376
diff changeset
402 showFileErrorDialog("Loading demo blob file "+ filename, ret);
376
40e33ad0d153 Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
403 delete tmp;
40e33ad0d153 Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
404 }
40e33ad0d153 Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
405 else
40e33ad0d153 Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
406 {
397
9993873ff655 More work towards editor.
Matti Hamalainen <ccr@tnsp.org>
parents: 394
diff changeset
407 delete currTimeline;
9993873ff655 More work towards editor.
Matti Hamalainen <ccr@tnsp.org>
parents: 394
diff changeset
408 currTimeline = tmp;
403
d34922e6a244 Even more work towards the editor.
Matti Hamalainen <ccr@tnsp.org>
parents: 402
diff changeset
409 rehash();
376
40e33ad0d153 Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
410 }
40e33ad0d153 Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
411 }
40e33ad0d153 Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
412
40e33ad0d153 Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
413
40e33ad0d153 Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
414 void DemoEditor::saveToFile(QString filename)
40e33ad0d153 Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
415 {
397
9993873ff655 More work towards editor.
Matti Hamalainen <ccr@tnsp.org>
parents: 394
diff changeset
416 int ret = currTimeline->save(filename);
376
40e33ad0d153 Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
417 if (ret != DMERR_OK)
40e33ad0d153 Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
418 {
378
feaeec4c6c55 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 376
diff changeset
419 showFileErrorDialog("Saving demo blob file "+ filename, ret);
376
40e33ad0d153 Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
420 }
40e33ad0d153 Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
421
40e33ad0d153 Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
422 updateMenuStates();
40e33ad0d153 Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
423 }
40e33ad0d153 Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
424
40e33ad0d153 Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
425
40e33ad0d153 Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
426 void DemoEditor::settingsRestore()
40e33ad0d153 Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
427 {
40e33ad0d153 Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
428 QSettings s;
40e33ad0d153 Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
429
40e33ad0d153 Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
430 restoreGeometry(s.value("windowGeometry").toByteArray());
40e33ad0d153 Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
431 restoreState(s.value("windowState").toByteArray());
40e33ad0d153 Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
432 }
40e33ad0d153 Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
433
40e33ad0d153 Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
434
40e33ad0d153 Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
435 void DemoEditor::settingsSave()
40e33ad0d153 Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
436 {
40e33ad0d153 Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
437 QSettings s;
40e33ad0d153 Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
438
40e33ad0d153 Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
439 s.setValue("windowGeometry", saveGeometry());
40e33ad0d153 Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
440 s.setValue("windowState", saveState());
40e33ad0d153 Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
441 }
40e33ad0d153 Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
442
40e33ad0d153 Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
443
40e33ad0d153 Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
444 //
40e33ad0d153 Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
445 // Edit history functionality
40e33ad0d153 Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
446 //
40e33ad0d153 Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
447 void DemoEditor::historyReset()
40e33ad0d153 Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
448 {
401
2fdf440ea66a Fix some segfaults, etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 400
diff changeset
449 if (currTimeline != NULL)
2fdf440ea66a Fix some segfaults, etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 400
diff changeset
450 currTimeline->scrub();
2fdf440ea66a Fix some segfaults, etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 400
diff changeset
451
376
40e33ad0d153 Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
452 undoHistoryPos = -1;
40e33ad0d153 Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
453 undoHistoryMax = DOC_UNDO_MAX;
40e33ad0d153 Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
454 undoHistory.clear();
40e33ad0d153 Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
455 }
40e33ad0d153 Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
456
40e33ad0d153 Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
457
40e33ad0d153 Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
458 void DemoEditor::historyPush(QString description)
40e33ad0d153 Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
459 {
401
2fdf440ea66a Fix some segfaults, etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 400
diff changeset
460 if (currTimeline == NULL)
2fdf440ea66a Fix some segfaults, etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 400
diff changeset
461 return;
2fdf440ea66a Fix some segfaults, etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 400
diff changeset
462
2fdf440ea66a Fix some segfaults, etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 400
diff changeset
463 if (!undoHistory.isEmpty() && undoHistory.last()->state() == "-")
376
40e33ad0d153 Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
464 {
40e33ad0d153 Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
465 delete undoHistory.takeLast();
40e33ad0d153 Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
466 }
40e33ad0d153 Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
467
40e33ad0d153 Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
468 while (undoHistory.size() >= undoHistoryMax)
40e33ad0d153 Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
469 {
40e33ad0d153 Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
470 delete undoHistory.takeFirst();
40e33ad0d153 Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
471 }
40e33ad0d153 Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
472
403
d34922e6a244 Even more work towards the editor.
Matti Hamalainen <ccr@tnsp.org>
parents: 402
diff changeset
473 EDTimelineObject *copy = new EDTimelineObject(currTimeline);
401
2fdf440ea66a Fix some segfaults, etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 400
diff changeset
474 copy->setState(description);
376
40e33ad0d153 Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
475 undoHistory.append(copy);
40e33ad0d153 Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
476 }
40e33ad0d153 Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
477
40e33ad0d153 Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
478
40e33ad0d153 Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
479 void DemoEditor::historyTop()
40e33ad0d153 Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
480 {
401
2fdf440ea66a Fix some segfaults, etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 400
diff changeset
481 if (currTimeline == NULL)
2fdf440ea66a Fix some segfaults, etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 400
diff changeset
482 return;
2fdf440ea66a Fix some segfaults, etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 400
diff changeset
483
403
d34922e6a244 Even more work towards the editor.
Matti Hamalainen <ccr@tnsp.org>
parents: 402
diff changeset
484 EDTimelineObject *copy = new EDTimelineObject(currTimeline);
401
2fdf440ea66a Fix some segfaults, etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 400
diff changeset
485 copy->setState("-");
376
40e33ad0d153 Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
486 undoHistory.append(copy);
40e33ad0d153 Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
487
40e33ad0d153 Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
488 undoHistoryPos = undoHistory.size() - 1;
401
2fdf440ea66a Fix some segfaults, etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 400
diff changeset
489 currTimeline->touch();
403
d34922e6a244 Even more work towards the editor.
Matti Hamalainen <ccr@tnsp.org>
parents: 402
diff changeset
490 updateTimelineView();
376
40e33ad0d153 Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
491 updateMenuStates();
40e33ad0d153 Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
492 update();
40e33ad0d153 Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
493 }
40e33ad0d153 Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
494
40e33ad0d153 Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
495
40e33ad0d153 Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
496 void DemoEditor::historyPop()
40e33ad0d153 Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
497 {
40e33ad0d153 Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
498 if (!undoHistory.isEmpty())
40e33ad0d153 Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
499 {
40e33ad0d153 Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
500 delete undoHistory.takeLast();
40e33ad0d153 Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
501 }
40e33ad0d153 Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
502 }
40e33ad0d153 Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
503
40e33ad0d153 Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
504
40e33ad0d153 Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
505 void DemoEditor::performRedo()
40e33ad0d153 Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
506 {
40e33ad0d153 Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
507 if (undoHistoryPos >= 0 && undoHistoryPos < undoHistory.size() - 1)
40e33ad0d153 Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
508 {
40e33ad0d153 Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
509 undoHistoryPos++;
393
5137db55f00b More work towards the editor ..
Matti Hamalainen <ccr@tnsp.org>
parents: 391
diff changeset
510 delete currTimeline;
403
d34922e6a244 Even more work towards the editor.
Matti Hamalainen <ccr@tnsp.org>
parents: 402
diff changeset
511 currTimeline = new EDTimelineObject(undoHistory.at(undoHistoryPos));
401
2fdf440ea66a Fix some segfaults, etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 400
diff changeset
512 currTimeline->touch();
403
d34922e6a244 Even more work towards the editor.
Matti Hamalainen <ccr@tnsp.org>
parents: 402
diff changeset
513 updateTimelineView();
376
40e33ad0d153 Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
514 updateMenuStates();
40e33ad0d153 Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
515 update();
40e33ad0d153 Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
516 }
40e33ad0d153 Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
517 }
40e33ad0d153 Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
518
40e33ad0d153 Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
519
40e33ad0d153 Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
520 void DemoEditor::performUndo()
40e33ad0d153 Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
521 {
40e33ad0d153 Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
522 if (undoHistoryPos > 0 && undoHistory.size() > 1)
40e33ad0d153 Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
523 {
40e33ad0d153 Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
524 undoHistoryPos--;
393
5137db55f00b More work towards the editor ..
Matti Hamalainen <ccr@tnsp.org>
parents: 391
diff changeset
525 delete currTimeline;
403
d34922e6a244 Even more work towards the editor.
Matti Hamalainen <ccr@tnsp.org>
parents: 402
diff changeset
526 currTimeline = new EDTimelineObject(undoHistory.at(undoHistoryPos));
401
2fdf440ea66a Fix some segfaults, etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 400
diff changeset
527 currTimeline->touch();
403
d34922e6a244 Even more work towards the editor.
Matti Hamalainen <ccr@tnsp.org>
parents: 402
diff changeset
528 updateTimelineView();
376
40e33ad0d153 Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
529 updateMenuStates();
40e33ad0d153 Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
530 update();
40e33ad0d153 Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
531 }
40e33ad0d153 Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
532 }