Mercurial > hg > dmlib
annotate edmain.cpp @ 393:5137db55f00b
More work towards the editor ..
author | Matti Hamalainen <ccr@tnsp.org> |
---|---|
date | Fri, 19 Oct 2012 05:50:11 +0300 |
parents | 28a74940f2b6 |
children | 412082d5babc |
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 |
378 | 102 changed = FALSE; |
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 memset(&engine, 0, sizeof(engine)); |
40e33ad0d153
Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
106 |
40e33ad0d153
Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
107 // Pre-initialization |
40e33ad0d153
Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
108 if ((err = demoPreInit(&engine)) != DMERR_OK) |
40e33ad0d153
Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
109 goto error_exit; |
40e33ad0d153
Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
110 |
40e33ad0d153
Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
111 // Initialize SDL components |
40e33ad0d153
Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
112 dmPrint(1, "Initializing libSDL.\n"); |
40e33ad0d153
Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
113 if (SDL_Init(SDL_INIT_VIDEO | SDL_INIT_AUDIO | SDL_INIT_TIMER) != 0) |
40e33ad0d153
Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
114 { |
40e33ad0d153
Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
115 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
|
116 goto error_exit; |
40e33ad0d153
Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
117 } |
40e33ad0d153
Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
118 initSDL = true; |
40e33ad0d153
Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
119 |
40e33ad0d153
Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
120 // Initialize audio parts |
40e33ad0d153
Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
121 if (engine.optAfmt.freq == 0 && engine.optAfmt.channels == 0) |
40e33ad0d153
Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
122 { |
40e33ad0d153
Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
123 // Defaults, if none seem to be set |
40e33ad0d153
Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
124 engine.optAfmt.freq = 44100; |
40e33ad0d153
Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
125 engine.optAfmt.format = AUDIO_S16SYS; |
40e33ad0d153
Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
126 engine.optAfmt.channels = 2; |
40e33ad0d153
Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
127 engine.optAfmt.samples = engine.optAfmt.freq / 16; |
40e33ad0d153
Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
128 } |
40e33ad0d153
Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
129 |
40e33ad0d153
Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
130 #ifdef DM_USE_JSS |
40e33ad0d153
Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
131 jssInit(); |
40e33ad0d153
Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
132 |
40e33ad0d153
Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
133 switch (engine.optAfmt.format) |
40e33ad0d153
Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
134 { |
40e33ad0d153
Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
135 case AUDIO_S16SYS: |
40e33ad0d153
Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
136 engine.jss_format = JSS_AUDIO_S16; |
40e33ad0d153
Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
137 break; |
40e33ad0d153
Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
138 case AUDIO_U16SYS: |
40e33ad0d153
Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
139 engine.jss_format = JSS_AUDIO_U16; |
40e33ad0d153
Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
140 break; |
40e33ad0d153
Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
141 case AUDIO_S8: |
40e33ad0d153
Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
142 engine.jss_format = JSS_AUDIO_S8; |
40e33ad0d153
Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
143 break; |
40e33ad0d153
Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
144 case AUDIO_U8: |
40e33ad0d153
Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
145 engine.jss_format = JSS_AUDIO_U8; |
40e33ad0d153
Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
146 break; |
40e33ad0d153
Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
147 } |
40e33ad0d153
Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
148 |
40e33ad0d153
Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
149 dmPrint(1, "Initializing miniJSS mixer with fmt=%d, chn=%d, freq=%d\n", |
40e33ad0d153
Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
150 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
|
151 |
40e33ad0d153
Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
152 if ((engine.dev = |
40e33ad0d153
Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
153 jvmInit(engine.jss_format, engine.optAfmt.channels, |
40e33ad0d153
Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
154 engine.optAfmt.freq, JMIX_AUTO)) == NULL) |
40e33ad0d153
Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
155 { |
40e33ad0d153
Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
156 dmError("jvmInit() returned NULL, voi perkele.\n"); |
40e33ad0d153
Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
157 goto error_exit; |
40e33ad0d153
Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
158 } |
40e33ad0d153
Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
159 |
40e33ad0d153
Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
160 if ((engine.plr = jmpInit(engine.dev)) == NULL) |
40e33ad0d153
Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
161 { |
40e33ad0d153
Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
162 dmError("jmpInit() returned NULL\n"); |
40e33ad0d153
Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
163 goto error_exit; |
40e33ad0d153
Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
164 } |
40e33ad0d153
Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
165 #endif |
40e33ad0d153
Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
166 |
40e33ad0d153
Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
167 // Initialize SDL audio |
40e33ad0d153
Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
168 dmPrint(1, "Trying to init SDL audio with: fmt=%d, chn=%d, freq=%d\n", |
40e33ad0d153
Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
169 engine.optAfmt.format, engine.optAfmt.channels, |
40e33ad0d153
Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
170 engine.optAfmt.freq); |
40e33ad0d153
Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
171 |
40e33ad0d153
Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
172 engine.optAfmt.callback = engineAudioCallback; |
40e33ad0d153
Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
173 |
40e33ad0d153
Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
174 if (SDL_OpenAudio(&engine.optAfmt, NULL) < 0) |
40e33ad0d153
Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
175 { |
40e33ad0d153
Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
176 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
|
177 goto error_exit; |
40e33ad0d153
Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
178 } |
40e33ad0d153
Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
179 |
40e33ad0d153
Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
180 // Initialize SDL video |
40e33ad0d153
Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
181 if (engine.demoInitPreVideo != NULL && |
40e33ad0d153
Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
182 (err = engine.demoInitPreVideo(&engine)) != DMERR_OK) |
40e33ad0d153
Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
183 { |
40e33ad0d153
Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
184 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
|
185 goto error_exit; |
40e33ad0d153
Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
186 } |
40e33ad0d153
Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
187 |
40e33ad0d153
Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
188 dmPrint(1, "Initializing SDL video %d x %d x %dbpp, flags=0x%08x\n", |
40e33ad0d153
Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
189 engine.optScrWidth, engine.optScrHeight, engine.optBitDepth, engine.optVFlags); |
40e33ad0d153
Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
190 |
40e33ad0d153
Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
191 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
|
192 if (engine.screen == NULL) |
40e33ad0d153
Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
193 { |
40e33ad0d153
Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
194 dmError("Could not allocate video backbuffer surface.\n"); |
40e33ad0d153
Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
195 goto error_exit; |
40e33ad0d153
Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
196 } |
40e33ad0d153
Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
197 |
40e33ad0d153
Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
198 if (engine.demoInitPostVideo != NULL && |
40e33ad0d153
Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
199 (err = engine.demoInitPostVideo(&engine)) != DMERR_OK) |
40e33ad0d153
Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
200 { |
40e33ad0d153
Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
201 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
|
202 goto error_exit; |
40e33ad0d153
Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
203 } |
40e33ad0d153
Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
204 |
40e33ad0d153
Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
205 |
40e33ad0d153
Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
206 error_exit: |
40e33ad0d153
Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
207 |
40e33ad0d153
Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
208 // Setup GUI elements |
40e33ad0d153
Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
209 createMainGUI(); |
40e33ad0d153
Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
210 createNewFile(); |
40e33ad0d153
Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
211 |
40e33ad0d153
Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
212 settingsRestore(); |
40e33ad0d153
Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
213 |
40e33ad0d153
Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
214 // view->setViewport(new QGLWidget(QGLFormat(QGL::SampleBuffers))); |
40e33ad0d153
Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
215 |
384
e5220ff48bc8
Slowly working on the editor.
Matti Hamalainen <ccr@tnsp.org>
parents:
379
diff
changeset
|
216 initEffectsAndResources(); |
376
40e33ad0d153
Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
217 statusMsg("Application started."); |
40e33ad0d153
Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
218 } |
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 DemoEditor::~DemoEditor() |
40e33ad0d153
Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
222 { |
384
e5220ff48bc8
Slowly working on the editor.
Matti Hamalainen <ccr@tnsp.org>
parents:
379
diff
changeset
|
223 statusMsg("Shutting down."); |
376
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 settingsSave(); |
384
e5220ff48bc8
Slowly working on the editor.
Matti Hamalainen <ccr@tnsp.org>
parents:
379
diff
changeset
|
226 delete demoView; |
378 | 227 delete tl; |
376
40e33ad0d153
Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
228 historyReset(); |
40e33ad0d153
Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
229 |
40e33ad0d153
Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
230 if (engine.screen) |
40e33ad0d153
Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
231 SDL_FreeSurface(engine.screen); |
40e33ad0d153
Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
232 |
40e33ad0d153
Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
233 SDL_LockAudio(); |
40e33ad0d153
Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
234 SDL_PauseAudio(1); |
40e33ad0d153
Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
235 #ifdef DM_USE_JSS |
40e33ad0d153
Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
236 jmpClose(engine.plr); |
40e33ad0d153
Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
237 jvmClose(engine.dev); |
40e33ad0d153
Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
238 jssClose(); |
40e33ad0d153
Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
239 #endif |
40e33ad0d153
Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
240 SDL_UnlockAudio(); |
40e33ad0d153
Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
241 |
378 | 242 shutdownEffectsAndResources(); |
243 | |
244 if (initSDL) | |
245 SDL_Quit(); | |
246 } | |
247 | |
248 | |
391 | 249 // Return audio track duration in milliseconds |
250 int DemoEditor::getAudioTrackDuration() | |
251 { | |
252 return timelineAudioTrack->getDuration(); | |
253 } | |
254 | |
255 | |
256 int DemoEditor::getTimelineDuration() | |
257 { | |
258 return getAudioTrackDuration(); | |
259 } | |
260 | |
261 | |
384
e5220ff48bc8
Slowly working on the editor.
Matti Hamalainen <ccr@tnsp.org>
parents:
379
diff
changeset
|
262 void DemoEditor::updateTimelineView() |
e5220ff48bc8
Slowly working on the editor.
Matti Hamalainen <ccr@tnsp.org>
parents:
379
diff
changeset
|
263 { |
393
5137db55f00b
More work towards the editor ..
Matti Hamalainen <ccr@tnsp.org>
parents:
391
diff
changeset
|
264 demoView->setEngineData(&engine); |
5137db55f00b
More work towards the editor ..
Matti Hamalainen <ccr@tnsp.org>
parents:
391
diff
changeset
|
265 |
5137db55f00b
More work towards the editor ..
Matti Hamalainen <ccr@tnsp.org>
parents:
391
diff
changeset
|
266 timelineAudioTrack->setWaveform( |
5137db55f00b
More work towards the editor ..
Matti Hamalainen <ccr@tnsp.org>
parents:
391
diff
changeset
|
267 engine.audioRes->rdata, engine.audioRes->rdataSize, |
5137db55f00b
More work towards the editor ..
Matti Hamalainen <ccr@tnsp.org>
parents:
391
diff
changeset
|
268 engine.optAfmt.format, engine.optAfmt.channels, |
5137db55f00b
More work towards the editor ..
Matti Hamalainen <ccr@tnsp.org>
parents:
391
diff
changeset
|
269 engine.optAfmt.freq); |
5137db55f00b
More work towards the editor ..
Matti Hamalainen <ccr@tnsp.org>
parents:
391
diff
changeset
|
270 |
391 | 271 timelineAudioTrack->setOffset(currViewOffset); |
272 timelineAudioTrack->setScale(currViewScale); | |
393
5137db55f00b
More work towards the editor ..
Matti Hamalainen <ccr@tnsp.org>
parents:
391
diff
changeset
|
273 |
5137db55f00b
More work towards the editor ..
Matti Hamalainen <ccr@tnsp.org>
parents:
391
diff
changeset
|
274 if (currTimeline != NULL) |
5137db55f00b
More work towards the editor ..
Matti Hamalainen <ccr@tnsp.org>
parents:
391
diff
changeset
|
275 timelineView->setTrack(currTimeline->tl); |
5137db55f00b
More work towards the editor ..
Matti Hamalainen <ccr@tnsp.org>
parents:
391
diff
changeset
|
276 |
5137db55f00b
More work towards the editor ..
Matti Hamalainen <ccr@tnsp.org>
parents:
391
diff
changeset
|
277 timelineView->setTime(currFrameTime); |
5137db55f00b
More work towards the editor ..
Matti Hamalainen <ccr@tnsp.org>
parents:
391
diff
changeset
|
278 timelineView->setOffset(currViewOffset); |
5137db55f00b
More work towards the editor ..
Matti Hamalainen <ccr@tnsp.org>
parents:
391
diff
changeset
|
279 timelineView->setScale(currViewScale); |
391 | 280 |
281 timelineScrollBar->setRange(0, getTimelineDuration() - timelineAudioTrack->getScaledWidth()); | |
282 timelineScrollBar->setValue(currViewOffset); | |
283 } | |
284 | |
285 | |
286 void DemoEditor::actionTimelineScrollChanged(int value) | |
287 { | |
288 currViewOffset = value; | |
289 updateTimelineView(); | |
290 } | |
291 | |
292 | |
293 void DemoEditor::actionOffsetChanged(float value) | |
294 { | |
295 currViewOffset = value; | |
296 updateTimelineView(); | |
297 } | |
298 | |
299 | |
300 void DemoEditor::actionTimeChanged(float value) | |
301 { | |
302 currFrameTime = value; | |
303 updateTimelineView(); | |
384
e5220ff48bc8
Slowly working on the editor.
Matti Hamalainen <ccr@tnsp.org>
parents:
379
diff
changeset
|
304 } |
e5220ff48bc8
Slowly working on the editor.
Matti Hamalainen <ccr@tnsp.org>
parents:
379
diff
changeset
|
305 |
e5220ff48bc8
Slowly working on the editor.
Matti Hamalainen <ccr@tnsp.org>
parents:
379
diff
changeset
|
306 |
378 | 307 int DemoEditor::initEffectsAndResources() |
308 { | |
309 int err; | |
310 | |
391 | 311 currViewOffset = 0; |
312 currFrameTime = 0; | |
313 currViewScale = 1.0f; | |
314 | |
378 | 315 // Initialize resource subsystem |
384
e5220ff48bc8
Slowly working on the editor.
Matti Hamalainen <ccr@tnsp.org>
parents:
379
diff
changeset
|
316 statusMsg("Initializing resources subsystem."); |
378 | 317 if ((err = reopenResources()) != DMERR_OK) |
318 return err; | |
319 | |
320 // Load resources | |
384
e5220ff48bc8
Slowly working on the editor.
Matti Hamalainen <ccr@tnsp.org>
parents:
379
diff
changeset
|
321 statusMsg("Loading resources, please wait..."); |
378 | 322 if ((err = loadResources()) != DMERR_OK) |
323 { | |
324 dmError("Error loading resources, %d: %s.\n", err, dmErrorStr(err)); | |
325 return err; | |
326 } | |
327 | |
328 | |
329 // Final initializations | |
384
e5220ff48bc8
Slowly working on the editor.
Matti Hamalainen <ccr@tnsp.org>
parents:
379
diff
changeset
|
330 statusMsg("Initializing custom demo data."); |
378 | 331 if ((err = engine.demoInit(&engine)) != DMERR_OK) |
332 { | |
333 dmError("Failure in demoInit(), %d: %s\n", | |
334 err, dmErrorStr(err)); | |
335 return err; | |
336 } | |
337 | |
338 // Initialize effects | |
384
e5220ff48bc8
Slowly working on the editor.
Matti Hamalainen <ccr@tnsp.org>
parents:
379
diff
changeset
|
339 statusMsg("Initializing effects ..."); |
378 | 340 if ((err = engineInitializeEffects(&engine)) != DMERR_OK) |
341 { | |
342 dmError("Effects initialization failed, %d: %s\n", | |
343 err, dmErrorStr(err)); | |
344 return err; | |
345 } | |
346 | |
384
e5220ff48bc8
Slowly working on the editor.
Matti Hamalainen <ccr@tnsp.org>
parents:
379
diff
changeset
|
347 // Etc. |
e5220ff48bc8
Slowly working on the editor.
Matti Hamalainen <ccr@tnsp.org>
parents:
379
diff
changeset
|
348 |
e5220ff48bc8
Slowly working on the editor.
Matti Hamalainen <ccr@tnsp.org>
parents:
379
diff
changeset
|
349 updateTimelineView(); |
e5220ff48bc8
Slowly working on the editor.
Matti Hamalainen <ccr@tnsp.org>
parents:
379
diff
changeset
|
350 updateMenuStates(); |
e5220ff48bc8
Slowly working on the editor.
Matti Hamalainen <ccr@tnsp.org>
parents:
379
diff
changeset
|
351 update(); |
378 | 352 return DMERR_OK; |
353 } | |
354 | |
355 | |
356 void DemoEditor::shutdownEffectsAndResources() | |
357 { | |
376
40e33ad0d153
Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
358 dmFreeTimeline(engine.tl); |
40e33ad0d153
Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
359 dmFreePreparedTimelineData(engine.ptl); |
40e33ad0d153
Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
360 engineShutdownEffects(&engine); |
40e33ad0d153
Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
361 dmres_close(engine.resources); |
40e33ad0d153
Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
362 |
40e33ad0d153
Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
363 if (engine.demoShutdown != NULL) |
40e33ad0d153
Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
364 engine.demoShutdown(&engine); |
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 |
378 | 368 void DemoEditor::createNewFile() |
376
40e33ad0d153
Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
369 { |
378 | 370 delete tl; |
371 tl = new TimelineObject(); | |
372 | |
376
40e33ad0d153
Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
373 update(); |
40e33ad0d153
Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
374 historyReset(); |
40e33ad0d153
Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
375 changed = false; |
40e33ad0d153
Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
376 updateMenuStates(); |
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 |
40e33ad0d153
Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
380 void DemoEditor::readFromFile(QString filename) |
40e33ad0d153
Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
381 { |
378 | 382 TimelineObject *tmp = new TimelineObject(); |
376
40e33ad0d153
Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
383 int ret = tmp->load(filename); |
40e33ad0d153
Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
384 if (ret != DMERR_OK) |
40e33ad0d153
Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
385 { |
378 | 386 showFileErrorDialog("Loading demo blob file "+ filename, ret); |
376
40e33ad0d153
Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
387 delete tmp; |
40e33ad0d153
Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
388 } |
40e33ad0d153
Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
389 else |
40e33ad0d153
Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
390 { |
378 | 391 delete tl; |
392 tl = tmp; | |
393 | |
394 update(); | |
395 historyReset(); | |
396 changed = false; | |
397 updateMenuStates(); | |
376
40e33ad0d153
Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
398 } |
40e33ad0d153
Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
399 } |
40e33ad0d153
Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
400 |
40e33ad0d153
Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
401 |
40e33ad0d153
Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
402 void DemoEditor::saveToFile(QString filename) |
40e33ad0d153
Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
403 { |
378 | 404 int ret = tl->save(filename); |
376
40e33ad0d153
Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
405 if (ret != DMERR_OK) |
40e33ad0d153
Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
406 { |
378 | 407 showFileErrorDialog("Saving demo blob file "+ filename, ret); |
376
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 updateMenuStates(); |
40e33ad0d153
Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
411 } |
40e33ad0d153
Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
412 |
40e33ad0d153
Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
413 |
40e33ad0d153
Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
414 void DemoEditor::settingsRestore() |
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 QSettings s; |
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 restoreGeometry(s.value("windowGeometry").toByteArray()); |
40e33ad0d153
Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
419 restoreState(s.value("windowState").toByteArray()); |
40e33ad0d153
Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
420 |
40e33ad0d153
Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
421 } |
40e33ad0d153
Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
422 |
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 void DemoEditor::settingsSave() |
40e33ad0d153
Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
425 { |
40e33ad0d153
Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
426 QSettings s; |
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 s.setValue("windowGeometry", saveGeometry()); |
40e33ad0d153
Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
429 s.setValue("windowState", saveState()); |
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 // |
40e33ad0d153
Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
435 // Edit history functionality |
40e33ad0d153
Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
436 // |
40e33ad0d153
Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
437 void DemoEditor::historyReset() |
40e33ad0d153
Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
438 { |
40e33ad0d153
Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
439 changed = false; |
40e33ad0d153
Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
440 undoHistoryPos = -1; |
40e33ad0d153
Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
441 undoHistoryMax = DOC_UNDO_MAX; |
40e33ad0d153
Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
442 undoHistory.clear(); |
40e33ad0d153
Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
443 } |
40e33ad0d153
Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
444 |
40e33ad0d153
Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
445 |
40e33ad0d153
Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
446 void DemoEditor::historyPush(QString description) |
40e33ad0d153
Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
447 { |
40e33ad0d153
Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
448 if (!undoHistory.isEmpty() && undoHistory.last()->state == "-") |
40e33ad0d153
Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
449 { |
40e33ad0d153
Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
450 delete undoHistory.takeLast(); |
40e33ad0d153
Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
451 } |
40e33ad0d153
Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
452 |
40e33ad0d153
Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
453 while (undoHistory.size() >= undoHistoryMax) |
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 delete undoHistory.takeFirst(); |
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 |
393
5137db55f00b
More work towards the editor ..
Matti Hamalainen <ccr@tnsp.org>
parents:
391
diff
changeset
|
458 TimelineObject *copy = new TimelineObject(currTimeline); |
376
40e33ad0d153
Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
459 copy->state = description; |
40e33ad0d153
Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
460 undoHistory.append(copy); |
40e33ad0d153
Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
461 } |
40e33ad0d153
Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
462 |
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 void DemoEditor::historyTop() |
40e33ad0d153
Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
465 { |
393
5137db55f00b
More work towards the editor ..
Matti Hamalainen <ccr@tnsp.org>
parents:
391
diff
changeset
|
466 TimelineObject *copy = new TimelineObject(currTimeline); |
376
40e33ad0d153
Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
467 copy->state = "-"; |
40e33ad0d153
Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
468 undoHistory.append(copy); |
40e33ad0d153
Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
469 |
40e33ad0d153
Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
470 undoHistoryPos = undoHistory.size() - 1; |
40e33ad0d153
Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
471 changed = true; |
40e33ad0d153
Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
472 updateMenuStates(); |
40e33ad0d153
Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
473 update(); |
40e33ad0d153
Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
474 } |
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 void DemoEditor::historyPop() |
40e33ad0d153
Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
478 { |
40e33ad0d153
Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
479 if (!undoHistory.isEmpty()) |
40e33ad0d153
Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
480 { |
40e33ad0d153
Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
481 delete undoHistory.takeLast(); |
40e33ad0d153
Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
482 } |
40e33ad0d153
Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
483 } |
40e33ad0d153
Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
484 |
40e33ad0d153
Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
485 |
40e33ad0d153
Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
486 void DemoEditor::performRedo() |
40e33ad0d153
Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
487 { |
40e33ad0d153
Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
488 if (undoHistoryPos >= 0 && undoHistoryPos < undoHistory.size() - 1) |
40e33ad0d153
Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
489 { |
40e33ad0d153
Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
490 undoHistoryPos++; |
393
5137db55f00b
More work towards the editor ..
Matti Hamalainen <ccr@tnsp.org>
parents:
391
diff
changeset
|
491 delete currTimeline; |
5137db55f00b
More work towards the editor ..
Matti Hamalainen <ccr@tnsp.org>
parents:
391
diff
changeset
|
492 currTimeline = new TimelineObject(undoHistory.at(undoHistoryPos)); |
376
40e33ad0d153
Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
493 changed = true; |
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 updateMenuStates(); |
40e33ad0d153
Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
496 update(); |
40e33ad0d153
Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
497 } |
40e33ad0d153
Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
498 } |
40e33ad0d153
Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
499 |
40e33ad0d153
Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
500 |
40e33ad0d153
Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
501 void DemoEditor::performUndo() |
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 if (undoHistoryPos > 0 && undoHistory.size() > 1) |
40e33ad0d153
Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
504 { |
40e33ad0d153
Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
505 undoHistoryPos--; |
393
5137db55f00b
More work towards the editor ..
Matti Hamalainen <ccr@tnsp.org>
parents:
391
diff
changeset
|
506 delete currTimeline; |
5137db55f00b
More work towards the editor ..
Matti Hamalainen <ccr@tnsp.org>
parents:
391
diff
changeset
|
507 currTimeline = new TimelineObject(undoHistory.at(undoHistoryPos)); |
376
40e33ad0d153
Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
508 changed = true; |
40e33ad0d153
Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
509 |
40e33ad0d153
Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
510 updateMenuStates(); |
40e33ad0d153
Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
511 update(); |
40e33ad0d153
Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
512 } |
40e33ad0d153
Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
513 } |