annotate edmain.cpp @ 409:b529b7e8ff83

Various improvements and cruft cleanups.
author Matti Hamalainen <ccr@tnsp.org>
date Sat, 03 Nov 2012 02:40:07 +0200
parents d34922e6a244
children 935b91d0f508
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 {
40e33ad0d153 Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
37 memset(stream, 0, len);
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 {
40e33ad0d153 Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
42 if (engine->dev != NULL)
40e33ad0d153 Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
43 jvmRenderAudio(engine->dev, stream,
40e33ad0d153 Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
44 len / jvmGetSampleSize(engine->dev));
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
40e33ad0d153 Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
48 if (engine->audioPos + len >= engine->audioRes->rdataSize)
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 {
40e33ad0d153 Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
54 memcpy(stream, (Uint8 *) engine->audioRes->rdata + engine->audioPos, len);
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
40e33ad0d153 Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
65 if ((err = dmres_init(&engine.resources, engine.optPackFilename, engine.optDataPath,
40e33ad0d153 Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
66 engine.optResFlags, engineClassifier)) != DMERR_OK)
40e33ad0d153 Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
67 {
40e33ad0d153 Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
68 dmError("Could not initialize resource manager: %d, %s.\n",
40e33ad0d153 Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
69 err, dmErrorStr(err));
40e33ad0d153 Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
70 }
40e33ad0d153 Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
71 return err;
40e33ad0d153 Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
72 }
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 int DemoEditor::loadResources()
40e33ad0d153 Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
76 {
40e33ad0d153 Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
77 int err, loaded, total;
40e33ad0d153 Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
78 err = dmres_preload(engine.resources, true, &loaded, &total);
40e33ad0d153 Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
79
40e33ad0d153 Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
80 while ((err = dmres_preload(engine.resources, false, &loaded, &total)) == DMERR_PROGRESS)
40e33ad0d153 Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
81 {
40e33ad0d153 Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
82 // Show a nice progress bar while loading
40e33ad0d153 Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
83 if (total > 0 && (loaded % 2) == 0)
40e33ad0d153 Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
84 {
40e33ad0d153 Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
85 /*
40e33ad0d153 Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
86 if ((err = engineShowProgress(loaded, total)) != DMERR_OK)
40e33ad0d153 Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
87 return err;
40e33ad0d153 Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
88 */
40e33ad0d153 Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
89 }
40e33ad0d153 Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
90 }
40e33ad0d153 Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
91 return DMERR_OK;
40e33ad0d153 Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
92 }
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 DemoEditor::DemoEditor()
40e33ad0d153 Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
96 {
40e33ad0d153 Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
97 int err;
40e33ad0d153 Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
98
40e33ad0d153 Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
99 resize(1024, 768);
40e33ad0d153 Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
100 setWindowTitle(QCoreApplication::applicationName());
40e33ad0d153 Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
101
397
9993873ff655 More work towards editor.
Matti Hamalainen <ccr@tnsp.org>
parents: 394
diff changeset
102 memset(&engine, 0, sizeof(engine));
378
feaeec4c6c55 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 376
diff changeset
103 initSDL = FALSE;
393
5137db55f00b More work towards the editor ..
Matti Hamalainen <ccr@tnsp.org>
parents: 391
diff changeset
104 currTimeline = NULL;
376
40e33ad0d153 Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
105
40e33ad0d153 Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
106 // Pre-initialization
40e33ad0d153 Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
107 if ((err = demoPreInit(&engine)) != DMERR_OK)
40e33ad0d153 Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
108 goto error_exit;
40e33ad0d153 Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
109
40e33ad0d153 Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
110 // Initialize SDL components
40e33ad0d153 Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
111 dmPrint(1, "Initializing libSDL.\n");
40e33ad0d153 Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
112 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
113 {
40e33ad0d153 Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
114 dmError("Could not initialize SDL: %s\n", SDL_GetError());
40e33ad0d153 Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
115 goto error_exit;
40e33ad0d153 Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
116 }
40e33ad0d153 Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
117 initSDL = true;
40e33ad0d153 Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
118
40e33ad0d153 Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
119 // Initialize audio parts
40e33ad0d153 Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
120 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
121 {
40e33ad0d153 Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
122 // Defaults, if none seem to be set
40e33ad0d153 Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
123 engine.optAfmt.freq = 44100;
40e33ad0d153 Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
124 engine.optAfmt.format = AUDIO_S16SYS;
40e33ad0d153 Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
125 engine.optAfmt.channels = 2;
40e33ad0d153 Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
126 engine.optAfmt.samples = engine.optAfmt.freq / 16;
40e33ad0d153 Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
127 }
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 #ifdef DM_USE_JSS
40e33ad0d153 Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
130 jssInit();
40e33ad0d153 Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
131
40e33ad0d153 Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
132 switch (engine.optAfmt.format)
40e33ad0d153 Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
133 {
40e33ad0d153 Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
134 case AUDIO_S16SYS:
40e33ad0d153 Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
135 engine.jss_format = JSS_AUDIO_S16;
40e33ad0d153 Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
136 break;
40e33ad0d153 Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
137 case AUDIO_U16SYS:
40e33ad0d153 Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
138 engine.jss_format = JSS_AUDIO_U16;
40e33ad0d153 Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
139 break;
40e33ad0d153 Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
140 case AUDIO_S8:
40e33ad0d153 Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
141 engine.jss_format = JSS_AUDIO_S8;
40e33ad0d153 Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
142 break;
40e33ad0d153 Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
143 case AUDIO_U8:
40e33ad0d153 Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
144 engine.jss_format = JSS_AUDIO_U8;
40e33ad0d153 Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
145 break;
40e33ad0d153 Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
146 }
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 dmPrint(1, "Initializing miniJSS mixer with fmt=%d, chn=%d, freq=%d\n",
40e33ad0d153 Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
149 engine.jss_format, engine.optAfmt.channels, engine.optAfmt.freq);
40e33ad0d153 Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
150
40e33ad0d153 Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
151 if ((engine.dev =
40e33ad0d153 Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
152 jvmInit(engine.jss_format, engine.optAfmt.channels,
40e33ad0d153 Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
153 engine.optAfmt.freq, JMIX_AUTO)) == NULL)
40e33ad0d153 Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
154 {
40e33ad0d153 Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
155 dmError("jvmInit() returned NULL, voi perkele.\n");
40e33ad0d153 Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
156 goto error_exit;
40e33ad0d153 Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
157 }
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 if ((engine.plr = jmpInit(engine.dev)) == NULL)
40e33ad0d153 Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
160 {
40e33ad0d153 Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
161 dmError("jmpInit() returned NULL\n");
40e33ad0d153 Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
162 goto error_exit;
40e33ad0d153 Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
163 }
40e33ad0d153 Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
164 #endif
40e33ad0d153 Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
165
40e33ad0d153 Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
166 // Initialize SDL audio
40e33ad0d153 Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
167 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
168 engine.optAfmt.format, engine.optAfmt.channels,
40e33ad0d153 Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
169 engine.optAfmt.freq);
40e33ad0d153 Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
170
40e33ad0d153 Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
171 engine.optAfmt.callback = engineAudioCallback;
40e33ad0d153 Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
172
40e33ad0d153 Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
173 if (SDL_OpenAudio(&engine.optAfmt, NULL) < 0)
40e33ad0d153 Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
174 {
40e33ad0d153 Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
175 dmError("Couldn't open SDL audio: %s\n", SDL_GetError());
40e33ad0d153 Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
176 goto error_exit;
40e33ad0d153 Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
177 }
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 // Initialize SDL video
40e33ad0d153 Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
180 if (engine.demoInitPreVideo != NULL &&
40e33ad0d153 Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
181 (err = engine.demoInitPreVideo(&engine)) != DMERR_OK)
40e33ad0d153 Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
182 {
40e33ad0d153 Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
183 dmError("demoInitPreVideo() failed, %d: %s\n", err, dmErrorStr(err));
40e33ad0d153 Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
184 goto error_exit;
40e33ad0d153 Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
185 }
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 dmPrint(1, "Initializing SDL video %d x %d x %dbpp, flags=0x%08x\n",
40e33ad0d153 Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
188 engine.optScrWidth, engine.optScrHeight, engine.optBitDepth, engine.optVFlags);
40e33ad0d153 Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
189
40e33ad0d153 Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
190 engine.screen = SDL_CreateRGBSurface(SDL_SWSURFACE, engine.optScrWidth, engine.optScrHeight, engine.optBitDepth, 0, 0, 0, 0);
40e33ad0d153 Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
191 if (engine.screen == NULL)
40e33ad0d153 Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
192 {
40e33ad0d153 Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
193 dmError("Could not allocate video backbuffer surface.\n");
40e33ad0d153 Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
194 goto error_exit;
40e33ad0d153 Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
195 }
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 if (engine.demoInitPostVideo != NULL &&
40e33ad0d153 Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
198 (err = engine.demoInitPostVideo(&engine)) != DMERR_OK)
40e33ad0d153 Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
199 {
40e33ad0d153 Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
200 dmError("demoInitPostVideo() failed, %d: %s\n", err, dmErrorStr(err));
40e33ad0d153 Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
201 goto error_exit;
40e33ad0d153 Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
202 }
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 error_exit:
40e33ad0d153 Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
206
40e33ad0d153 Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
207 // Setup GUI elements
40e33ad0d153 Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
208 createMainGUI();
402
0f290af63fc1 Timeline event drawing prototype works.
Matti Hamalainen <ccr@tnsp.org>
parents: 401
diff changeset
209 createNewFile();
397
9993873ff655 More work towards editor.
Matti Hamalainen <ccr@tnsp.org>
parents: 394
diff changeset
210 timelineView->setTimeline(currTimeline);
376
40e33ad0d153 Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
211 settingsRestore();
384
e5220ff48bc8 Slowly working on the editor.
Matti Hamalainen <ccr@tnsp.org>
parents: 379
diff changeset
212 initEffectsAndResources();
376
40e33ad0d153 Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
213 statusMsg("Application started.");
40e33ad0d153 Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
214 }
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 DemoEditor::~DemoEditor()
40e33ad0d153 Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
218 {
384
e5220ff48bc8 Slowly working on the editor.
Matti Hamalainen <ccr@tnsp.org>
parents: 379
diff changeset
219 statusMsg("Shutting down.");
376
40e33ad0d153 Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
220
40e33ad0d153 Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
221 settingsSave();
384
e5220ff48bc8 Slowly working on the editor.
Matti Hamalainen <ccr@tnsp.org>
parents: 379
diff changeset
222 delete demoView;
376
40e33ad0d153 Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
223 historyReset();
40e33ad0d153 Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
224
40e33ad0d153 Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
225 if (engine.screen)
40e33ad0d153 Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
226 SDL_FreeSurface(engine.screen);
40e33ad0d153 Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
227
40e33ad0d153 Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
228 SDL_LockAudio();
40e33ad0d153 Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
229 SDL_PauseAudio(1);
40e33ad0d153 Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
230 #ifdef DM_USE_JSS
40e33ad0d153 Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
231 jmpClose(engine.plr);
40e33ad0d153 Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
232 jvmClose(engine.dev);
40e33ad0d153 Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
233 jssClose();
40e33ad0d153 Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
234 #endif
40e33ad0d153 Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
235 SDL_UnlockAudio();
40e33ad0d153 Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
236
378
feaeec4c6c55 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 376
diff changeset
237 shutdownEffectsAndResources();
feaeec4c6c55 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 376
diff changeset
238
feaeec4c6c55 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 376
diff changeset
239 if (initSDL)
feaeec4c6c55 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 376
diff changeset
240 SDL_Quit();
feaeec4c6c55 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 376
diff changeset
241 }
feaeec4c6c55 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 376
diff changeset
242
feaeec4c6c55 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 376
diff changeset
243
400
f44a89a25c97 Fix waveform display from going over buffer limit.
Matti Hamalainen <ccr@tnsp.org>
parents: 398
diff changeset
244 int DemoEditor::getTimelineDuration()
391
28a74940f2b6 More work on the editor.
Matti Hamalainen <ccr@tnsp.org>
parents: 384
diff changeset
245 {
28a74940f2b6 More work on the editor.
Matti Hamalainen <ccr@tnsp.org>
parents: 384
diff changeset
246 return timelineAudioTrack->getDuration();
28a74940f2b6 More work on the editor.
Matti Hamalainen <ccr@tnsp.org>
parents: 384
diff changeset
247 }
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
403
d34922e6a244 Even more work towards the editor.
Matti Hamalainen <ccr@tnsp.org>
parents: 402
diff changeset
250 void DemoEditor::updateResourceView()
d34922e6a244 Even more work towards the editor.
Matti Hamalainen <ccr@tnsp.org>
parents: 402
diff changeset
251 {
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
384
e5220ff48bc8 Slowly working on the editor.
Matti Hamalainen <ccr@tnsp.org>
parents: 379
diff changeset
255 void DemoEditor::updateTimelineView()
e5220ff48bc8 Slowly working on the editor.
Matti Hamalainen <ccr@tnsp.org>
parents: 379
diff changeset
256 {
393
5137db55f00b More work towards the editor ..
Matti Hamalainen <ccr@tnsp.org>
parents: 391
diff changeset
257 demoView->setEngineData(&engine);
5137db55f00b More work towards the editor ..
Matti Hamalainen <ccr@tnsp.org>
parents: 391
diff changeset
258
397
9993873ff655 More work towards editor.
Matti Hamalainen <ccr@tnsp.org>
parents: 394
diff changeset
259 if (engine.audioRes != NULL)
9993873ff655 More work towards editor.
Matti Hamalainen <ccr@tnsp.org>
parents: 394
diff changeset
260 {
9993873ff655 More work towards editor.
Matti Hamalainen <ccr@tnsp.org>
parents: 394
diff changeset
261 timelineAudioTrack->setWaveform(
9993873ff655 More work towards editor.
Matti Hamalainen <ccr@tnsp.org>
parents: 394
diff changeset
262 engine.audioRes->rdata, engine.audioRes->rdataSize,
9993873ff655 More work towards editor.
Matti Hamalainen <ccr@tnsp.org>
parents: 394
diff changeset
263 engine.optAfmt.format, engine.optAfmt.channels,
9993873ff655 More work towards editor.
Matti Hamalainen <ccr@tnsp.org>
parents: 394
diff changeset
264 engine.optAfmt.freq);
9993873ff655 More work towards editor.
Matti Hamalainen <ccr@tnsp.org>
parents: 394
diff changeset
265 }
393
5137db55f00b More work towards the editor ..
Matti Hamalainen <ccr@tnsp.org>
parents: 391
diff changeset
266
391
28a74940f2b6 More work on the editor.
Matti Hamalainen <ccr@tnsp.org>
parents: 384
diff changeset
267 timelineAudioTrack->setOffset(currViewOffset);
28a74940f2b6 More work on the editor.
Matti Hamalainen <ccr@tnsp.org>
parents: 384
diff changeset
268 timelineAudioTrack->setScale(currViewScale);
393
5137db55f00b More work towards the editor ..
Matti Hamalainen <ccr@tnsp.org>
parents: 391
diff changeset
269
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 timelineView->setTime(currFrameTime);
5137db55f00b More work towards the editor ..
Matti Hamalainen <ccr@tnsp.org>
parents: 391
diff changeset
272 timelineView->setOffset(currViewOffset);
5137db55f00b More work towards the editor ..
Matti Hamalainen <ccr@tnsp.org>
parents: 391
diff changeset
273 timelineView->setScale(currViewScale);
391
28a74940f2b6 More work on the editor.
Matti Hamalainen <ccr@tnsp.org>
parents: 384
diff changeset
274
400
f44a89a25c97 Fix waveform display from going over buffer limit.
Matti Hamalainen <ccr@tnsp.org>
parents: 398
diff changeset
275 timelineScrollBar->setRange(0, getTimelineDuration());
391
28a74940f2b6 More work on the editor.
Matti Hamalainen <ccr@tnsp.org>
parents: 384
diff changeset
276 timelineScrollBar->setValue(currViewOffset);
28a74940f2b6 More work on the editor.
Matti Hamalainen <ccr@tnsp.org>
parents: 384
diff changeset
277 }
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 void DemoEditor::actionTimelineScrollChanged(int value)
28a74940f2b6 More work on the editor.
Matti Hamalainen <ccr@tnsp.org>
parents: 384
diff changeset
281 {
28a74940f2b6 More work on the editor.
Matti Hamalainen <ccr@tnsp.org>
parents: 384
diff changeset
282 currViewOffset = value;
28a74940f2b6 More work on the editor.
Matti Hamalainen <ccr@tnsp.org>
parents: 384
diff changeset
283 updateTimelineView();
28a74940f2b6 More work on the editor.
Matti Hamalainen <ccr@tnsp.org>
parents: 384
diff changeset
284 }
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 void DemoEditor::actionOffsetChanged(float value)
28a74940f2b6 More work on the editor.
Matti Hamalainen <ccr@tnsp.org>
parents: 384
diff changeset
288 {
28a74940f2b6 More work on the editor.
Matti Hamalainen <ccr@tnsp.org>
parents: 384
diff changeset
289 currViewOffset = value;
28a74940f2b6 More work on the editor.
Matti Hamalainen <ccr@tnsp.org>
parents: 384
diff changeset
290 updateTimelineView();
28a74940f2b6 More work on the editor.
Matti Hamalainen <ccr@tnsp.org>
parents: 384
diff changeset
291 }
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 void DemoEditor::actionTimeChanged(float value)
28a74940f2b6 More work on the editor.
Matti Hamalainen <ccr@tnsp.org>
parents: 384
diff changeset
295 {
28a74940f2b6 More work on the editor.
Matti Hamalainen <ccr@tnsp.org>
parents: 384
diff changeset
296 currFrameTime = value;
28a74940f2b6 More work on the editor.
Matti Hamalainen <ccr@tnsp.org>
parents: 384
diff changeset
297 updateTimelineView();
384
e5220ff48bc8 Slowly working on the editor.
Matti Hamalainen <ccr@tnsp.org>
parents: 379
diff changeset
298 }
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
397
9993873ff655 More work towards editor.
Matti Hamalainen <ccr@tnsp.org>
parents: 394
diff changeset
301 void DemoEditor::actionTimelineChanged()
9993873ff655 More work towards editor.
Matti Hamalainen <ccr@tnsp.org>
parents: 394
diff changeset
302 {
9993873ff655 More work towards editor.
Matti Hamalainen <ccr@tnsp.org>
parents: 394
diff changeset
303 updateMenuStates();
9993873ff655 More work towards editor.
Matti Hamalainen <ccr@tnsp.org>
parents: 394
diff changeset
304 update();
9993873ff655 More work towards editor.
Matti Hamalainen <ccr@tnsp.org>
parents: 394
diff changeset
305 }
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
378
feaeec4c6c55 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 376
diff changeset
308 int DemoEditor::initEffectsAndResources()
feaeec4c6c55 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 376
diff changeset
309 {
feaeec4c6c55 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 376
diff changeset
310 int err;
feaeec4c6c55 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 376
diff changeset
311
391
28a74940f2b6 More work on the editor.
Matti Hamalainen <ccr@tnsp.org>
parents: 384
diff changeset
312 currViewOffset = 0;
28a74940f2b6 More work on the editor.
Matti Hamalainen <ccr@tnsp.org>
parents: 384
diff changeset
313 currFrameTime = 0;
28a74940f2b6 More work on the editor.
Matti Hamalainen <ccr@tnsp.org>
parents: 384
diff changeset
314 currViewScale = 1.0f;
28a74940f2b6 More work on the editor.
Matti Hamalainen <ccr@tnsp.org>
parents: 384
diff changeset
315
378
feaeec4c6c55 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 376
diff changeset
316 // Initialize resource subsystem
384
e5220ff48bc8 Slowly working on the editor.
Matti Hamalainen <ccr@tnsp.org>
parents: 379
diff changeset
317 statusMsg("Initializing resources subsystem.");
378
feaeec4c6c55 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 376
diff changeset
318 if ((err = reopenResources()) != DMERR_OK)
feaeec4c6c55 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 376
diff changeset
319 return err;
feaeec4c6c55 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 376
diff changeset
320
feaeec4c6c55 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 376
diff changeset
321 // Load resources
384
e5220ff48bc8 Slowly working on the editor.
Matti Hamalainen <ccr@tnsp.org>
parents: 379
diff changeset
322 statusMsg("Loading resources, please wait...");
378
feaeec4c6c55 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 376
diff changeset
323 if ((err = loadResources()) != DMERR_OK)
feaeec4c6c55 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 376
diff changeset
324 {
feaeec4c6c55 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 376
diff changeset
325 dmError("Error loading resources, %d: %s.\n", err, dmErrorStr(err));
feaeec4c6c55 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 376
diff changeset
326 return err;
feaeec4c6c55 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 376
diff changeset
327 }
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 // Final initializations
384
e5220ff48bc8 Slowly working on the editor.
Matti Hamalainen <ccr@tnsp.org>
parents: 379
diff changeset
331 statusMsg("Initializing custom demo data.");
378
feaeec4c6c55 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 376
diff changeset
332 if ((err = engine.demoInit(&engine)) != DMERR_OK)
feaeec4c6c55 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 376
diff changeset
333 {
feaeec4c6c55 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 376
diff changeset
334 dmError("Failure in demoInit(), %d: %s\n",
feaeec4c6c55 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 376
diff changeset
335 err, dmErrorStr(err));
feaeec4c6c55 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 376
diff changeset
336 return err;
feaeec4c6c55 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 376
diff changeset
337 }
feaeec4c6c55 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 376
diff changeset
338
feaeec4c6c55 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 376
diff changeset
339 // Initialize effects
384
e5220ff48bc8 Slowly working on the editor.
Matti Hamalainen <ccr@tnsp.org>
parents: 379
diff changeset
340 statusMsg("Initializing effects ...");
378
feaeec4c6c55 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 376
diff changeset
341 if ((err = engineInitializeEffects(&engine)) != DMERR_OK)
feaeec4c6c55 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 376
diff changeset
342 {
feaeec4c6c55 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 376
diff changeset
343 dmError("Effects initialization failed, %d: %s\n",
feaeec4c6c55 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 376
diff changeset
344 err, dmErrorStr(err));
feaeec4c6c55 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 376
diff changeset
345 return err;
feaeec4c6c55 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 376
diff changeset
346 }
feaeec4c6c55 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 376
diff changeset
347
384
e5220ff48bc8 Slowly working on the editor.
Matti Hamalainen <ccr@tnsp.org>
parents: 379
diff changeset
348 // Etc.
403
d34922e6a244 Even more work towards the editor.
Matti Hamalainen <ccr@tnsp.org>
parents: 402
diff changeset
349 rehash();
378
feaeec4c6c55 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 376
diff changeset
350 return DMERR_OK;
feaeec4c6c55 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 376
diff changeset
351 }
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 void DemoEditor::shutdownEffectsAndResources()
feaeec4c6c55 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 376
diff changeset
355 {
397
9993873ff655 More work towards editor.
Matti Hamalainen <ccr@tnsp.org>
parents: 394
diff changeset
356 delete currTimeline;
376
40e33ad0d153 Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
357 dmFreePreparedTimelineData(engine.ptl);
40e33ad0d153 Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
358 engineShutdownEffects(&engine);
40e33ad0d153 Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
359 dmres_close(engine.resources);
40e33ad0d153 Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
360
40e33ad0d153 Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
361 if (engine.demoShutdown != NULL)
40e33ad0d153 Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
362 engine.demoShutdown(&engine);
40e33ad0d153 Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
363 }
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
403
d34922e6a244 Even more work towards the editor.
Matti Hamalainen <ccr@tnsp.org>
parents: 402
diff changeset
366 void DemoEditor::rehash()
d34922e6a244 Even more work towards the editor.
Matti Hamalainen <ccr@tnsp.org>
parents: 402
diff changeset
367 {
d34922e6a244 Even more work towards the editor.
Matti Hamalainen <ccr@tnsp.org>
parents: 402
diff changeset
368 timelineView->setTimeline(currTimeline);
d34922e6a244 Even more work towards the editor.
Matti Hamalainen <ccr@tnsp.org>
parents: 402
diff changeset
369 updateResourceView();
d34922e6a244 Even more work towards the editor.
Matti Hamalainen <ccr@tnsp.org>
parents: 402
diff changeset
370 updateTimelineView();
d34922e6a244 Even more work towards the editor.
Matti Hamalainen <ccr@tnsp.org>
parents: 402
diff changeset
371 updateMenuStates();
d34922e6a244 Even more work towards the editor.
Matti Hamalainen <ccr@tnsp.org>
parents: 402
diff changeset
372 update();
d34922e6a244 Even more work towards the editor.
Matti Hamalainen <ccr@tnsp.org>
parents: 402
diff changeset
373 }
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
378
feaeec4c6c55 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 376
diff changeset
376 void DemoEditor::createNewFile()
376
40e33ad0d153 Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
377 {
394
412082d5babc Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 393
diff changeset
378 delete currTimeline;
403
d34922e6a244 Even more work towards the editor.
Matti Hamalainen <ccr@tnsp.org>
parents: 402
diff changeset
379 currTimeline = new EDTimelineObject();
378
feaeec4c6c55 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 376
diff changeset
380
402
0f290af63fc1 Timeline event drawing prototype works.
Matti Hamalainen <ccr@tnsp.org>
parents: 401
diff changeset
381 DMTimelineTrack *tr;
0f290af63fc1 Timeline event drawing prototype works.
Matti Hamalainen <ccr@tnsp.org>
parents: 401
diff changeset
382 dmTimelineAddTrack(currTimeline->tl, &tr, "Penis");
0f290af63fc1 Timeline event drawing prototype works.
Matti Hamalainen <ccr@tnsp.org>
parents: 401
diff changeset
383
0f290af63fc1 Timeline event drawing prototype works.
Matti Hamalainen <ccr@tnsp.org>
parents: 401
diff changeset
384 DMTimelineEvent *ev;
0f290af63fc1 Timeline event drawing prototype works.
Matti Hamalainen <ccr@tnsp.org>
parents: 401
diff changeset
385 dmTimelineTrackAddEvent(tr, 500, 100, &ev);
0f290af63fc1 Timeline event drawing prototype works.
Matti Hamalainen <ccr@tnsp.org>
parents: 401
diff changeset
386
0f290af63fc1 Timeline event drawing prototype works.
Matti Hamalainen <ccr@tnsp.org>
parents: 401
diff changeset
387 dmTimelineEventSetEffectByIndex(ev, 0);
0f290af63fc1 Timeline event drawing prototype works.
Matti Hamalainen <ccr@tnsp.org>
parents: 401
diff changeset
388
376
40e33ad0d153 Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
389 historyReset();
40e33ad0d153 Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
390 updateMenuStates();
403
d34922e6a244 Even more work towards the editor.
Matti Hamalainen <ccr@tnsp.org>
parents: 402
diff changeset
391 update();
376
40e33ad0d153 Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
392 }
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 void DemoEditor::readFromFile(QString filename)
40e33ad0d153 Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
396 {
403
d34922e6a244 Even more work towards the editor.
Matti Hamalainen <ccr@tnsp.org>
parents: 402
diff changeset
397 EDTimelineObject *tmp = new EDTimelineObject();
376
40e33ad0d153 Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
398 int ret = tmp->load(filename);
40e33ad0d153 Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
399 if (ret != DMERR_OK)
40e33ad0d153 Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
400 {
378
feaeec4c6c55 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 376
diff changeset
401 showFileErrorDialog("Loading demo blob file "+ filename, ret);
376
40e33ad0d153 Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
402 delete tmp;
40e33ad0d153 Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
403 }
40e33ad0d153 Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
404 else
40e33ad0d153 Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
405 {
397
9993873ff655 More work towards editor.
Matti Hamalainen <ccr@tnsp.org>
parents: 394
diff changeset
406 delete currTimeline;
9993873ff655 More work towards editor.
Matti Hamalainen <ccr@tnsp.org>
parents: 394
diff changeset
407 currTimeline = tmp;
403
d34922e6a244 Even more work towards the editor.
Matti Hamalainen <ccr@tnsp.org>
parents: 402
diff changeset
408 rehash();
376
40e33ad0d153 Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
409 }
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 void DemoEditor::saveToFile(QString filename)
40e33ad0d153 Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
414 {
397
9993873ff655 More work towards editor.
Matti Hamalainen <ccr@tnsp.org>
parents: 394
diff changeset
415 int ret = currTimeline->save(filename);
376
40e33ad0d153 Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
416 if (ret != DMERR_OK)
40e33ad0d153 Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
417 {
378
feaeec4c6c55 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 376
diff changeset
418 showFileErrorDialog("Saving demo blob file "+ filename, ret);
376
40e33ad0d153 Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
419 }
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 updateMenuStates();
40e33ad0d153 Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
422 }
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 void DemoEditor::settingsRestore()
40e33ad0d153 Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
426 {
40e33ad0d153 Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
427 QSettings s;
40e33ad0d153 Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
428
40e33ad0d153 Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
429 restoreGeometry(s.value("windowGeometry").toByteArray());
40e33ad0d153 Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
430 restoreState(s.value("windowState").toByteArray());
40e33ad0d153 Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
431 }
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 void DemoEditor::settingsSave()
40e33ad0d153 Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
435 {
40e33ad0d153 Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
436 QSettings s;
40e33ad0d153 Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
437
40e33ad0d153 Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
438 s.setValue("windowGeometry", saveGeometry());
40e33ad0d153 Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
439 s.setValue("windowState", saveState());
40e33ad0d153 Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
440 }
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 // Edit history functionality
40e33ad0d153 Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
445 //
40e33ad0d153 Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
446 void DemoEditor::historyReset()
40e33ad0d153 Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
447 {
401
2fdf440ea66a Fix some segfaults, etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 400
diff changeset
448 if (currTimeline != NULL)
2fdf440ea66a Fix some segfaults, etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 400
diff changeset
449 currTimeline->scrub();
2fdf440ea66a Fix some segfaults, etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 400
diff changeset
450
376
40e33ad0d153 Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
451 undoHistoryPos = -1;
40e33ad0d153 Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
452 undoHistoryMax = DOC_UNDO_MAX;
40e33ad0d153 Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
453 undoHistory.clear();
40e33ad0d153 Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
454 }
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 void DemoEditor::historyPush(QString description)
40e33ad0d153 Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
458 {
401
2fdf440ea66a Fix some segfaults, etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 400
diff changeset
459 if (currTimeline == NULL)
2fdf440ea66a Fix some segfaults, etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 400
diff changeset
460 return;
2fdf440ea66a Fix some segfaults, etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 400
diff changeset
461
2fdf440ea66a Fix some segfaults, etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 400
diff changeset
462 if (!undoHistory.isEmpty() && undoHistory.last()->state() == "-")
376
40e33ad0d153 Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
463 {
40e33ad0d153 Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
464 delete undoHistory.takeLast();
40e33ad0d153 Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
465 }
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 while (undoHistory.size() >= undoHistoryMax)
40e33ad0d153 Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
468 {
40e33ad0d153 Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
469 delete undoHistory.takeFirst();
40e33ad0d153 Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
470 }
40e33ad0d153 Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
471
403
d34922e6a244 Even more work towards the editor.
Matti Hamalainen <ccr@tnsp.org>
parents: 402
diff changeset
472 EDTimelineObject *copy = new EDTimelineObject(currTimeline);
401
2fdf440ea66a Fix some segfaults, etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 400
diff changeset
473 copy->setState(description);
376
40e33ad0d153 Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
474 undoHistory.append(copy);
40e33ad0d153 Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
475 }
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 void DemoEditor::historyTop()
40e33ad0d153 Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
479 {
401
2fdf440ea66a Fix some segfaults, etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 400
diff changeset
480 if (currTimeline == NULL)
2fdf440ea66a Fix some segfaults, etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 400
diff changeset
481 return;
2fdf440ea66a Fix some segfaults, etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 400
diff changeset
482
403
d34922e6a244 Even more work towards the editor.
Matti Hamalainen <ccr@tnsp.org>
parents: 402
diff changeset
483 EDTimelineObject *copy = new EDTimelineObject(currTimeline);
401
2fdf440ea66a Fix some segfaults, etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 400
diff changeset
484 copy->setState("-");
376
40e33ad0d153 Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
485 undoHistory.append(copy);
40e33ad0d153 Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
486
40e33ad0d153 Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
487 undoHistoryPos = undoHistory.size() - 1;
401
2fdf440ea66a Fix some segfaults, etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 400
diff changeset
488 currTimeline->touch();
403
d34922e6a244 Even more work towards the editor.
Matti Hamalainen <ccr@tnsp.org>
parents: 402
diff changeset
489 updateTimelineView();
376
40e33ad0d153 Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
490 updateMenuStates();
40e33ad0d153 Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
491 update();
40e33ad0d153 Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
492 }
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 void DemoEditor::historyPop()
40e33ad0d153 Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
496 {
40e33ad0d153 Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
497 if (!undoHistory.isEmpty())
40e33ad0d153 Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
498 {
40e33ad0d153 Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
499 delete undoHistory.takeLast();
40e33ad0d153 Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
500 }
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 void DemoEditor::performRedo()
40e33ad0d153 Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
505 {
40e33ad0d153 Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
506 if (undoHistoryPos >= 0 && undoHistoryPos < undoHistory.size() - 1)
40e33ad0d153 Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
507 {
40e33ad0d153 Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
508 undoHistoryPos++;
393
5137db55f00b More work towards the editor ..
Matti Hamalainen <ccr@tnsp.org>
parents: 391
diff changeset
509 delete currTimeline;
403
d34922e6a244 Even more work towards the editor.
Matti Hamalainen <ccr@tnsp.org>
parents: 402
diff changeset
510 currTimeline = new EDTimelineObject(undoHistory.at(undoHistoryPos));
401
2fdf440ea66a Fix some segfaults, etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 400
diff changeset
511 currTimeline->touch();
403
d34922e6a244 Even more work towards the editor.
Matti Hamalainen <ccr@tnsp.org>
parents: 402
diff changeset
512 updateTimelineView();
376
40e33ad0d153 Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
513 updateMenuStates();
40e33ad0d153 Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
514 update();
40e33ad0d153 Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
515 }
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 void DemoEditor::performUndo()
40e33ad0d153 Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
520 {
40e33ad0d153 Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
521 if (undoHistoryPos > 0 && undoHistory.size() > 1)
40e33ad0d153 Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
522 {
40e33ad0d153 Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
523 undoHistoryPos--;
393
5137db55f00b More work towards the editor ..
Matti Hamalainen <ccr@tnsp.org>
parents: 391
diff changeset
524 delete currTimeline;
403
d34922e6a244 Even more work towards the editor.
Matti Hamalainen <ccr@tnsp.org>
parents: 402
diff changeset
525 currTimeline = new EDTimelineObject(undoHistory.at(undoHistoryPos));
401
2fdf440ea66a Fix some segfaults, etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 400
diff changeset
526 currTimeline->touch();
403
d34922e6a244 Even more work towards the editor.
Matti Hamalainen <ccr@tnsp.org>
parents: 402
diff changeset
527 updateTimelineView();
376
40e33ad0d153 Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
528 updateMenuStates();
40e33ad0d153 Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
529 update();
40e33ad0d153 Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
530 }
40e33ad0d153 Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
531 }