annotate edmain.cpp @ 378:feaeec4c6c55

Cleanups.
author Matti Hamalainen <ccr@tnsp.org>
date Wed, 17 Oct 2012 03:33:19 +0300
parents 40e33ad0d153
children 05e85401480a
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 "eddemoobj.h"
40e33ad0d153 Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
9 #include <QSettings>
40e33ad0d153 Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
10 #include <QGLWidget>
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
40e33ad0d153 Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
13 int main(int argc, char *argv[])
40e33ad0d153 Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
14 {
40e33ad0d153 Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
15 dmVerbosity = 5;
40e33ad0d153 Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
16
40e33ad0d153 Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
17 QApplication app(argc, argv);
40e33ad0d153 Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
18
40e33ad0d153 Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
19 app.setOrganizationName("TNSP");
40e33ad0d153 Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
20 app.setOrganizationDomain("tnsp.org");
40e33ad0d153 Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
21 app.setApplicationName(PROGRAM_NAME);
40e33ad0d153 Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
22 app.setApplicationVersion(PROGRAM_VERSION);
40e33ad0d153 Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
23
40e33ad0d153 Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
24 DemoEditor mainWin;
40e33ad0d153 Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
25
40e33ad0d153 Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
26 mainWin.show();
40e33ad0d153 Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
27
40e33ad0d153 Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
28 return app.exec();
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
40e33ad0d153 Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
32 void engineAudioCallback(void *userdata, Uint8 * stream, int len)
40e33ad0d153 Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
33 {
40e33ad0d153 Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
34 DMEngineData *engine = (DMEngineData *) userdata;
40e33ad0d153 Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
35
40e33ad0d153 Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
36 if (engine->paused)
40e33ad0d153 Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
37 {
40e33ad0d153 Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
38 memset(stream, 0, len);
40e33ad0d153 Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
39 }
40e33ad0d153 Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
40 else
40e33ad0d153 Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
41 #ifdef DM_USE_JSS
40e33ad0d153 Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
42 {
40e33ad0d153 Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
43 if (engine->dev != NULL)
40e33ad0d153 Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
44 jvmRenderAudio(engine->dev, stream,
40e33ad0d153 Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
45 len / jvmGetSampleSize(engine->dev));
40e33ad0d153 Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
46 }
40e33ad0d153 Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
47 #endif
40e33ad0d153 Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
48 #ifdef DM_USE_TREMOR
40e33ad0d153 Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
49 if (engine->audioPos + len >= engine->audioRes->rdataSize)
40e33ad0d153 Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
50 {
40e33ad0d153 Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
51 engine->exitFlag = true;
40e33ad0d153 Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
52 }
40e33ad0d153 Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
53 else
40e33ad0d153 Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
54 {
40e33ad0d153 Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
55 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
56 engine->audioPos += len;
40e33ad0d153 Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
57 }
40e33ad0d153 Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
58 #endif
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
40e33ad0d153 Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
62 int DemoEditor::reopenResources()
40e33ad0d153 Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
63 {
40e33ad0d153 Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
64 int err;
40e33ad0d153 Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
65
40e33ad0d153 Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
66 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
67 engine.optResFlags, engineClassifier)) != DMERR_OK)
40e33ad0d153 Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
68 {
40e33ad0d153 Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
69 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
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 {
40e33ad0d153 Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
78 int err, loaded, total;
40e33ad0d153 Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
79 err = dmres_preload(engine.resources, true, &loaded, &total);
40e33ad0d153 Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
80
40e33ad0d153 Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
81 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
82 {
40e33ad0d153 Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
83 // Show a nice progress bar while loading
40e33ad0d153 Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
84 if (total > 0 && (loaded % 2) == 0)
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 /*
40e33ad0d153 Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
87 if ((err = engineShowProgress(loaded, total)) != DMERR_OK)
40e33ad0d153 Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
88 return err;
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 }
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
378
feaeec4c6c55 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 376
diff changeset
103 changed = FALSE;
feaeec4c6c55 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 376
diff changeset
104 initSDL = FALSE;
feaeec4c6c55 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 376
diff changeset
105 tl = NULL;
376
40e33ad0d153 Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
106 memset(&engine, 0, sizeof(engine));
40e33ad0d153 Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
107
40e33ad0d153 Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
108 // Pre-initialization
40e33ad0d153 Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
109 if ((err = demoPreInit(&engine)) != DMERR_OK)
40e33ad0d153 Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
110 goto error_exit;
40e33ad0d153 Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
111
40e33ad0d153 Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
112 // Initialize SDL components
40e33ad0d153 Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
113 dmPrint(1, "Initializing libSDL.\n");
40e33ad0d153 Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
114 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
115 {
40e33ad0d153 Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
116 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
117 goto error_exit;
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 initSDL = true;
40e33ad0d153 Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
120
40e33ad0d153 Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
121 // Initialize audio parts
40e33ad0d153 Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
122 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
123 {
40e33ad0d153 Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
124 // Defaults, if none seem to be set
40e33ad0d153 Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
125 engine.optAfmt.freq = 44100;
40e33ad0d153 Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
126 engine.optAfmt.format = AUDIO_S16SYS;
40e33ad0d153 Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
127 engine.optAfmt.channels = 2;
40e33ad0d153 Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
128 engine.optAfmt.samples = engine.optAfmt.freq / 16;
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
40e33ad0d153 Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
131 #ifdef DM_USE_JSS
40e33ad0d153 Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
132 jssInit();
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 switch (engine.optAfmt.format)
40e33ad0d153 Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
135 {
40e33ad0d153 Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
136 case AUDIO_S16SYS:
40e33ad0d153 Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
137 engine.jss_format = JSS_AUDIO_S16;
40e33ad0d153 Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
138 break;
40e33ad0d153 Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
139 case AUDIO_U16SYS:
40e33ad0d153 Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
140 engine.jss_format = JSS_AUDIO_U16;
40e33ad0d153 Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
141 break;
40e33ad0d153 Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
142 case AUDIO_S8:
40e33ad0d153 Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
143 engine.jss_format = JSS_AUDIO_S8;
40e33ad0d153 Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
144 break;
40e33ad0d153 Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
145 case AUDIO_U8:
40e33ad0d153 Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
146 engine.jss_format = JSS_AUDIO_U8;
40e33ad0d153 Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
147 break;
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
40e33ad0d153 Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
150 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
151 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
152
40e33ad0d153 Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
153 if ((engine.dev =
40e33ad0d153 Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
154 jvmInit(engine.jss_format, engine.optAfmt.channels,
40e33ad0d153 Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
155 engine.optAfmt.freq, JMIX_AUTO)) == NULL)
40e33ad0d153 Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
156 {
40e33ad0d153 Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
157 dmError("jvmInit() returned NULL, voi perkele.\n");
40e33ad0d153 Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
158 goto error_exit;
40e33ad0d153 Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
159 }
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 if ((engine.plr = jmpInit(engine.dev)) == NULL)
40e33ad0d153 Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
162 {
40e33ad0d153 Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
163 dmError("jmpInit() returned NULL\n");
40e33ad0d153 Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
164 goto error_exit;
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 #endif
40e33ad0d153 Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
167
40e33ad0d153 Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
168 // Initialize SDL audio
40e33ad0d153 Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
169 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
170 engine.optAfmt.format, engine.optAfmt.channels,
40e33ad0d153 Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
171 engine.optAfmt.freq);
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 engine.optAfmt.callback = engineAudioCallback;
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 if (SDL_OpenAudio(&engine.optAfmt, NULL) < 0)
40e33ad0d153 Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
176 {
40e33ad0d153 Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
177 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
178 goto error_exit;
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
40e33ad0d153 Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
181 // Initialize SDL video
40e33ad0d153 Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
182 if (engine.demoInitPreVideo != NULL &&
40e33ad0d153 Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
183 (err = engine.demoInitPreVideo(&engine)) != DMERR_OK)
40e33ad0d153 Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
184 {
40e33ad0d153 Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
185 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
186 goto error_exit;
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
40e33ad0d153 Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
189 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
190 engine.optScrWidth, engine.optScrHeight, engine.optBitDepth, engine.optVFlags);
40e33ad0d153 Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
191
40e33ad0d153 Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
192 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
193 if (engine.screen == NULL)
40e33ad0d153 Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
194 {
40e33ad0d153 Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
195 dmError("Could not allocate video backbuffer surface.\n");
40e33ad0d153 Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
196 goto error_exit;
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
40e33ad0d153 Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
199 if (engine.demoInitPostVideo != NULL &&
40e33ad0d153 Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
200 (err = engine.demoInitPostVideo(&engine)) != DMERR_OK)
40e33ad0d153 Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
201 {
40e33ad0d153 Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
202 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
203 goto error_exit;
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
40e33ad0d153 Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
207 error_exit:
40e33ad0d153 Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
208
40e33ad0d153 Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
209 // Setup GUI elements
40e33ad0d153 Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
210 createMainGUI();
40e33ad0d153 Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
211 createNewFile();
40e33ad0d153 Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
212
40e33ad0d153 Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
213 settingsRestore();
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 // view->setViewport(new QGLWidget(QGLFormat(QGL::SampleBuffers)));
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 updateMenuStates();
40e33ad0d153 Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
218 statusMsg("Application started.");
40e33ad0d153 Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
219 }
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
40e33ad0d153 Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
222 DemoEditor::~DemoEditor()
40e33ad0d153 Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
223 {
40e33ad0d153 Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
224 dmPrint(1, "Shutting down.\n");
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 settingsSave();
40e33ad0d153 Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
227 // delete view;
378
feaeec4c6c55 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 376
diff changeset
228 delete tl;
376
40e33ad0d153 Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
229 historyReset();
40e33ad0d153 Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
230
40e33ad0d153 Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
231 if (engine.screen)
40e33ad0d153 Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
232 SDL_FreeSurface(engine.screen);
40e33ad0d153 Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
233
40e33ad0d153 Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
234 SDL_LockAudio();
40e33ad0d153 Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
235 SDL_PauseAudio(1);
40e33ad0d153 Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
236 #ifdef DM_USE_JSS
40e33ad0d153 Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
237 jmpClose(engine.plr);
40e33ad0d153 Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
238 jvmClose(engine.dev);
40e33ad0d153 Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
239 jssClose();
40e33ad0d153 Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
240 #endif
40e33ad0d153 Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
241 SDL_UnlockAudio();
40e33ad0d153 Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
242
378
feaeec4c6c55 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 376
diff changeset
243 shutdownEffectsAndResources();
feaeec4c6c55 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 376
diff changeset
244
feaeec4c6c55 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 376
diff changeset
245 if (initSDL)
feaeec4c6c55 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 376
diff changeset
246 SDL_Quit();
feaeec4c6c55 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 376
diff changeset
247 }
feaeec4c6c55 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 376
diff changeset
248
feaeec4c6c55 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 376
diff changeset
249
feaeec4c6c55 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 376
diff changeset
250 int DemoEditor::initEffectsAndResources()
feaeec4c6c55 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 376
diff changeset
251 {
feaeec4c6c55 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 376
diff changeset
252 int err;
feaeec4c6c55 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 376
diff changeset
253
feaeec4c6c55 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 376
diff changeset
254 // Initialize resource subsystem
feaeec4c6c55 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 376
diff changeset
255 dmPrint(1, "Initializing resources subsystem.\n");
feaeec4c6c55 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 376
diff changeset
256 if ((err = reopenResources()) != DMERR_OK)
feaeec4c6c55 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 376
diff changeset
257 return err;
feaeec4c6c55 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 376
diff changeset
258
feaeec4c6c55 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 376
diff changeset
259 // Load resources
feaeec4c6c55 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 376
diff changeset
260 dmPrint(1, "Loading resources, please wait...\n");
feaeec4c6c55 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 376
diff changeset
261 if ((err = loadResources()) != DMERR_OK)
feaeec4c6c55 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 376
diff changeset
262 {
feaeec4c6c55 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 376
diff changeset
263 dmError("Error loading resources, %d: %s.\n", err, dmErrorStr(err));
feaeec4c6c55 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 376
diff changeset
264 return err;
feaeec4c6c55 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 376
diff changeset
265 }
feaeec4c6c55 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 376
diff changeset
266
feaeec4c6c55 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 376
diff changeset
267 dmPrint(1, "Initializing effects, etc.\n");
feaeec4c6c55 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 376
diff changeset
268
feaeec4c6c55 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 376
diff changeset
269 // Final initializations
feaeec4c6c55 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 376
diff changeset
270 if ((err = engine.demoInit(&engine)) != DMERR_OK)
feaeec4c6c55 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 376
diff changeset
271 {
feaeec4c6c55 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 376
diff changeset
272 dmError("Failure in demoInit(), %d: %s\n",
feaeec4c6c55 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 376
diff changeset
273 err, dmErrorStr(err));
feaeec4c6c55 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 376
diff changeset
274 return err;
feaeec4c6c55 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 376
diff changeset
275 }
feaeec4c6c55 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 376
diff changeset
276
feaeec4c6c55 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 376
diff changeset
277 // Initialize effects
feaeec4c6c55 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 376
diff changeset
278 if ((err = engineInitializeEffects(&engine)) != DMERR_OK)
feaeec4c6c55 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 376
diff changeset
279 {
feaeec4c6c55 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 376
diff changeset
280 dmError("Effects initialization failed, %d: %s\n",
feaeec4c6c55 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 376
diff changeset
281 err, dmErrorStr(err));
feaeec4c6c55 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 376
diff changeset
282 return err;
feaeec4c6c55 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 376
diff changeset
283 }
feaeec4c6c55 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 376
diff changeset
284
feaeec4c6c55 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 376
diff changeset
285 return DMERR_OK;
feaeec4c6c55 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 376
diff changeset
286 }
feaeec4c6c55 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 376
diff changeset
287
feaeec4c6c55 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 376
diff changeset
288
feaeec4c6c55 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 376
diff changeset
289 void DemoEditor::shutdownEffectsAndResources()
feaeec4c6c55 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 376
diff changeset
290 {
376
40e33ad0d153 Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
291 dmFreeTimeline(engine.tl);
40e33ad0d153 Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
292 dmFreePreparedTimelineData(engine.ptl);
40e33ad0d153 Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
293 engineShutdownEffects(&engine);
40e33ad0d153 Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
294 dmres_close(engine.resources);
40e33ad0d153 Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
295
40e33ad0d153 Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
296 if (engine.demoShutdown != NULL)
40e33ad0d153 Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
297 engine.demoShutdown(&engine);
40e33ad0d153 Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
298 }
40e33ad0d153 Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
299
40e33ad0d153 Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
300
378
feaeec4c6c55 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 376
diff changeset
301 void DemoEditor::createNewFile()
376
40e33ad0d153 Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
302 {
378
feaeec4c6c55 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 376
diff changeset
303 delete tl;
feaeec4c6c55 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 376
diff changeset
304 tl = new TimelineObject();
feaeec4c6c55 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 376
diff changeset
305
376
40e33ad0d153 Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
306 update();
40e33ad0d153 Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
307 historyReset();
40e33ad0d153 Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
308 changed = false;
40e33ad0d153 Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
309 updateMenuStates();
40e33ad0d153 Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
310 }
40e33ad0d153 Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
311
40e33ad0d153 Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
312
40e33ad0d153 Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
313 void DemoEditor::readFromFile(QString filename)
40e33ad0d153 Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
314 {
378
feaeec4c6c55 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 376
diff changeset
315 TimelineObject *tmp = new TimelineObject();
376
40e33ad0d153 Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
316 int ret = tmp->load(filename);
40e33ad0d153 Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
317 if (ret != DMERR_OK)
40e33ad0d153 Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
318 {
378
feaeec4c6c55 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 376
diff changeset
319 showFileErrorDialog("Loading demo blob file "+ filename, ret);
376
40e33ad0d153 Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
320 delete tmp;
40e33ad0d153 Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
321 }
40e33ad0d153 Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
322 else
40e33ad0d153 Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
323 {
378
feaeec4c6c55 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 376
diff changeset
324 delete tl;
feaeec4c6c55 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 376
diff changeset
325 tl = tmp;
feaeec4c6c55 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 376
diff changeset
326
feaeec4c6c55 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 376
diff changeset
327 update();
feaeec4c6c55 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 376
diff changeset
328 historyReset();
feaeec4c6c55 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 376
diff changeset
329 changed = false;
feaeec4c6c55 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 376
diff changeset
330 updateMenuStates();
376
40e33ad0d153 Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
331 }
40e33ad0d153 Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
332 }
40e33ad0d153 Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
333
40e33ad0d153 Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
334
40e33ad0d153 Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
335 void DemoEditor::saveToFile(QString filename)
40e33ad0d153 Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
336 {
378
feaeec4c6c55 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 376
diff changeset
337 int ret = tl->save(filename);
376
40e33ad0d153 Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
338 if (ret != DMERR_OK)
40e33ad0d153 Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
339 {
378
feaeec4c6c55 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 376
diff changeset
340 showFileErrorDialog("Saving demo blob file "+ filename, ret);
376
40e33ad0d153 Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
341 }
40e33ad0d153 Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
342
40e33ad0d153 Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
343 updateMenuStates();
40e33ad0d153 Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
344 }
40e33ad0d153 Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
345
40e33ad0d153 Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
346
40e33ad0d153 Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
347 void DemoEditor::settingsRestore()
40e33ad0d153 Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
348 {
40e33ad0d153 Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
349 QSettings s;
40e33ad0d153 Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
350
40e33ad0d153 Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
351 restoreGeometry(s.value("windowGeometry").toByteArray());
40e33ad0d153 Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
352 restoreState(s.value("windowState").toByteArray());
40e33ad0d153 Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
353
40e33ad0d153 Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
354 }
40e33ad0d153 Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
355
40e33ad0d153 Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
356
40e33ad0d153 Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
357 void DemoEditor::settingsSave()
40e33ad0d153 Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
358 {
40e33ad0d153 Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
359 QSettings s;
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 s.setValue("windowGeometry", saveGeometry());
40e33ad0d153 Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
362 s.setValue("windowState", saveState());
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
40e33ad0d153 Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
366
40e33ad0d153 Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
367 //
40e33ad0d153 Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
368 // Edit history functionality
40e33ad0d153 Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
369 //
40e33ad0d153 Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
370 void DemoEditor::historyReset()
40e33ad0d153 Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
371 {
40e33ad0d153 Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
372 changed = false;
40e33ad0d153 Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
373 undoHistoryPos = -1;
40e33ad0d153 Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
374 undoHistoryMax = DOC_UNDO_MAX;
40e33ad0d153 Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
375 undoHistory.clear();
40e33ad0d153 Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
376 }
40e33ad0d153 Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
377
40e33ad0d153 Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
378
40e33ad0d153 Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
379 void DemoEditor::historyPush(QString description)
40e33ad0d153 Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
380 {
40e33ad0d153 Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
381 if (!undoHistory.isEmpty() && undoHistory.last()->state == "-")
40e33ad0d153 Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
382 {
40e33ad0d153 Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
383 delete undoHistory.takeLast();
40e33ad0d153 Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
384 }
40e33ad0d153 Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
385
40e33ad0d153 Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
386 while (undoHistory.size() >= undoHistoryMax)
40e33ad0d153 Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
387 {
40e33ad0d153 Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
388 delete undoHistory.takeFirst();
40e33ad0d153 Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
389 }
40e33ad0d153 Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
390
378
feaeec4c6c55 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 376
diff changeset
391 TimelineObject *copy = new TimelineObject(tl);
376
40e33ad0d153 Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
392 copy->state = description;
40e33ad0d153 Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
393 undoHistory.append(copy);
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
40e33ad0d153 Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
397 void DemoEditor::historyTop()
40e33ad0d153 Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
398 {
378
feaeec4c6c55 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 376
diff changeset
399 TimelineObject *copy = new TimelineObject(tl);
376
40e33ad0d153 Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
400 copy->state = "-";
40e33ad0d153 Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
401 undoHistory.append(copy);
40e33ad0d153 Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
402
40e33ad0d153 Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
403 undoHistoryPos = undoHistory.size() - 1;
40e33ad0d153 Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
404 changed = true;
40e33ad0d153 Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
405 updateMenuStates();
40e33ad0d153 Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
406 update();
40e33ad0d153 Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
407 }
40e33ad0d153 Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
408
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 void DemoEditor::historyPop()
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 if (!undoHistory.isEmpty())
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 delete undoHistory.takeLast();
40e33ad0d153 Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
415 }
40e33ad0d153 Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
416 }
40e33ad0d153 Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
417
40e33ad0d153 Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
418
40e33ad0d153 Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
419 void DemoEditor::performRedo()
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 if (undoHistoryPos >= 0 && undoHistoryPos < undoHistory.size() - 1)
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 undoHistoryPos++;
378
feaeec4c6c55 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 376
diff changeset
424 delete tl;
feaeec4c6c55 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 376
diff changeset
425 tl = new TimelineObject(undoHistory.at(undoHistoryPos));
376
40e33ad0d153 Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
426 changed = true;
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 updateMenuStates();
40e33ad0d153 Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
429 update();
40e33ad0d153 Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
430 }
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::performUndo()
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 if (undoHistoryPos > 0 && undoHistory.size() > 1)
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 undoHistoryPos--;
378
feaeec4c6c55 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 376
diff changeset
439 delete tl;
feaeec4c6c55 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 376
diff changeset
440 tl = new TimelineObject(undoHistory.at(undoHistoryPos));
376
40e33ad0d153 Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
441 changed = true;
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 updateMenuStates();
40e33ad0d153 Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
444 update();
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 }