annotate tools/auval.c @ 1327:59e9ad13b50e

Move common functions to libgutil.
author Matti Hamalainen <ccr@tnsp.org>
date Tue, 22 Aug 2017 13:18:21 +0300
parents 2260ed90ab6b
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
690
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1 #include "dmlib.h"
1327
59e9ad13b50e Move common functions to libgutil.
Matti Hamalainen <ccr@tnsp.org>
parents: 1323
diff changeset
2 #include "libgutil.h"
690
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
3 #include "dmargs.h"
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
4 #include "dmeval.h"
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
5 #include "dmtext.h"
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
6 #include <math.h>
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
7
1327
59e9ad13b50e Move common functions to libgutil.
Matti Hamalainen <ccr@tnsp.org>
parents: 1323
diff changeset
8
690
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
9 #define AUVAL_NAME "AuVal"
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
10 #define AUVAL_VERSION "0.6"
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
11 #define AUVAL_TMPBUF_SIZE (4096)
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
12 #define AUVAL_HISTORY_FILE "history.txt"
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
13 #define AUVAL_HISTORY_USER "formulas.txt"
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
14 #define SDL_NCOLORS 256
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
15
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
16
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
17 enum
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
18 {
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
19 REDRAW_VISUALIZER = 0x00000001,
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
20 REDRAW_EDITOR = 0x00000002,
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
21 REDRAW_INFO = 0x00000004,
867
56e12109b936 Portability warning fixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 860
diff changeset
22 REDRAW_ALL = 0x0fffffff,
690
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
23 };
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
24
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
25
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
26 typedef struct
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
27 {
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
28 DMEvalNode *expr;
761
7be7c7c5deaa Large cleanup, breaking everything. Yay.
Matti Hamalainen <ccr@tnsp.org>
parents: 760
diff changeset
29 DMEvalContext *ctx;
1235
5b8245e5f785 Remove trailing whitespace.
Matti Hamalainen <ccr@tnsp.org>
parents: 1167
diff changeset
30
690
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
31 double varTime, varFreq, varKeyTime,
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
32 varKeyTimeRev, varKeyFreq, varUnit;
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
33
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
34 int avail, bufsize, pos, oldpos;
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
35 Uint8 *buf;
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
36
760
d345a898bda1 Use DMMutex and the appropriate function wrappers.
Matti Hamalainen <ccr@tnsp.org>
parents: 710
diff changeset
37 DMMutex *mutex;
690
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
38 } AUAudioData;
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
39
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
40
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
41 char *optFontFile = "font.ttf";
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
42
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
43 int optVFlags = SDL_SWSURFACE | SDL_HWPALETTE,
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
44 optScrWidth = 640,
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
45 optScrHeight = 480,
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
46 optScrDepth = 32,
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
47 optFontSize = 20,
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
48 optAudioFreq = 44100,
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
49 optBMPSize = 32,
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
50 optHistoryLen = 64;
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
51
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
52 BOOL optClipping = TRUE,
705
39c03b7dd853 Remove some remnants of Lua mode.
Matti Hamalainen <ccr@tnsp.org>
parents: 691
diff changeset
53 optScale = TRUE;
690
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
54
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
55
860
daebbf28953d The argument handling API in dmargs* was synced with th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents: 761
diff changeset
56 static const DMOptArg optList[] =
daebbf28953d The argument handling API in dmargs* was synced with th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents: 761
diff changeset
57 {
690
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
58 { 0, '?', "help", "Show this help", OPT_NONE },
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
59 { 2, 'v', "verbose", "Be more verbose", OPT_NONE },
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
60 { 3, 0, "fs", "Fullscreen", OPT_NONE },
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
61 { 5, 's', "size", "Initial window size/resolution -s 640x480", OPT_ARGREQ },
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
62 { 6, 'd', "depth", "Color depth of mode/window in bits (8/15/16/32)", OPT_ARGREQ },
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
63 { 7, 'f', "freq", "Audio output frequency", OPT_ARGREQ },
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
64 { 8, 'b', "bmpsize", "Bitmap size", OPT_ARGREQ },
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
65
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
66 {10, 'n', "noclip", "Disable clipping by default", OPT_NONE },
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
67 {11, 'r', "range", "Use range [0, 255] instead of [0.0, 1.0]", OPT_NONE },
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
68 };
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
69
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
70 const int optListN = sizeof(optList) / sizeof(optList[0]);
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
71
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
72
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
73 void argShowHelp()
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
74 {
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
75 printf("%s v%s\n(C) Copyright 2011 ccr/TNSP\n", AUVAL_NAME, AUVAL_VERSION);
860
daebbf28953d The argument handling API in dmargs* was synced with th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents: 761
diff changeset
76 dmArgsPrintHelp(stdout, optList, optListN, 0);
690
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
77 }
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
78
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
79
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
80 BOOL argHandleOpt(const int optN, char *optArg, char *currArg)
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
81 {
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
82 switch (optN) {
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
83 case 0:
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
84 argShowHelp();
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
85 exit(0);
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
86 break;
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
87
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
88 case 2:
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
89 dmVerbosity++;
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
90 break;
1235
5b8245e5f785 Remove trailing whitespace.
Matti Hamalainen <ccr@tnsp.org>
parents: 1167
diff changeset
91
690
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
92 case 3:
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
93 optVFlags |= SDL_FULLSCREEN;
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
94 break;
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
95
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
96 case 5:
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
97 if (optArg)
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
98 {
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
99 int w, h;
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
100 if (sscanf(optArg, "%dx%d", &w, &h) == 2)
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
101 {
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
102 if (w < 320 || h < 200 || w > 3200 || h > 3200)
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
103 {
958
985225a93aeb Add error code parameter to dmError() and dmErrorVA().
Matti Hamalainen <ccr@tnsp.org>
parents: 867
diff changeset
104 dmErrorMsg("Invalid width or height: %d x %d\n", w, h);
690
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
105 return FALSE;
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
106 }
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
107 optScrWidth = w;
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
108 optScrHeight = h;
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
109 }
1235
5b8245e5f785 Remove trailing whitespace.
Matti Hamalainen <ccr@tnsp.org>
parents: 1167
diff changeset
110 else
690
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
111 {
958
985225a93aeb Add error code parameter to dmError() and dmErrorVA().
Matti Hamalainen <ccr@tnsp.org>
parents: 867
diff changeset
112 dmErrorMsg("Invalid size argument '%s'.\n", optArg);
690
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
113 return FALSE;
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
114 }
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
115 }
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
116 else
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
117 {
958
985225a93aeb Add error code parameter to dmError() and dmErrorVA().
Matti Hamalainen <ccr@tnsp.org>
parents: 867
diff changeset
118 dmErrorMsg("Dimensions option %s requires an argument.\n", currArg);
690
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
119 }
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
120 break;
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
121
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
122 case 6:
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
123 optScrDepth = atoi(optArg);
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
124 break;
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
125
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
126 case 7:
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
127 {
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
128 int tmp = atoi(optArg);
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
129 if (tmp < 4000 || tmp > 96000)
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
130 {
958
985225a93aeb Add error code parameter to dmError() and dmErrorVA().
Matti Hamalainen <ccr@tnsp.org>
parents: 867
diff changeset
131 dmErrorMsg("Invalid audio frequency '%s'.\n", optArg);
690
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
132 return FALSE;
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
133 }
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
134 optAudioFreq = tmp;
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
135 }
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
136 break;
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
137
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
138 case 8:
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
139 {
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
140 int tmp = atoi(optArg);
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
141 if (tmp < 32 || tmp > 512)
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
142 {
958
985225a93aeb Add error code parameter to dmError() and dmErrorVA().
Matti Hamalainen <ccr@tnsp.org>
parents: 867
diff changeset
143 dmErrorMsg("Invalid bitmap size '%s'.\n", optArg);
690
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
144 return FALSE;
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
145 }
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
146 optBMPSize = tmp;
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
147 }
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
148 break;
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
149
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
150 case 10:
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
151 optClipping = FALSE;
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
152 break;
1235
5b8245e5f785 Remove trailing whitespace.
Matti Hamalainen <ccr@tnsp.org>
parents: 1167
diff changeset
153
690
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
154 case 11:
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
155 optScale = FALSE;
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
156 break;
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
157
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
158 default:
958
985225a93aeb Add error code parameter to dmError() and dmErrorVA().
Matti Hamalainen <ccr@tnsp.org>
parents: 867
diff changeset
159 dmErrorMsg("Unknown option '%s'.\n", currArg);
690
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
160 return FALSE;
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
161 }
1235
5b8245e5f785 Remove trailing whitespace.
Matti Hamalainen <ccr@tnsp.org>
parents: 1167
diff changeset
162
690
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
163 return TRUE;
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
164 }
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
165
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
166
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
167 typedef struct
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
168 {
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
169 ssize_t pos, len, size;
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
170 char *data;
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
171 BOOL dirty;
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
172 } AUEditBuf;
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
173
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
174
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
175 int au_editbuf_write(AUEditBuf *buf, ssize_t pos, int ch)
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
176 {
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
177 if (buf->len+1 >= buf->size) return -3;
1235
5b8245e5f785 Remove trailing whitespace.
Matti Hamalainen <ccr@tnsp.org>
parents: 1167
diff changeset
178
690
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
179 if (pos < 0)
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
180 return -1;
1323
2260ed90ab6b Remove dmgfx and move the functions used to PPL and Auval.
Matti Hamalainen <ccr@tnsp.org>
parents: 1235
diff changeset
181 else
2260ed90ab6b Remove dmgfx and move the functions used to PPL and Auval.
Matti Hamalainen <ccr@tnsp.org>
parents: 1235
diff changeset
182 if (pos >= buf->len)
690
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
183 buf->data[buf->len++] = ch;
1323
2260ed90ab6b Remove dmgfx and move the functions used to PPL and Auval.
Matti Hamalainen <ccr@tnsp.org>
parents: 1235
diff changeset
184 else
690
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
185 buf->data[pos] = ch;
1323
2260ed90ab6b Remove dmgfx and move the functions used to PPL and Auval.
Matti Hamalainen <ccr@tnsp.org>
parents: 1235
diff changeset
186
690
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
187 buf->dirty = TRUE;
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
188 return 0;
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
189 }
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
190
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
191
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
192 int au_editbuf_insert(AUEditBuf *buf, ssize_t pos, int ch)
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
193 {
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
194 if (buf->len+1 >= buf->size) return -3;
1235
5b8245e5f785 Remove trailing whitespace.
Matti Hamalainen <ccr@tnsp.org>
parents: 1167
diff changeset
195
690
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
196 if (pos < 0)
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
197 return -1;
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
198 else if (pos >= buf->len) {
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
199 buf->data[buf->len] = ch;
1323
2260ed90ab6b Remove dmgfx and move the functions used to PPL and Auval.
Matti Hamalainen <ccr@tnsp.org>
parents: 1235
diff changeset
200 }
2260ed90ab6b Remove dmgfx and move the functions used to PPL and Auval.
Matti Hamalainen <ccr@tnsp.org>
parents: 1235
diff changeset
201 else
2260ed90ab6b Remove dmgfx and move the functions used to PPL and Auval.
Matti Hamalainen <ccr@tnsp.org>
parents: 1235
diff changeset
202 {
690
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
203 memmove(&(buf->data[pos+1]), &(buf->data[pos]), buf->len - pos + 1);
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
204 buf->data[pos] = ch;
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
205 }
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
206 buf->len++;
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
207 buf->dirty = TRUE;
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
208 return 0;
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
209 }
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
210
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
211
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
212 int au_editbuf_delete(AUEditBuf *buf, ssize_t pos)
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
213 {
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
214 if (pos < 0)
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
215 return -1;
1323
2260ed90ab6b Remove dmgfx and move the functions used to PPL and Auval.
Matti Hamalainen <ccr@tnsp.org>
parents: 1235
diff changeset
216 else
2260ed90ab6b Remove dmgfx and move the functions used to PPL and Auval.
Matti Hamalainen <ccr@tnsp.org>
parents: 1235
diff changeset
217 if (pos < buf->len)
2260ed90ab6b Remove dmgfx and move the functions used to PPL and Auval.
Matti Hamalainen <ccr@tnsp.org>
parents: 1235
diff changeset
218 {
690
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
219 memmove(&(buf->data[pos]), &(buf->data[pos+1]), buf->len - pos);
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
220 buf->len--;
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
221 buf->dirty = TRUE;
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
222 return 0;
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
223 } else
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
224 return -2;
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
225 }
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
226
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
227
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
228 void au_editbuf_clear(AUEditBuf *buf)
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
229 {
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
230 buf->len = 0;
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
231 buf->pos = 0;
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
232 buf->dirty = TRUE;
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
233 }
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
234
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
235
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
236 AUEditBuf * au_editbuf_new(ssize_t n)
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
237 {
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
238 AUEditBuf *res = dmCalloc(1, sizeof(AUEditBuf));
1235
5b8245e5f785 Remove trailing whitespace.
Matti Hamalainen <ccr@tnsp.org>
parents: 1167
diff changeset
239
690
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
240 res->data = (char *) dmMalloc(n);
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
241 res->size = n;
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
242 res->dirty = TRUE;
1235
5b8245e5f785 Remove trailing whitespace.
Matti Hamalainen <ccr@tnsp.org>
parents: 1167
diff changeset
243
690
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
244 return res;
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
245 }
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
246
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
247 AUEditBuf * au_editbuf_new_str(ssize_t n, const char *str)
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
248 {
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
249 AUEditBuf *res = au_editbuf_new(n);
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
250 strncpy(res->data, str, res->size);
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
251 res->data[res->size - 1] = 0;
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
252 res->pos = res->len = strlen(res->data);
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
253 return res;
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
254 }
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
255
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
256
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
257 void au_editbuf_free(AUEditBuf *buf)
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
258 {
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
259 if (buf != NULL)
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
260 {
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
261 dmFree(buf->data);
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
262 dmFree(buf);
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
263 }
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
264 }
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
265
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
266
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
267 AUEditBuf * au_editbuf_copy(AUEditBuf *src)
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
268 {
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
269 AUEditBuf *res;
1235
5b8245e5f785 Remove trailing whitespace.
Matti Hamalainen <ccr@tnsp.org>
parents: 1167
diff changeset
270
690
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
271 if (src == NULL) return NULL;
1235
5b8245e5f785 Remove trailing whitespace.
Matti Hamalainen <ccr@tnsp.org>
parents: 1167
diff changeset
272
690
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
273 if ((res = au_editbuf_new(src->size)) == NULL)
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
274 return NULL;
1235
5b8245e5f785 Remove trailing whitespace.
Matti Hamalainen <ccr@tnsp.org>
parents: 1167
diff changeset
275
690
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
276 memcpy(res->data, src->data, src->size);
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
277 res->pos = res->len = src->len;
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
278 res->dirty = TRUE;
1235
5b8245e5f785 Remove trailing whitespace.
Matti Hamalainen <ccr@tnsp.org>
parents: 1167
diff changeset
279
690
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
280 return res;
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
281 }
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
282
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
283
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
284 char * au_editbuf_get_string(AUEditBuf *buf, ssize_t start, ssize_t end)
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
285 {
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
286 char *str;
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
287 ssize_t siz;
1235
5b8245e5f785 Remove trailing whitespace.
Matti Hamalainen <ccr@tnsp.org>
parents: 1167
diff changeset
288
690
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
289 if (buf == NULL)
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
290 return NULL;
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
291
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
292 if (start < 0 || end > buf->len || start >= buf->len)
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
293 return NULL;
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
294
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
295 if (end < 0) {
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
296 siz = buf->len - start + 1;
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
297 } else if (start <= end) {
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
298 siz = end - start + 1;
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
299 } else
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
300 return NULL;
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
301
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
302 if ((str = dmMalloc(siz + 1)) == NULL)
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
303 return NULL;
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
304
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
305 memcpy(str, buf->data + start, siz);
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
306 str[siz] = 0;
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
307
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
308 return str;
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
309 }
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
310
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
311
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
312 void au_editbuf_setpos(AUEditBuf *buf, ssize_t pos)
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
313 {
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
314 if (pos < 0)
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
315 buf->pos = 0;
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
316 else if (pos >= buf->len)
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
317 buf->pos = buf->len;
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
318 else
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
319 buf->pos = pos;
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
320 }
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
321
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
322
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
323 BOOL au_init_video(SDL_Surface **screen)
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
324 {
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
325 *screen = SDL_SetVideoMode(optScrWidth, optScrHeight, optScrDepth, optVFlags | SDL_RESIZABLE);
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
326 if (*screen == NULL)
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
327 {
958
985225a93aeb Add error code parameter to dmError() and dmErrorVA().
Matti Hamalainen <ccr@tnsp.org>
parents: 867
diff changeset
328 dmErrorMsg("Can't SDL_SetVideoMode(): %s\n", SDL_GetError());
690
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
329 return FALSE;
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
330 }
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
331
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
332 return TRUE;
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
333 }
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
334
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
335
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
336 void au_draw_editbuf(SDL_Surface *screen, TTF_Font *font, SDL_Color col,
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
337 int xc, int yc, int w, int h, AUEditBuf *buf, int curcol)
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
338 {
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
339 ssize_t left, maxlen, pos;
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
340 int strw, strh, y1 = yc + h;
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
341 char *line = NULL, *ptr;
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
342
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
343 if (buf == NULL)
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
344 return;
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
345
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
346 if (TTF_SizeText(font, "X", &strw, &strh) != 0)
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
347 goto error;
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
348
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
349 maxlen = w / strw;
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
350 line = dmMalloc(maxlen + 2);
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
351 pos = 0;
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
352 left = buf->len;
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
353 ptr = buf->data;
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
354
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
355 do
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
356 {
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
357 ssize_t ppos = buf->pos - pos;
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
358 if (ppos >= 0 && ppos < maxlen)
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
359 {
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
360 int x0 = xc + ppos * strw;
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
361 dmFillRect(screen, x0, yc, x0 + strw, yc + strh, curcol);
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
362 }
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
363 else
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
364 if ((buf->pos % maxlen) == 0)
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
365 {
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
366 dmFillRect(screen, xc, yc + strh, xc + strw, yc + strh + strh, curcol);
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
367 }
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
368
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
369 ssize_t len = left > maxlen ? maxlen : left;
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
370 strncpy(line, ptr, len);
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
371 line[len] = 0;
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
372
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
373 dmDrawTTFTextConst(screen, font, col, xc, yc, line);
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
374
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
375 left -= len;
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
376 ptr += len;
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
377 pos += len;
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
378
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
379 yc += strh;
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
380 }
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
381 while (left > 0 && yc < y1);
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
382
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
383
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
384 error:
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
385 dmFree(line);
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
386 }
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
387
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
388
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
389 void au_vis_wave(SDL_Surface *screen, int x0, int y0, int x1, int y1, AUAudioData *data)
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
390 {
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
391 int x, offs;
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
392 const int height = y1 - y0, center = y0 + (height / 2);
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
393 const int pitch = screen->pitch, bpp = screen->format->BytesPerPixel;
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
394 const int xend = x1 * bpp;
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
395 const float scale = 128.0f / (float) height;
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
396
760
d345a898bda1 Use DMMutex and the appropriate function wrappers.
Matti Hamalainen <ccr@tnsp.org>
parents: 710
diff changeset
397 dmMutexLock(data->mutex);
690
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
398
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
399 Uint8 *dp = data->buf,
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
400 *sp = screen->pixels;
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
401
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
402 for (offs = 0, x = x0 * bpp; x < xend && offs < data->avail; x += bpp, offs++)
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
403 {
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
404 const int curr = center + ((dp[offs] - 128) * scale);
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
405 sp[x + curr * pitch] = 255;
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
406 }
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
407
760
d345a898bda1 Use DMMutex and the appropriate function wrappers.
Matti Hamalainen <ccr@tnsp.org>
parents: 710
diff changeset
408 dmMutexUnlock(data->mutex);
690
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
409 }
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
410
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
411
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
412 void au_vis_image(SDL_Surface *screen, AUAudioData *data)
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
413 {
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
414 int y;
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
415 Uint8 *p = (Uint8 *) screen->pixels;
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
416
760
d345a898bda1 Use DMMutex and the appropriate function wrappers.
Matti Hamalainen <ccr@tnsp.org>
parents: 710
diff changeset
417 dmMutexLock(data->mutex);
690
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
418
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
419 Uint8 *dp = data->buf;
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
420
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
421 for (y = 0; y < screen->h; y++)
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
422 {
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
423 int x;
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
424 for (x = 0; x < screen->w; x++)
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
425 *p++ = *dp++;
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
426
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
427 p += screen->pitch - screen->w;
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
428 }
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
429
760
d345a898bda1 Use DMMutex and the appropriate function wrappers.
Matti Hamalainen <ccr@tnsp.org>
parents: 710
diff changeset
430 dmMutexUnlock(data->mutex);
690
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
431 }
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
432
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
433
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
434 int au_get_note_from_key(SDL_keysym *key, int octave)
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
435 {
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
436 int note;
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
437
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
438 switch (key->sym)
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
439 {
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
440 case SDLK_z: note = 1; break;
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
441 case SDLK_s: note = 2; break;
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
442 case SDLK_x: note = 3; break;
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
443 case SDLK_d: note = 4; break;
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
444 case SDLK_c: note = 5; break;
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
445 case SDLK_v: note = 6; break;
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
446 case SDLK_g: note = 7; break;
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
447 case SDLK_b: note = 8; break;
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
448 case SDLK_h: note = 9; break;
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
449 case SDLK_n: note = 10; break;
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
450 case SDLK_j: note = 11; break;
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
451 case SDLK_m: note = 12; break;
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
452
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
453 case SDLK_q: note = 13; break;
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
454 case SDLK_2: note = 14; break;
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
455 case SDLK_w: note = 15; break;
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
456 case SDLK_3: note = 16; break;
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
457 case SDLK_e: note = 17; break;
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
458 case SDLK_r: note = 18; break;
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
459 case SDLK_5: note = 19; break;
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
460 case SDLK_t: note = 20; break;
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
461 case SDLK_6: note = 21; break;
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
462 case SDLK_y: note = 22; break;
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
463 case SDLK_7: note = 23; break;
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
464 case SDLK_u: note = 24; break;
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
465 case SDLK_i: note = 25; break;
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
466 case SDLK_9: note = 26; break;
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
467 case SDLK_o: note = 27; break;
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
468 case SDLK_0: note = 28; break;
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
469 case SDLK_p: note = 29; break;
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
470
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
471 default: return -1;
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
472 }
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
473
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
474 note += 12 * octave;
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
475 return (note < 1) ? 1 : (note > 120 ? 120 : note);
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
476 }
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
477
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
478
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
479 void au_adjust_value(int *val, int min, int max, int delta)
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
480 {
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
481 *val += delta;
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
482 if (*val < min) *val = min;
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
483 else if (*val > max) *val = max;
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
484 }
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
485
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
486
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
487 int au_read_history(const char *filename, AUEditBuf **history, int maxHistory, int *histMax)
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
488 {
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
489 char tmpStr[1024];
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
490 int i;
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
491
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
492 FILE *f = fopen(filename, "r");
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
493 if (f == NULL)
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
494 {
958
985225a93aeb Add error code parameter to dmError() and dmErrorVA().
Matti Hamalainen <ccr@tnsp.org>
parents: 867
diff changeset
495 dmErrorMsg("Could not open input file '%s'.\n", filename);
690
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
496 return -1;
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
497 }
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
498
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
499 while (fgets(tmpStr, sizeof(tmpStr), f) != NULL)
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
500 {
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
501 /* Strip the string end from linefeeds etc. */
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
502 for (i = 0; tmpStr[i] != 0 && i < 512; i++);
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
503 while (--i >= 0 && (tmpStr[i] == '\n' || tmpStr[i] == '\r' || isspace(tmpStr[i])))
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
504 tmpStr[i] = 0;
1235
5b8245e5f785 Remove trailing whitespace.
Matti Hamalainen <ccr@tnsp.org>
parents: 1167
diff changeset
505
690
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
506 /* Add to history only if it's not an empty line */
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
507 if (tmpStr[0] != 0)
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
508 {
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
509 au_editbuf_free(history[maxHistory + 1]);
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
510 history[maxHistory + 1] = NULL;
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
511 memmove(&history[2], &history[1], maxHistory * sizeof(history[0]));
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
512
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
513 history[1] = au_editbuf_new_str(AUVAL_TMPBUF_SIZE, tmpStr);
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
514
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
515 if (*histMax < maxHistory)
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
516 (*histMax)++;
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
517 }
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
518 }
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
519
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
520 fclose(f);
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
521 return 0;
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
522 }
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
523
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
524
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
525 int au_save_history(const char *filename, AUEditBuf **history, int histMax)
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
526 {
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
527 int i;
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
528
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
529 FILE *f = fopen(filename, "w");
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
530 if (f == NULL)
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
531 {
958
985225a93aeb Add error code parameter to dmError() and dmErrorVA().
Matti Hamalainen <ccr@tnsp.org>
parents: 867
diff changeset
532 dmErrorMsg("Could not create output file '%s'.\n", filename);
690
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
533 return -1;
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
534 }
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
535
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
536 for (i = histMax; i >= 0; i--)
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
537 {
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
538 AUEditBuf *buf = history[i];
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
539 if (buf != NULL)
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
540 {
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
541 buf->data[buf->len] = 0;
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
542 fprintf(f, "%s\n", buf->data);
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
543 }
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
544 }
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
545
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
546 fclose(f);
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
547 return 0;
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
548 }
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
549
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
550
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
551 /* SDL audio callback. We do the actual rendering here, by setting
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
552 * Lua variables and calling Lua evaluation function to generate samples.
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
553 *
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
554 * Mutex locking is used to ensure that the variables are not improperly
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
555 * accessed.
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
556 */
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
557 void au_sdl_audio_fill(void *udata, Uint8 *buf, int len)
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
558 {
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
559 AUAudioData *data = (AUAudioData *) udata;
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
560
760
d345a898bda1 Use DMMutex and the appropriate function wrappers.
Matti Hamalainen <ccr@tnsp.org>
parents: 710
diff changeset
561 dmMutexLock(data->mutex);
1235
5b8245e5f785 Remove trailing whitespace.
Matti Hamalainen <ccr@tnsp.org>
parents: 1167
diff changeset
562
690
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
563 data->avail = 0;
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
564
761
7be7c7c5deaa Large cleanup, breaking everything. Yay.
Matti Hamalainen <ccr@tnsp.org>
parents: 760
diff changeset
565 if (!data->ctx->err)
690
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
566 {
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
567 while (data->avail < len && data->avail < data->bufsize)
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
568 {
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
569 double value;
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
570
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
571 data->varKeyTimeRev = 1.0f - data->varKeyTime;
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
572
761
7be7c7c5deaa Large cleanup, breaking everything. Yay.
Matti Hamalainen <ccr@tnsp.org>
parents: 760
diff changeset
573 if (dmEvalTreeExecute(data->ctx, data->expr, &value) != 0)
690
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
574 break;
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
575
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
576 if (optScale)
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
577 {
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
578 if (optClipping)
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
579 value = ((value < -1.0f) ? -1.0f : ((value > 1.0f) ? 1.0f : value));
1235
5b8245e5f785 Remove trailing whitespace.
Matti Hamalainen <ccr@tnsp.org>
parents: 1167
diff changeset
580
690
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
581 value = 128 + (value * 126);
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
582 }
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
583 else
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
584 {
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
585 if (optClipping)
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
586 value = ((value < 0) ? 0 : ((value > 255) ? 255 : value));
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
587 }
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
588
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
589 data->buf[data->avail++] = value;
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
590
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
591 data->varTime += data->varFreq;
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
592 data->varUnit += data->varKeyFreq;
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
593
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
594 data->varKeyTime += data->varKeyFreq;
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
595 if (data->varKeyTime > 1.0f)
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
596 data->varKeyTime = 1.0f;
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
597 }
1235
5b8245e5f785 Remove trailing whitespace.
Matti Hamalainen <ccr@tnsp.org>
parents: 1167
diff changeset
598
761
7be7c7c5deaa Large cleanup, breaking everything. Yay.
Matti Hamalainen <ccr@tnsp.org>
parents: 760
diff changeset
599 if (data->avail >= len && !data->ctx->err)
690
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
600 {
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
601 memcpy(buf, data->buf, len);
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
602 data->pos += len;
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
603 }
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
604 else
1167
848a88ce7a57 Use dmMemset().
Matti Hamalainen <ccr@tnsp.org>
parents: 958
diff changeset
605 dmMemset(buf, 0, len);
690
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
606 }
1235
5b8245e5f785 Remove trailing whitespace.
Matti Hamalainen <ccr@tnsp.org>
parents: 1167
diff changeset
607
760
d345a898bda1 Use DMMutex and the appropriate function wrappers.
Matti Hamalainen <ccr@tnsp.org>
parents: 710
diff changeset
608 dmMutexUnlock(data->mutex);
690
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
609 }
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
610
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
611
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
612 int main(int argc, char *argv[])
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
613 {
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
614 AUEditBuf *editBuf = au_editbuf_new(AUVAL_TMPBUF_SIZE);
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
615 AUEditBuf **histBuf = NULL;
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
616 int histPos = 0, histMax = 0, viewMode;
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
617 SDL_Surface *screen = NULL, *bmp = NULL;
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
618 TTF_Font *font = NULL;
860
daebbf28953d The argument handling API in dmargs* was synced with th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents: 761
diff changeset
619 SDL_Color fontcol = {255,255,255, 0};
690
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
620 SDL_Event event;
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
621 SDL_AudioSpec fmt;
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
622 AUAudioData audata;
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
623 int needRedraw;
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
624 BOOL initSDL = FALSE, initTTF = FALSE, exitFlag,
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
625 insertMode, audioPlaying = FALSE, jazzMode;
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
626
1167
848a88ce7a57 Use dmMemset().
Matti Hamalainen <ccr@tnsp.org>
parents: 958
diff changeset
627 dmMemset(&audata, 0, sizeof(audata));
690
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
628
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
629 /* Parse arguments */
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
630 if (!dmArgsProcess(argc, argv, optList, optListN,
860
daebbf28953d The argument handling API in dmargs* was synced with th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents: 761
diff changeset
631 argHandleOpt, NULL, 0))
690
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
632 exit(1);
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
633
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
634
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
635 /* Allocate edit history buffers */
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
636 histBuf = dmCalloc(sizeof(histBuf[0]), optHistoryLen + 2);
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
637 if (histBuf == NULL)
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
638 {
958
985225a93aeb Add error code parameter to dmError() and dmErrorVA().
Matti Hamalainen <ccr@tnsp.org>
parents: 867
diff changeset
639 dmErrorMsg("Could not allocate memory for edit history buffer!\n");
690
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
640 goto error_exit;
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
641 }
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
642
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
643
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
644 /* Read in history file, if any exists */
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
645 au_read_history(AUVAL_HISTORY_FILE, histBuf, optHistoryLen, &histMax);
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
646
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
647
761
7be7c7c5deaa Large cleanup, breaking everything. Yay.
Matti Hamalainen <ccr@tnsp.org>
parents: 760
diff changeset
648 /* Initialize evaluator ctx */
7be7c7c5deaa Large cleanup, breaking everything. Yay.
Matti Hamalainen <ccr@tnsp.org>
parents: 760
diff changeset
649 audata.ctx = dmEvalContextNew();
690
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
650 audata.expr = NULL;
1235
5b8245e5f785 Remove trailing whitespace.
Matti Hamalainen <ccr@tnsp.org>
parents: 1167
diff changeset
651
761
7be7c7c5deaa Large cleanup, breaking everything. Yay.
Matti Hamalainen <ccr@tnsp.org>
parents: 760
diff changeset
652 dmEvalContextAddVar(audata.ctx, "t", &audata.varTime);
7be7c7c5deaa Large cleanup, breaking everything. Yay.
Matti Hamalainen <ccr@tnsp.org>
parents: 760
diff changeset
653 dmEvalContextAddVar(audata.ctx, "k", &audata.varKeyTime);
7be7c7c5deaa Large cleanup, breaking everything. Yay.
Matti Hamalainen <ccr@tnsp.org>
parents: 760
diff changeset
654 dmEvalContextAddVar(audata.ctx, "q", &audata.varKeyTimeRev);
7be7c7c5deaa Large cleanup, breaking everything. Yay.
Matti Hamalainen <ccr@tnsp.org>
parents: 760
diff changeset
655 dmEvalContextAddVar(audata.ctx, "f", &audata.varUnit);
690
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
656
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
657
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
658 /* Initialize SDL */
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
659 if (SDL_Init(SDL_INIT_VIDEO | SDL_INIT_TIMER | SDL_INIT_AUDIO) != 0)
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
660 {
958
985225a93aeb Add error code parameter to dmError() and dmErrorVA().
Matti Hamalainen <ccr@tnsp.org>
parents: 867
diff changeset
661 dmErrorMsg("Could not initialize SDL: %s\n", SDL_GetError());
690
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
662 goto error_exit;
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
663 }
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
664 initSDL = TRUE;
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
665
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
666 if (TTF_Init() < 0)
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
667 {
958
985225a93aeb Add error code parameter to dmError() and dmErrorVA().
Matti Hamalainen <ccr@tnsp.org>
parents: 867
diff changeset
668 dmErrorMsg("Could not initialize FreeType/TTF: %s\n", SDL_GetError());
690
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
669 goto error_exit;
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
670 }
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
671 initTTF = TRUE;
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
672
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
673 font = TTF_OpenFont(optFontFile, optFontSize);
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
674 if (font == NULL)
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
675 {
958
985225a93aeb Add error code parameter to dmError() and dmErrorVA().
Matti Hamalainen <ccr@tnsp.org>
parents: 867
diff changeset
676 dmErrorMsg("Could not load TTF font '%s' (%d): %s\n",
690
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
677 optFontFile, optFontSize, SDL_GetError());
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
678 goto error_exit;
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
679 }
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
680 TTF_SetFontStyle(font, TTF_STYLE_NORMAL);
1235
5b8245e5f785 Remove trailing whitespace.
Matti Hamalainen <ccr@tnsp.org>
parents: 1167
diff changeset
681
690
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
682 if (!au_init_video(&screen))
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
683 goto error_exit;
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
684
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
685 SDL_WM_SetCaption(AUVAL_NAME " v" AUVAL_VERSION, AUVAL_NAME);
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
686
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
687 SDL_EnableUNICODE(1);
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
688 SDL_EnableKeyRepeat(SDL_DEFAULT_REPEAT_DELAY, SDL_DEFAULT_REPEAT_INTERVAL);
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
689
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
690
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
691 /* Initialize audio */
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
692 fmt.freq = optAudioFreq;
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
693 fmt.format = AUDIO_U8;
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
694 fmt.channels = 1;
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
695 fmt.samples = 512;
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
696 fmt.callback = au_sdl_audio_fill;
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
697 fmt.userdata = &audata;
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
698
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
699 if (SDL_OpenAudio(&fmt, NULL) < 0)
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
700 {
958
985225a93aeb Add error code parameter to dmError() and dmErrorVA().
Matti Hamalainen <ccr@tnsp.org>
parents: 867
diff changeset
701 dmErrorMsg("Could not initialize SDL audio.\n");
690
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
702 goto error_exit;
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
703 }
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
704
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
705 audata.bufsize = optAudioFreq;
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
706 audata.buf = dmMalloc(audata.bufsize * sizeof(*audata.buf));
760
d345a898bda1 Use DMMutex and the appropriate function wrappers.
Matti Hamalainen <ccr@tnsp.org>
parents: 710
diff changeset
707 audata.mutex = dmCreateMutex();
690
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
708 audata.varTime = 0;
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
709 audata.varKeyFreq = 1.0f / (double) optAudioFreq;
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
710
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
711 SDL_PauseAudio(0);
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
712 SDL_PauseAudio(1);
1235
5b8245e5f785 Remove trailing whitespace.
Matti Hamalainen <ccr@tnsp.org>
parents: 1167
diff changeset
713
690
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
714
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
715 /* Create visualizer bitmap surface */
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
716 bmp = SDL_CreateRGBSurface(SDL_SWSURFACE, optBMPSize, optBMPSize, 8, 0, 0, 0, 0);
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
717 SDL_Color pal[SDL_NCOLORS];
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
718 int n;
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
719 for (n = 0; n < SDL_NCOLORS; n++)
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
720 {
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
721 pal[n].r = n;
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
722 pal[n].g = n;
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
723 pal[n].b = n;
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
724 }
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
725 SDL_SetColors(bmp, pal, 0, SDL_NCOLORS);
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
726
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
727 /* Misc inits */
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
728 au_editbuf_clear(editBuf);
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
729 needRedraw = REDRAW_ALL;
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
730 exitFlag = FALSE;
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
731 insertMode = TRUE;
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
732 jazzMode = FALSE;
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
733 viewMode = 0;
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
734
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
735 /* Enter mainloop */
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
736 while (!exitFlag)
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
737 {
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
738 /* Handle events */
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
739 while (SDL_PollEvent(&event))
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
740 switch (event.type)
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
741 {
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
742 case SDL_KEYDOWN:
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
743 {
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
744 /* Get key event modifiers into handy booleans */
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
745 BOOL modCtrl = event.key.keysym.mod & KMOD_CTRL,
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
746 modShift = event.key.keysym.mod & KMOD_SHIFT;
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
747
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
748 switch (event.key.keysym.sym)
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
749 {
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
750 case SDLK_F1:
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
751 audioPlaying = !audioPlaying;
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
752 SDL_PauseAudio(!audioPlaying);
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
753 needRedraw |= REDRAW_ALL;
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
754 break;
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
755
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
756 case SDLK_F2:
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
757 audata.varTime = 0;
691
e7663dd15eea Reset keytime and update screen on F2.
Matti Hamalainen <ccr@tnsp.org>
parents: 690
diff changeset
758 audata.varKeyTime = 0;
e7663dd15eea Reset keytime and update screen on F2.
Matti Hamalainen <ccr@tnsp.org>
parents: 690
diff changeset
759 needRedraw |= REDRAW_ALL;
690
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
760 break;
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
761
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
762 case SDLK_F4:
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
763 optClipping = !optClipping;
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
764 needRedraw |= REDRAW_VISUALIZER;
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
765 break;
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
766
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
767 case SDLK_F5:
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
768 /* Toggle audio scaling / range between [0.0, 1.0] and [0, 255] */
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
769 optScale = !optScale;
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
770 needRedraw |= REDRAW_VISUALIZER;
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
771 break;
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
772
1235
5b8245e5f785 Remove trailing whitespace.
Matti Hamalainen <ccr@tnsp.org>
parents: 1167
diff changeset
773
690
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
774 case SDLK_F6:
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
775 viewMode = (viewMode + 1) % 2;
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
776 needRedraw |= REDRAW_VISUALIZER;
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
777 break;
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
778
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
779 case SDLK_F8:
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
780 /* Toggle keyboard jazz mode */
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
781 jazzMode = !jazzMode;
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
782 needRedraw |= REDRAW_VISUALIZER;
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
783 break;
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
784
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
785 case SDLK_F9:
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
786 /* Save history to file */
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
787 au_save_history(AUVAL_HISTORY_USER, histBuf, histMax);
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
788 break;
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
789
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
790 case SDLK_ESCAPE:
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
791 exitFlag = TRUE;
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
792 break;
1235
5b8245e5f785 Remove trailing whitespace.
Matti Hamalainen <ccr@tnsp.org>
parents: 1167
diff changeset
793
690
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
794 case SDLK_RETURN:
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
795 /* Add to history buffer */
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
796 if (!jazzMode && editBuf->len > 0)
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
797 {
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
798 if (histMax > 0)
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
799 {
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
800 au_editbuf_free(histBuf[optHistoryLen+1]);
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
801 histBuf[optHistoryLen+1] = NULL;
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
802 memmove(&histBuf[2], &histBuf[1], histMax * sizeof(histBuf[0]));
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
803 }
1235
5b8245e5f785 Remove trailing whitespace.
Matti Hamalainen <ccr@tnsp.org>
parents: 1167
diff changeset
804
690
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
805 histPos = 0;
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
806 histBuf[1] = au_editbuf_copy(editBuf);
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
807 if (histMax < optHistoryLen) histMax++;
1235
5b8245e5f785 Remove trailing whitespace.
Matti Hamalainen <ccr@tnsp.org>
parents: 1167
diff changeset
808
690
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
809 au_editbuf_insert(editBuf, editBuf->len, 0);
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
810
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
811 /* You could do something here with the data ... */
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
812 //result = handleUserInput(conn, editBuf->data, editBuf->len);
1235
5b8245e5f785 Remove trailing whitespace.
Matti Hamalainen <ccr@tnsp.org>
parents: 1167
diff changeset
813
690
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
814 au_editbuf_clear(editBuf);
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
815 }
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
816 break;
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
817
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
818 case SDLK_UP: /* Backwards in input history */
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
819 if (jazzMode)
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
820 break;
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
821
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
822 if (histPos == 0)
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
823 {
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
824 au_editbuf_free(histBuf[0]);
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
825 histBuf[0] = au_editbuf_copy(editBuf);
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
826 }
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
827 if (histPos < histMax)
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
828 {
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
829 histPos++;
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
830 au_editbuf_free(editBuf);
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
831 editBuf = au_editbuf_copy(histBuf[histPos]);
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
832 }
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
833 break;
1235
5b8245e5f785 Remove trailing whitespace.
Matti Hamalainen <ccr@tnsp.org>
parents: 1167
diff changeset
834
690
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
835 case SDLK_DOWN: /* Forwards in input history */
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
836 if (jazzMode)
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
837 break;
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
838
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
839 if (histPos > 0)
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
840 {
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
841 histPos--;
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
842 au_editbuf_free(editBuf);
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
843 editBuf = au_editbuf_copy(histBuf[histPos]);
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
844 }
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
845 break;
1235
5b8245e5f785 Remove trailing whitespace.
Matti Hamalainen <ccr@tnsp.org>
parents: 1167
diff changeset
846
690
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
847 case SDLK_LEFT:
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
848 if (jazzMode)
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
849 break;
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
850
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
851 /* ctrl+left arrow = Skip words left */
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
852 if (modCtrl)
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
853 {
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
854 while (editBuf->pos > 0 && isspace((int) editBuf->data[editBuf->pos - 1]))
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
855 editBuf->pos--;
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
856 while (editBuf->pos > 0 && !isspace((int) editBuf->data[editBuf->pos - 1]))
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
857 editBuf->pos--;
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
858 }
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
859 else
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
860 {
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
861 au_editbuf_setpos(editBuf, editBuf->pos - 1);
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
862 }
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
863 break;
1235
5b8245e5f785 Remove trailing whitespace.
Matti Hamalainen <ccr@tnsp.org>
parents: 1167
diff changeset
864
690
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
865 case SDLK_RIGHT:
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
866 if (jazzMode)
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
867 break;
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
868
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
869 /* ctrl+right arrow = Skip words right */
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
870 if (modCtrl)
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
871 {
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
872 while (editBuf->pos < editBuf->len && isspace((int) editBuf->data[editBuf->pos]))
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
873 editBuf->pos++;
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
874 while (editBuf->pos < editBuf->len && !isspace((int) editBuf->data[editBuf->pos]))
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
875 editBuf->pos++;
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
876 }
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
877 else
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
878 {
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
879 au_editbuf_setpos(editBuf, editBuf->pos + 1);
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
880 }
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
881 break;
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
882
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
883 case SDLK_HOME:
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
884 if (jazzMode)
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
885 break;
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
886
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
887 au_editbuf_setpos(editBuf, 0);
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
888 break;
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
889
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
890 case SDLK_END:
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
891 if (jazzMode)
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
892 break;
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
893
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
894 au_editbuf_setpos(editBuf, editBuf->len);
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
895 break;
1235
5b8245e5f785 Remove trailing whitespace.
Matti Hamalainen <ccr@tnsp.org>
parents: 1167
diff changeset
896
690
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
897 case SDLK_BACKSPACE:
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
898 if (jazzMode)
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
899 break;
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
900
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
901 au_editbuf_delete(editBuf, editBuf->pos - 1);
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
902 au_editbuf_setpos(editBuf, editBuf->pos - 1);
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
903 break;
1235
5b8245e5f785 Remove trailing whitespace.
Matti Hamalainen <ccr@tnsp.org>
parents: 1167
diff changeset
904
690
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
905 case SDLK_DELETE: /* Delete character */
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
906 if (jazzMode)
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
907 break;
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
908
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
909 au_editbuf_delete(editBuf, editBuf->pos);
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
910 break;
1235
5b8245e5f785 Remove trailing whitespace.
Matti Hamalainen <ccr@tnsp.org>
parents: 1167
diff changeset
911
690
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
912 case SDLK_INSERT: /* Ins = Toggle insert / overwrite mode */
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
913 if (jazzMode)
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
914 break;
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
915
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
916 insertMode = !insertMode;
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
917 break;
1235
5b8245e5f785 Remove trailing whitespace.
Matti Hamalainen <ccr@tnsp.org>
parents: 1167
diff changeset
918
690
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
919 default:
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
920 if (jazzMode)
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
921 {
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
922 int key = event.key.keysym.unicode;
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
923 /* In keyboard jazz-mode, space stops playing */
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
924 if (key == SDLK_SPACE)
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
925 {
760
d345a898bda1 Use DMMutex and the appropriate function wrappers.
Matti Hamalainen <ccr@tnsp.org>
parents: 710
diff changeset
926 dmMutexLock(audata.mutex);
690
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
927 audata.varFreq = 1.0f;
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
928 audata.pos = 0;
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
929 audata.varTime = 0;
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
930 audata.varKeyTime = 0;
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
931 audata.varUnit = 0;
760
d345a898bda1 Use DMMutex and the appropriate function wrappers.
Matti Hamalainen <ccr@tnsp.org>
parents: 710
diff changeset
932 dmMutexUnlock(audata.mutex);
690
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
933
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
934 audioPlaying = FALSE;
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
935 SDL_PauseAudio(!audioPlaying);
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
936 break;
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
937 }
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
938 else
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
939 {
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
940 /* Calculate note based on key */
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
941 int period, note = au_get_note_from_key(&event.key.keysym, 4);
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
942 if (note > 0)
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
943 {
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
944 period = 7680 - (note * 64) - (/* finetune */ 128 / 2);
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
945 if (period < 1) period = 1;
1235
5b8245e5f785 Remove trailing whitespace.
Matti Hamalainen <ccr@tnsp.org>
parents: 1167
diff changeset
946
760
d345a898bda1 Use DMMutex and the appropriate function wrappers.
Matti Hamalainen <ccr@tnsp.org>
parents: 710
diff changeset
947 dmMutexLock(audata.mutex);
690
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
948 audata.varFreq = 8363.0f * pow(2.0f, (4608.0f - (double) period) / 768.0f) / optAudioFreq ;
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
949 audata.pos = 0;
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
950 audata.varTime = 0;
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
951 audata.varKeyTime = 0;
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
952 audata.varUnit = 0;
760
d345a898bda1 Use DMMutex and the appropriate function wrappers.
Matti Hamalainen <ccr@tnsp.org>
parents: 710
diff changeset
953 dmMutexUnlock(audata.mutex);
1235
5b8245e5f785 Remove trailing whitespace.
Matti Hamalainen <ccr@tnsp.org>
parents: 1167
diff changeset
954
690
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
955 audioPlaying = TRUE;
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
956 SDL_PauseAudio(!audioPlaying);
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
957 }
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
958 }
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
959
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
960 needRedraw |= REDRAW_VISUALIZER;
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
961 }
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
962 else
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
963 {
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
964 int key = event.key.keysym.unicode;
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
965 if (isprint(key))
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
966 {
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
967 if (insertMode)
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
968 au_editbuf_insert(editBuf, editBuf->pos, key);
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
969 else
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
970 au_editbuf_write(editBuf, editBuf->pos, key);
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
971 au_editbuf_setpos(editBuf, editBuf->pos + 1);
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
972 }
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
973 }
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
974 break;
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
975 }
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
976 }
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
977 needRedraw |= REDRAW_EDITOR | REDRAW_INFO;
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
978 break;
1235
5b8245e5f785 Remove trailing whitespace.
Matti Hamalainen <ccr@tnsp.org>
parents: 1167
diff changeset
979
690
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
980 case SDL_VIDEORESIZE:
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
981 /* Window resized, reinit video etc */
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
982 optScrWidth = event.resize.w;
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
983 optScrHeight = event.resize.h;
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
984
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
985 if (!au_init_video(&screen))
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
986 goto error_exit;
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
987
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
988 needRedraw = REDRAW_ALL;
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
989 break;
1235
5b8245e5f785 Remove trailing whitespace.
Matti Hamalainen <ccr@tnsp.org>
parents: 1167
diff changeset
990
690
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
991 case SDL_VIDEOEXPOSE:
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
992 /* Window exposed, redraw everything just to be sure */
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
993 needRedraw = REDRAW_ALL;
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
994 break;
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
995
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
996 case SDL_QUIT:
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
997 goto error_exit;
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
998 }
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
999
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1000
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1001 /* If formula has changed, update evaluation variables and load the
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1002 * expression into Lua. Check for errors. The actual expression
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1003 * evaluation is done in the audio rendering callback.
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1004 */
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1005 if (!jazzMode && editBuf->len > 0 && editBuf->dirty)
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1006 {
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1007 editBuf->dirty = FALSE;
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1008 editBuf->data[editBuf->len] = 0;
1235
5b8245e5f785 Remove trailing whitespace.
Matti Hamalainen <ccr@tnsp.org>
parents: 1167
diff changeset
1009
760
d345a898bda1 Use DMMutex and the appropriate function wrappers.
Matti Hamalainen <ccr@tnsp.org>
parents: 710
diff changeset
1010 dmMutexLock(audata.mutex);
1235
5b8245e5f785 Remove trailing whitespace.
Matti Hamalainen <ccr@tnsp.org>
parents: 1167
diff changeset
1011
761
7be7c7c5deaa Large cleanup, breaking everything. Yay.
Matti Hamalainen <ccr@tnsp.org>
parents: 760
diff changeset
1012 dmEvalTreeFree(audata.expr);
690
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1013 audata.expr = NULL;
761
7be7c7c5deaa Large cleanup, breaking everything. Yay.
Matti Hamalainen <ccr@tnsp.org>
parents: 760
diff changeset
1014 audata.ctx->err = dmEvalParseExpr(audata.ctx, editBuf->data, &audata.expr);
7be7c7c5deaa Large cleanup, breaking everything. Yay.
Matti Hamalainen <ccr@tnsp.org>
parents: 760
diff changeset
1015 dmEvalPrintOpTree(stdout, audata.ctx, audata.expr);
709
8c6cf02718be Add XOR operator (^, caret) to the parser .. was implemented already otherwise.
Matti Hamalainen <ccr@tnsp.org>
parents: 705
diff changeset
1016 printf("--\n");
690
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1017
710
a2d567d8a82d Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 709
diff changeset
1018 audata.pos = 0;
a2d567d8a82d Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 709
diff changeset
1019 audata.varTime = 0;
a2d567d8a82d Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 709
diff changeset
1020 audata.varFreq = 1.0f;
690
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1021 audata.varKeyTime = 0;
710
a2d567d8a82d Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 709
diff changeset
1022 audata.varUnit = 0;
690
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1023
760
d345a898bda1 Use DMMutex and the appropriate function wrappers.
Matti Hamalainen <ccr@tnsp.org>
parents: 710
diff changeset
1024 dmMutexUnlock(audata.mutex);
690
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1025 }
1235
5b8245e5f785 Remove trailing whitespace.
Matti Hamalainen <ccr@tnsp.org>
parents: 1167
diff changeset
1026
690
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1027 /* Check if visualizer needs redrawing
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1028 */
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1029 if (audata.pos != audata.oldpos)
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1030 {
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1031 audata.oldpos = audata.pos;
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1032 needRedraw |= REDRAW_VISUALIZER;
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1033 }
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1034
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1035 /* Redraw screen, if needed */
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1036 if (needRedraw)
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1037 {
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1038 if (SDL_MUSTLOCK(screen) != 0 && SDL_LockSurface(screen) != 0)
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1039 {
958
985225a93aeb Add error code parameter to dmError() and dmErrorVA().
Matti Hamalainen <ccr@tnsp.org>
parents: 867
diff changeset
1040 dmErrorMsg("Can't lock surface");
690
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1041 goto error_exit;
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1042 }
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1043
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1044 /* Clear the surface, draw copyright etc */
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1045 int fh = TTF_FontHeight(font);
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1046 int eh = screen->h - fh * 4;
1235
5b8245e5f785 Remove trailing whitespace.
Matti Hamalainen <ccr@tnsp.org>
parents: 1167
diff changeset
1047
690
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1048 if (needRedraw & REDRAW_INFO)
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1049 {
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1050 dmFillBox3D(screen, 0, 0, screen->w - 1, fh + 5, dmMapRGB(screen, 50, 50, 150),
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1051 dmMapRGB(screen, 150,150,250), dmMapRGB(screen, 25,25,50));
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1052
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1053 dmDrawTTFTextConst(screen, font, fontcol, 5, 2,
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1054 AUVAL_NAME " v" AUVAL_VERSION " (C) Copyright 2013 ccr/TNSP");
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1055
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1056
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1057 dmFillBox3D(screen, 0, eh - 25 - fh, screen->w - 1, eh - 16, dmMapRGB(screen, 50, 50, 150),
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1058 dmMapRGB(screen, 150,150,250), dmMapRGB(screen, 25,25,50));
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1059
705
39c03b7dd853 Remove some remnants of Lua mode.
Matti Hamalainen <ccr@tnsp.org>
parents: 691
diff changeset
1060 dmDrawTTFText(screen, font, fontcol, 5, eh - fh - 20, "%s | [%-8s] | %s",
690
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1061 optClipping ? "CLIPPED" : "WRAPPED",
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1062 optScale ? "0.0-1.0" : "0 - 255",
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1063 jazzMode ? "jazz" : "edit");
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1064 }
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1065
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1066 /* Draw the visualizer, based on the current mode*/
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1067 if (needRedraw & REDRAW_VISUALIZER)
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1068 {
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1069 char *vms;
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1070 dmFillRect(screen, 0, fh + 6, screen->w - 1, eh - fh - 27, dmMapRGB(screen, 15, 15, 15));
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1071
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1072 switch (viewMode)
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1073 {
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1074 case 0:
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1075 au_vis_wave(screen, 5, fh * 2 + 15, screen->w - 5, eh - 20, &audata);
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1076 vms = "scope";
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1077 break;
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1078
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1079 case 1:
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1080 au_vis_image(bmp, &audata);
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1081 dmScaledBlitSurfaceAny(bmp, 5, fh * 2 + 15, screen->w - 10, eh - fh * 2 - 30, screen, DMD_NONE);
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1082 vms = "bitmap";
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1083 break;
1235
5b8245e5f785 Remove trailing whitespace.
Matti Hamalainen <ccr@tnsp.org>
parents: 1167
diff changeset
1084
690
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1085 default:
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1086 vms = "?";
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1087 }
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1088
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1089 dmDrawTTFText(screen, font, fontcol, 5, fh + 10, "%s | %s | f=%dHz | t=%-8.1f",
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1090 audioPlaying ? "PLAYING" : "STOPPED",
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1091 vms, optAudioFreq, audata.varTime
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1092 );
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1093 }
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1094
1235
5b8245e5f785 Remove trailing whitespace.
Matti Hamalainen <ccr@tnsp.org>
parents: 1167
diff changeset
1095 /* Draw the function editor box */
690
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1096 if (needRedraw & REDRAW_EDITOR)
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1097 {
760
d345a898bda1 Use DMMutex and the appropriate function wrappers.
Matti Hamalainen <ccr@tnsp.org>
parents: 710
diff changeset
1098 dmMutexLock(audata.mutex);
690
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1099
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1100 dmFillBox3D(screen, 0, eh - 15, screen->w - 1, screen->h - 1,
761
7be7c7c5deaa Large cleanup, breaking everything. Yay.
Matti Hamalainen <ccr@tnsp.org>
parents: 760
diff changeset
1101 audata.ctx->err ? dmMapRGB(screen, 255, 0, 0) : dmMapRGB(screen, 0, 128, 64),
690
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1102 dmMapRGB(screen, 200, 255, 200), 100);
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1103
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1104 au_draw_editbuf(screen, font, fontcol, 5, eh - 10, screen->w - 10, eh - 15, editBuf,
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1105 dmMapRGB(screen, 0, 0, 150));
1235
5b8245e5f785 Remove trailing whitespace.
Matti Hamalainen <ccr@tnsp.org>
parents: 1167
diff changeset
1106
761
7be7c7c5deaa Large cleanup, breaking everything. Yay.
Matti Hamalainen <ccr@tnsp.org>
parents: 760
diff changeset
1107 if (audata.ctx->err && audata.ctx->errStr != NULL)
7be7c7c5deaa Large cleanup, breaking everything. Yay.
Matti Hamalainen <ccr@tnsp.org>
parents: 760
diff changeset
1108 dmDrawTTFTextConst(screen, font, fontcol, 5, screen->h - fh, audata.ctx->errStr);
690
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1109
760
d345a898bda1 Use DMMutex and the appropriate function wrappers.
Matti Hamalainen <ccr@tnsp.org>
parents: 710
diff changeset
1110 dmMutexUnlock(audata.mutex);
690
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1111 }
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1112
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1113 if (SDL_MUSTLOCK(screen) != 0)
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1114 SDL_UnlockSurface(screen);
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1115
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1116 SDL_Flip(screen);
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1117 needRedraw = 0;
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1118 }
1235
5b8245e5f785 Remove trailing whitespace.
Matti Hamalainen <ccr@tnsp.org>
parents: 1167
diff changeset
1119
690
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1120 SDL_Delay(50);
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1121 }
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1122
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1123 /* Save history */
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1124 au_save_history(AUVAL_HISTORY_FILE, histBuf, histMax);
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1125
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1126 error_exit:
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1127 if (font)
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1128 TTF_CloseFont(font);
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1129
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1130 if (audioPlaying)
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1131 SDL_PauseAudio(1);
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1132
760
d345a898bda1 Use DMMutex and the appropriate function wrappers.
Matti Hamalainen <ccr@tnsp.org>
parents: 710
diff changeset
1133 dmDestroyMutex(audata.mutex);
690
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1134
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1135 if (initSDL)
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1136 SDL_Quit();
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1137
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1138 if (initTTF)
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1139 TTF_Quit();
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1140
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1141 return 0;
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1142 }