annotate tools/auval.c @ 958:985225a93aeb

Add error code parameter to dmError() and dmErrorVA().
author Matti Hamalainen <ccr@tnsp.org>
date Fri, 27 Feb 2015 03:58:25 +0200
parents 56e12109b936
children 848a88ce7a57
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"
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
2 #include "dmargs.h"
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
3 #include "dmeval.h"
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
4 #include "dmtext.h"
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
5 #include <math.h>
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
6
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
7 #define AUVAL_NAME "AuVal"
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
8 #define AUVAL_VERSION "0.6"
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
9 #define AUVAL_TMPBUF_SIZE (4096)
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
10 #define AUVAL_HISTORY_FILE "history.txt"
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
11 #define AUVAL_HISTORY_USER "formulas.txt"
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
12 #define SDL_NCOLORS 256
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
13
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
14
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
15 enum
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 REDRAW_VISUALIZER = 0x00000001,
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
18 REDRAW_EDITOR = 0x00000002,
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
19 REDRAW_INFO = 0x00000004,
867
56e12109b936 Portability warning fixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 860
diff changeset
20 REDRAW_ALL = 0x0fffffff,
690
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
21 };
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
22
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 typedef struct
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 DMEvalNode *expr;
761
7be7c7c5deaa Large cleanup, breaking everything. Yay.
Matti Hamalainen <ccr@tnsp.org>
parents: 760
diff changeset
27 DMEvalContext *ctx;
690
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
28
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
29 double varTime, varFreq, varKeyTime,
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
30 varKeyTimeRev, varKeyFreq, varUnit;
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
31
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
32 int avail, bufsize, pos, oldpos;
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
33 Uint8 *buf;
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
34
760
d345a898bda1 Use DMMutex and the appropriate function wrappers.
Matti Hamalainen <ccr@tnsp.org>
parents: 710
diff changeset
35 DMMutex *mutex;
690
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
36 } AUAudioData;
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
37
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
38
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
39 char *optFontFile = "font.ttf";
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 int optVFlags = SDL_SWSURFACE | SDL_HWPALETTE,
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
42 optScrWidth = 640,
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
43 optScrHeight = 480,
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
44 optScrDepth = 32,
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
45 optFontSize = 20,
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
46 optAudioFreq = 44100,
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
47 optBMPSize = 32,
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
48 optHistoryLen = 64;
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
49
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
50 BOOL optClipping = TRUE,
705
39c03b7dd853 Remove some remnants of Lua mode.
Matti Hamalainen <ccr@tnsp.org>
parents: 691
diff changeset
51 optScale = TRUE;
690
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
52
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
53
860
daebbf28953d The argument handling API in dmargs* was synced with th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents: 761
diff changeset
54 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
55 {
690
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
56 { 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
57 { 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
58 { 3, 0, "fs", "Fullscreen", OPT_NONE },
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
59 { 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
60 { 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
61 { 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
62 { 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
63
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
64 {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
65 {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
66 };
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
67
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
68 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
69
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
70
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
71 void argShowHelp()
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 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
74 dmArgsPrintHelp(stdout, optList, optListN, 0);
690
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
75 }
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
76
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 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
79 {
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
80 switch (optN) {
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
81 case 0:
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
82 argShowHelp();
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
83 exit(0);
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
84 break;
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
85
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
86 case 2:
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
87 dmVerbosity++;
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
88 break;
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
89
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
90 case 3:
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
91 optVFlags |= SDL_FULLSCREEN;
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
92 break;
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
93
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
94 case 5:
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
95 if (optArg)
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
96 {
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
97 int w, h;
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
98 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
99 {
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
100 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
101 {
958
985225a93aeb Add error code parameter to dmError() and dmErrorVA().
Matti Hamalainen <ccr@tnsp.org>
parents: 867
diff changeset
102 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
103 return FALSE;
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
104 }
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
105 optScrWidth = w;
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
106 optScrHeight = h;
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
107 }
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
108 else
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
109 {
958
985225a93aeb Add error code parameter to dmError() and dmErrorVA().
Matti Hamalainen <ccr@tnsp.org>
parents: 867
diff changeset
110 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
111 return FALSE;
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
112 }
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
113 }
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
114 else
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
115 {
958
985225a93aeb Add error code parameter to dmError() and dmErrorVA().
Matti Hamalainen <ccr@tnsp.org>
parents: 867
diff changeset
116 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
117 }
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
118 break;
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 case 6:
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
121 optScrDepth = atoi(optArg);
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
122 break;
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
123
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
124 case 7:
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 int tmp = atoi(optArg);
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
127 if (tmp < 4000 || tmp > 96000)
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
128 {
958
985225a93aeb Add error code parameter to dmError() and dmErrorVA().
Matti Hamalainen <ccr@tnsp.org>
parents: 867
diff changeset
129 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
130 return FALSE;
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
131 }
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
132 optAudioFreq = tmp;
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 break;
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 case 8:
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 int tmp = atoi(optArg);
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
139 if (tmp < 32 || tmp > 512)
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
140 {
958
985225a93aeb Add error code parameter to dmError() and dmErrorVA().
Matti Hamalainen <ccr@tnsp.org>
parents: 867
diff changeset
141 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
142 return FALSE;
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
143 }
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
144 optBMPSize = tmp;
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 break;
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 case 10:
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
149 optClipping = FALSE;
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
150 break;
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
151
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
152 case 11:
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
153 optScale = FALSE;
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
154 break;
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
155
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
156 default:
958
985225a93aeb Add error code parameter to dmError() and dmErrorVA().
Matti Hamalainen <ccr@tnsp.org>
parents: 867
diff changeset
157 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
158 return FALSE;
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
159 }
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
160
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
161 return TRUE;
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
162 }
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
163
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 typedef struct
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 ssize_t pos, len, size;
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
168 char *data;
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
169 BOOL dirty;
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
170 } AUEditBuf;
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
171
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
172
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
173 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
174 {
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
175 if (buf->len+1 >= buf->size) return -3;
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 (pos < 0)
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
178 return -1;
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
179 else if (pos >= buf->len) {
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
180 buf->data[buf->len++] = ch;
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
181 } else {
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
182 buf->data[pos] = ch;
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
183 }
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
184 buf->dirty = TRUE;
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
185 return 0;
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
186 }
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
187
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
188
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
189 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
190 {
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
191 if (buf->len+1 >= buf->size) return -3;
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
192
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
193 if (pos < 0)
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
194 return -1;
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
195 else if (pos >= buf->len) {
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
196 buf->data[buf->len] = ch;
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
197 } else {
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
198 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
199 buf->data[pos] = ch;
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
200 }
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
201 buf->len++;
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
202 buf->dirty = TRUE;
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
203 return 0;
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
204 }
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
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
207 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
208 {
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
209 if (pos < 0)
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
210 return -1;
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
211 else if (pos < buf->len) {
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
212 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
213 buf->len--;
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
214 buf->dirty = TRUE;
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
215 return 0;
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
216 } else
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
217 return -2;
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
218 }
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
219
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
220
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
221 void au_editbuf_clear(AUEditBuf *buf)
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
222 {
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
223 buf->len = 0;
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
224 buf->pos = 0;
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
225 buf->dirty = TRUE;
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
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
229 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
230 {
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
231 AUEditBuf *res = dmCalloc(1, sizeof(AUEditBuf));
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
232
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
233 res->data = (char *) dmMalloc(n);
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
234 res->size = n;
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
235 res->dirty = TRUE;
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
236
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
237 return res;
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
238 }
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
239
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
240 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
241 {
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
242 AUEditBuf *res = au_editbuf_new(n);
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
243 strncpy(res->data, str, res->size);
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
244 res->data[res->size - 1] = 0;
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
245 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
246 return res;
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
247 }
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
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
250 void au_editbuf_free(AUEditBuf *buf)
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
251 {
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
252 if (buf != NULL)
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
253 {
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
254 dmFree(buf->data);
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
255 dmFree(buf);
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 }
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
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
260 AUEditBuf * au_editbuf_copy(AUEditBuf *src)
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
261 {
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
262 AUEditBuf *res;
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 if (src == NULL) return NULL;
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 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
267 return NULL;
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 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
270 res->pos = res->len = src->len;
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
271 res->dirty = TRUE;
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
272
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
273 return res;
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
274 }
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
275
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
276
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
277 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
278 {
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
279 char *str;
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
280 ssize_t siz;
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 if (buf == NULL)
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
283 return NULL;
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
284
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
285 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
286 return NULL;
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
287
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
288 if (end < 0) {
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
289 siz = buf->len - start + 1;
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
290 } else if (start <= end) {
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
291 siz = end - start + 1;
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
292 } else
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 ((str = dmMalloc(siz + 1)) == NULL)
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
296 return NULL;
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
297
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
298 memcpy(str, buf->data + start, siz);
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
299 str[siz] = 0;
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
300
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
301 return str;
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
302 }
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
303
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 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
306 {
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
307 if (pos < 0)
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
308 buf->pos = 0;
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
309 else if (pos >= buf->len)
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
310 buf->pos = buf->len;
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
311 else
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
312 buf->pos = 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
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
315
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
316 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
317 {
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
318 *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
319 if (*screen == NULL)
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
320 {
958
985225a93aeb Add error code parameter to dmError() and dmErrorVA().
Matti Hamalainen <ccr@tnsp.org>
parents: 867
diff changeset
321 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
322 return FALSE;
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
323 }
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 return TRUE;
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
326 }
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
327
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
328
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
329 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
330 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
331 {
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
332 ssize_t left, maxlen, pos;
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
333 int strw, strh, y1 = yc + h;
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
334 char *line = NULL, *ptr;
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 if (buf == NULL)
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
337 return;
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 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
340 goto error;
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
341
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
342 maxlen = w / strw;
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
343 line = dmMalloc(maxlen + 2);
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
344 pos = 0;
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
345 left = buf->len;
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
346 ptr = buf->data;
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
347
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
348 do
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
349 {
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
350 ssize_t ppos = buf->pos - pos;
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
351 if (ppos >= 0 && ppos < maxlen)
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
352 {
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
353 int x0 = xc + ppos * strw;
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
354 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
355 }
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
356 else
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
357 if ((buf->pos % maxlen) == 0)
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
358 {
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
359 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
360 }
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
361
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
362 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
363 strncpy(line, ptr, len);
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
364 line[len] = 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 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
367
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
368 left -= len;
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
369 ptr += len;
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
370 pos += len;
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
371
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
372 yc += strh;
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
373 }
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
374 while (left > 0 && yc < y1);
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
375
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
376
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
377 error:
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
378 dmFree(line);
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
379 }
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
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
382 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
383 {
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
384 int x, offs;
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
385 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
386 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
387 const int xend = x1 * bpp;
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
388 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
389
760
d345a898bda1 Use DMMutex and the appropriate function wrappers.
Matti Hamalainen <ccr@tnsp.org>
parents: 710
diff changeset
390 dmMutexLock(data->mutex);
690
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
391
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
392 Uint8 *dp = data->buf,
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
393 *sp = screen->pixels;
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
394
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
395 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
396 {
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
397 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
398 sp[x + curr * pitch] = 255;
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
399 }
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
400
760
d345a898bda1 Use DMMutex and the appropriate function wrappers.
Matti Hamalainen <ccr@tnsp.org>
parents: 710
diff changeset
401 dmMutexUnlock(data->mutex);
690
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
402 }
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
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
405 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
406 {
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
407 int y;
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
408 Uint8 *p = (Uint8 *) screen->pixels;
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
409
760
d345a898bda1 Use DMMutex and the appropriate function wrappers.
Matti Hamalainen <ccr@tnsp.org>
parents: 710
diff changeset
410 dmMutexLock(data->mutex);
690
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 Uint8 *dp = data->buf;
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 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
415 {
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
416 int x;
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
417 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
418 *p++ = *dp++;
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
419
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
420 p += screen->pitch - screen->w;
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
421 }
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
422
760
d345a898bda1 Use DMMutex and the appropriate function wrappers.
Matti Hamalainen <ccr@tnsp.org>
parents: 710
diff changeset
423 dmMutexUnlock(data->mutex);
690
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
424 }
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
425
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 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
428 {
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
429 int note;
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
430
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
431 switch (key->sym)
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 case SDLK_z: note = 1; break;
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
434 case SDLK_s: note = 2; break;
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
435 case SDLK_x: note = 3; break;
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
436 case SDLK_d: note = 4; break;
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
437 case SDLK_c: note = 5; break;
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
438 case SDLK_v: note = 6; break;
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
439 case SDLK_g: note = 7; break;
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
440 case SDLK_b: note = 8; break;
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
441 case SDLK_h: note = 9; break;
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
442 case SDLK_n: note = 10; break;
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
443 case SDLK_j: note = 11; break;
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
444 case SDLK_m: note = 12; break;
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
445
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
446 case SDLK_q: note = 13; break;
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
447 case SDLK_2: note = 14; break;
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
448 case SDLK_w: note = 15; break;
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
449 case SDLK_3: note = 16; break;
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
450 case SDLK_e: note = 17; break;
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
451 case SDLK_r: note = 18; break;
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
452 case SDLK_5: note = 19; break;
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
453 case SDLK_t: note = 20; break;
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
454 case SDLK_6: note = 21; break;
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
455 case SDLK_y: note = 22; break;
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
456 case SDLK_7: note = 23; break;
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
457 case SDLK_u: note = 24; break;
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
458 case SDLK_i: note = 25; break;
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
459 case SDLK_9: note = 26; break;
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
460 case SDLK_o: note = 27; break;
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
461 case SDLK_0: note = 28; break;
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
462 case SDLK_p: note = 29; break;
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
463
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
464 default: return -1;
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
465 }
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
466
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
467 note += 12 * octave;
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
468 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
469 }
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
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
472 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
473 {
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
474 *val += delta;
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
475 if (*val < min) *val = min;
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
476 else if (*val > max) *val = max;
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
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
480 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
481 {
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
482 char tmpStr[1024];
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
483 int i;
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 FILE *f = fopen(filename, "r");
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
486 if (f == NULL)
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
487 {
958
985225a93aeb Add error code parameter to dmError() and dmErrorVA().
Matti Hamalainen <ccr@tnsp.org>
parents: 867
diff changeset
488 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
489 return -1;
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
490 }
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 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
493 {
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
494 /* 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
495 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
496 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
497 tmpStr[i] = 0;
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 /* 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
500 if (tmpStr[0] != 0)
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
501 {
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
502 au_editbuf_free(history[maxHistory + 1]);
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
503 history[maxHistory + 1] = NULL;
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
504 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
505
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
506 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
507
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
508 if (*histMax < maxHistory)
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
509 (*histMax)++;
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
510 }
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
511 }
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 fclose(f);
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
514 return 0;
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
515 }
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
516
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 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
519 {
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
520 int i;
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
521
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
522 FILE *f = fopen(filename, "w");
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
523 if (f == NULL)
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
524 {
958
985225a93aeb Add error code parameter to dmError() and dmErrorVA().
Matti Hamalainen <ccr@tnsp.org>
parents: 867
diff changeset
525 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
526 return -1;
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
527 }
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 for (i = histMax; i >= 0; i--)
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
530 {
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
531 AUEditBuf *buf = history[i];
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
532 if (buf != NULL)
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
533 {
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
534 buf->data[buf->len] = 0;
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
535 fprintf(f, "%s\n", buf->data);
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
536 }
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
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
539 fclose(f);
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
540 return 0;
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
541 }
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
542
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 /* 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
545 * 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
546 *
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
547 * 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
548 * accessed.
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 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
551 {
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
552 AUAudioData *data = (AUAudioData *) udata;
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
553
760
d345a898bda1 Use DMMutex and the appropriate function wrappers.
Matti Hamalainen <ccr@tnsp.org>
parents: 710
diff changeset
554 dmMutexLock(data->mutex);
690
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
555
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
556 data->avail = 0;
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
557
761
7be7c7c5deaa Large cleanup, breaking everything. Yay.
Matti Hamalainen <ccr@tnsp.org>
parents: 760
diff changeset
558 if (!data->ctx->err)
690
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
559 {
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
560 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
561 {
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
562 double value;
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
563
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
564 data->varKeyTimeRev = 1.0f - data->varKeyTime;
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
565
761
7be7c7c5deaa Large cleanup, breaking everything. Yay.
Matti Hamalainen <ccr@tnsp.org>
parents: 760
diff changeset
566 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
567 break;
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 if (optScale)
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 if (optClipping)
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
572 value = ((value < -1.0f) ? -1.0f : ((value > 1.0f) ? 1.0f : value));
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
573
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
574 value = 128 + (value * 126);
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 else
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 < 0) ? 0 : ((value > 255) ? 255 : value));
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
580 }
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
581
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
582 data->buf[data->avail++] = value;
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
583
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
584 data->varTime += data->varFreq;
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
585 data->varUnit += data->varKeyFreq;
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
586
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
587 data->varKeyTime += data->varKeyFreq;
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
588 if (data->varKeyTime > 1.0f)
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
589 data->varKeyTime = 1.0f;
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
761
7be7c7c5deaa Large cleanup, breaking everything. Yay.
Matti Hamalainen <ccr@tnsp.org>
parents: 760
diff changeset
592 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
593 {
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
594 memcpy(buf, data->buf, len);
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
595 data->pos += len;
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
596 }
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
597 else
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
598 memset(buf, 0, len);
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
599 }
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
600
760
d345a898bda1 Use DMMutex and the appropriate function wrappers.
Matti Hamalainen <ccr@tnsp.org>
parents: 710
diff changeset
601 dmMutexUnlock(data->mutex);
690
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
602 }
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
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
605 int main(int argc, char *argv[])
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
606 {
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
607 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
608 AUEditBuf **histBuf = NULL;
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
609 int histPos = 0, histMax = 0, viewMode;
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
610 SDL_Surface *screen = NULL, *bmp = NULL;
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
611 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
612 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
613 SDL_Event event;
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
614 SDL_AudioSpec fmt;
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
615 AUAudioData audata;
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
616 int needRedraw;
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
617 BOOL initSDL = FALSE, initTTF = FALSE, exitFlag,
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
618 insertMode, audioPlaying = FALSE, jazzMode;
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
619
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
620 memset(&audata, 0, sizeof(audata));
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
621
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
622 /* Parse arguments */
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
623 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
624 argHandleOpt, NULL, 0))
690
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
625 exit(1);
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
626
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
627
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
628 /* Allocate edit history buffers */
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
629 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
630 if (histBuf == NULL)
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
631 {
958
985225a93aeb Add error code parameter to dmError() and dmErrorVA().
Matti Hamalainen <ccr@tnsp.org>
parents: 867
diff changeset
632 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
633 goto error_exit;
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
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
636
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
637 /* 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
638 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
639
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
640
761
7be7c7c5deaa Large cleanup, breaking everything. Yay.
Matti Hamalainen <ccr@tnsp.org>
parents: 760
diff changeset
641 /* Initialize evaluator ctx */
7be7c7c5deaa Large cleanup, breaking everything. Yay.
Matti Hamalainen <ccr@tnsp.org>
parents: 760
diff changeset
642 audata.ctx = dmEvalContextNew();
690
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
643 audata.expr = NULL;
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
644
761
7be7c7c5deaa Large cleanup, breaking everything. Yay.
Matti Hamalainen <ccr@tnsp.org>
parents: 760
diff changeset
645 dmEvalContextAddVar(audata.ctx, "t", &audata.varTime);
7be7c7c5deaa Large cleanup, breaking everything. Yay.
Matti Hamalainen <ccr@tnsp.org>
parents: 760
diff changeset
646 dmEvalContextAddVar(audata.ctx, "k", &audata.varKeyTime);
7be7c7c5deaa Large cleanup, breaking everything. Yay.
Matti Hamalainen <ccr@tnsp.org>
parents: 760
diff changeset
647 dmEvalContextAddVar(audata.ctx, "q", &audata.varKeyTimeRev);
7be7c7c5deaa Large cleanup, breaking everything. Yay.
Matti Hamalainen <ccr@tnsp.org>
parents: 760
diff changeset
648 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
649
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
650
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
651 /* Initialize SDL */
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
652 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
653 {
958
985225a93aeb Add error code parameter to dmError() and dmErrorVA().
Matti Hamalainen <ccr@tnsp.org>
parents: 867
diff changeset
654 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
655 goto error_exit;
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 initSDL = TRUE;
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
658
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
659 if (TTF_Init() < 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 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
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 initTTF = 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 font = TTF_OpenFont(optFontFile, optFontSize);
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
667 if (font == NULL)
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
668 {
958
985225a93aeb Add error code parameter to dmError() and dmErrorVA().
Matti Hamalainen <ccr@tnsp.org>
parents: 867
diff changeset
669 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
670 optFontFile, optFontSize, SDL_GetError());
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
671 goto error_exit;
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 TTF_SetFontStyle(font, TTF_STYLE_NORMAL);
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
674
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
675 if (!au_init_video(&screen))
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
676 goto error_exit;
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
677
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
678 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
679
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
680 SDL_EnableUNICODE(1);
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
681 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
682
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
683
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
684 /* Initialize audio */
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
685 fmt.freq = optAudioFreq;
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
686 fmt.format = AUDIO_U8;
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
687 fmt.channels = 1;
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
688 fmt.samples = 512;
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
689 fmt.callback = au_sdl_audio_fill;
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
690 fmt.userdata = &audata;
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
691
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
692 if (SDL_OpenAudio(&fmt, NULL) < 0)
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
693 {
958
985225a93aeb Add error code parameter to dmError() and dmErrorVA().
Matti Hamalainen <ccr@tnsp.org>
parents: 867
diff changeset
694 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
695 goto error_exit;
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
696 }
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
697
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
698 audata.bufsize = optAudioFreq;
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
699 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
700 audata.mutex = dmCreateMutex();
690
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
701 audata.varTime = 0;
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
702 audata.varKeyFreq = 1.0f / (double) optAudioFreq;
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 SDL_PauseAudio(0);
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
705 SDL_PauseAudio(1);
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
706
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
707
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
708 /* Create visualizer bitmap surface */
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
709 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
710 SDL_Color pal[SDL_NCOLORS];
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
711 int n;
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
712 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
713 {
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
714 pal[n].r = n;
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
715 pal[n].g = n;
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
716 pal[n].b = n;
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
717 }
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
718 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
719
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
720 /* Misc inits */
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
721 au_editbuf_clear(editBuf);
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
722 needRedraw = REDRAW_ALL;
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
723 exitFlag = FALSE;
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
724 insertMode = TRUE;
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
725 jazzMode = FALSE;
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
726 viewMode = 0;
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
727
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
728 /* Enter mainloop */
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
729 while (!exitFlag)
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
730 {
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
731 /* Handle events */
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
732 while (SDL_PollEvent(&event))
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
733 switch (event.type)
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 case SDL_KEYDOWN:
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
736 {
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
737 /* 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
738 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
739 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
740
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
741 switch (event.key.keysym.sym)
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
742 {
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
743 case SDLK_F1:
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
744 audioPlaying = !audioPlaying;
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
745 SDL_PauseAudio(!audioPlaying);
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
746 needRedraw |= REDRAW_ALL;
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
747 break;
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
748
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
749 case SDLK_F2:
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
750 audata.varTime = 0;
691
e7663dd15eea Reset keytime and update screen on F2.
Matti Hamalainen <ccr@tnsp.org>
parents: 690
diff changeset
751 audata.varKeyTime = 0;
e7663dd15eea Reset keytime and update screen on F2.
Matti Hamalainen <ccr@tnsp.org>
parents: 690
diff changeset
752 needRedraw |= REDRAW_ALL;
690
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
753 break;
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
754
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
755 case SDLK_F4:
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
756 optClipping = !optClipping;
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
757 needRedraw |= REDRAW_VISUALIZER;
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
758 break;
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
759
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
760 case SDLK_F5:
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
761 /* 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
762 optScale = !optScale;
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
763 needRedraw |= REDRAW_VISUALIZER;
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
764 break;
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
765
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_F6:
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
768 viewMode = (viewMode + 1) % 2;
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
769 needRedraw |= REDRAW_VISUALIZER;
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
770 break;
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
771
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
772 case SDLK_F8:
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
773 /* Toggle keyboard jazz mode */
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
774 jazzMode = !jazzMode;
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
775 needRedraw |= REDRAW_VISUALIZER;
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
776 break;
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
777
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
778 case SDLK_F9:
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
779 /* Save history to file */
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
780 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
781 break;
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
782
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
783 case SDLK_ESCAPE:
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
784 exitFlag = TRUE;
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
785 break;
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
786
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
787 case SDLK_RETURN:
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
788 /* Add to history buffer */
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
789 if (!jazzMode && editBuf->len > 0)
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
790 {
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
791 if (histMax > 0)
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
792 {
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
793 au_editbuf_free(histBuf[optHistoryLen+1]);
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
794 histBuf[optHistoryLen+1] = NULL;
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
795 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
796 }
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 histPos = 0;
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
799 histBuf[1] = au_editbuf_copy(editBuf);
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
800 if (histMax < optHistoryLen) histMax++;
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
801
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
802 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
803
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
804 /* 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
805 //result = handleUserInput(conn, editBuf->data, editBuf->len);
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
806
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
807 au_editbuf_clear(editBuf);
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
808 }
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
809 break;
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 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
812 if (jazzMode)
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
813 break;
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
814
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
815 if (histPos == 0)
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
816 {
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
817 au_editbuf_free(histBuf[0]);
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
818 histBuf[0] = au_editbuf_copy(editBuf);
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
819 }
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
820 if (histPos < histMax)
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 histPos++;
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
823 au_editbuf_free(editBuf);
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
824 editBuf = au_editbuf_copy(histBuf[histPos]);
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
825 }
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
826 break;
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
827
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
828 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
829 if (jazzMode)
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
830 break;
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
831
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
832 if (histPos > 0)
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
833 {
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
834 histPos--;
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
835 au_editbuf_free(editBuf);
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
836 editBuf = au_editbuf_copy(histBuf[histPos]);
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
837 }
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
838 break;
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
839
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
840 case SDLK_LEFT:
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
841 if (jazzMode)
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
842 break;
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
843
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
844 /* ctrl+left arrow = Skip words left */
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
845 if (modCtrl)
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
846 {
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
847 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
848 editBuf->pos--;
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
849 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
850 editBuf->pos--;
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
851 }
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
852 else
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 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
855 }
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
856 break;
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
857
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
858 case SDLK_RIGHT:
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
859 if (jazzMode)
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
860 break;
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
861
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
862 /* ctrl+right arrow = Skip words right */
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
863 if (modCtrl)
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
864 {
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
865 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
866 editBuf->pos++;
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
867 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
868 editBuf->pos++;
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
869 }
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
870 else
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 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
873 }
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
874 break;
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
875
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
876 case SDLK_HOME:
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
877 if (jazzMode)
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
878 break;
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
879
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
880 au_editbuf_setpos(editBuf, 0);
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_END:
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, editBuf->len);
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_BACKSPACE:
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_delete(editBuf, editBuf->pos - 1);
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
895 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
896 break;
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
897
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
898 case SDLK_DELETE: /* Delete character */
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
899 if (jazzMode)
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
900 break;
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
901
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
902 au_editbuf_delete(editBuf, editBuf->pos);
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
903 break;
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
904
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
905 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
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 insertMode = !insertMode;
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
910 break;
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
911
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
912 default:
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 {
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
915 int key = event.key.keysym.unicode;
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
916 /* 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
917 if (key == SDLK_SPACE)
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
918 {
760
d345a898bda1 Use DMMutex and the appropriate function wrappers.
Matti Hamalainen <ccr@tnsp.org>
parents: 710
diff changeset
919 dmMutexLock(audata.mutex);
690
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
920 audata.varFreq = 1.0f;
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
921 audata.pos = 0;
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
922 audata.varTime = 0;
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
923 audata.varKeyTime = 0;
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
924 audata.varUnit = 0;
760
d345a898bda1 Use DMMutex and the appropriate function wrappers.
Matti Hamalainen <ccr@tnsp.org>
parents: 710
diff changeset
925 dmMutexUnlock(audata.mutex);
690
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
926
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
927 audioPlaying = FALSE;
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
928 SDL_PauseAudio(!audioPlaying);
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
929 break;
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
930 }
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
931 else
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
932 {
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
933 /* Calculate note based on key */
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
934 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
935 if (note > 0)
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
936 {
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
937 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
938 if (period < 1) period = 1;
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
939
760
d345a898bda1 Use DMMutex and the appropriate function wrappers.
Matti Hamalainen <ccr@tnsp.org>
parents: 710
diff changeset
940 dmMutexLock(audata.mutex);
690
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
941 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
942 audata.pos = 0;
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
943 audata.varTime = 0;
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
944 audata.varKeyTime = 0;
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
945 audata.varUnit = 0;
760
d345a898bda1 Use DMMutex and the appropriate function wrappers.
Matti Hamalainen <ccr@tnsp.org>
parents: 710
diff changeset
946 dmMutexUnlock(audata.mutex);
690
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
947
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
948 audioPlaying = TRUE;
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
949 SDL_PauseAudio(!audioPlaying);
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
950 }
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
951 }
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
952
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
953 needRedraw |= REDRAW_VISUALIZER;
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
954 }
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
955 else
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
956 {
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
957 int key = event.key.keysym.unicode;
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
958 if (isprint(key))
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 if (insertMode)
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
961 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
962 else
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
963 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
964 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
965 }
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 break;
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
968 }
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
969 }
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
970 needRedraw |= REDRAW_EDITOR | REDRAW_INFO;
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
971 break;
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 case SDL_VIDEORESIZE:
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
974 /* Window resized, reinit video etc */
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
975 optScrWidth = event.resize.w;
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
976 optScrHeight = event.resize.h;
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
977
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
978 if (!au_init_video(&screen))
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
979 goto error_exit;
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
980
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
981 needRedraw = REDRAW_ALL;
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
982 break;
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
983
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
984 case SDL_VIDEOEXPOSE:
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
985 /* 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
986 needRedraw = REDRAW_ALL;
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
987 break;
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
988
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
989 case SDL_QUIT:
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
990 goto error_exit;
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
991 }
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
992
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
993
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
994 /* 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
995 * 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
996 * 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
997 */
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
998 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
999 {
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1000 editBuf->dirty = FALSE;
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1001 editBuf->data[editBuf->len] = 0;
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1002
760
d345a898bda1 Use DMMutex and the appropriate function wrappers.
Matti Hamalainen <ccr@tnsp.org>
parents: 710
diff changeset
1003 dmMutexLock(audata.mutex);
690
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1004
761
7be7c7c5deaa Large cleanup, breaking everything. Yay.
Matti Hamalainen <ccr@tnsp.org>
parents: 760
diff changeset
1005 dmEvalTreeFree(audata.expr);
690
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1006 audata.expr = NULL;
761
7be7c7c5deaa Large cleanup, breaking everything. Yay.
Matti Hamalainen <ccr@tnsp.org>
parents: 760
diff changeset
1007 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
1008 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
1009 printf("--\n");
690
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1010
710
a2d567d8a82d Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 709
diff changeset
1011 audata.pos = 0;
a2d567d8a82d Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 709
diff changeset
1012 audata.varTime = 0;
a2d567d8a82d Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 709
diff changeset
1013 audata.varFreq = 1.0f;
690
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1014 audata.varKeyTime = 0;
710
a2d567d8a82d Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 709
diff changeset
1015 audata.varUnit = 0;
690
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1016
760
d345a898bda1 Use DMMutex and the appropriate function wrappers.
Matti Hamalainen <ccr@tnsp.org>
parents: 710
diff changeset
1017 dmMutexUnlock(audata.mutex);
690
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1018 }
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1019
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1020 /* Check if visualizer needs redrawing
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1021 */
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1022 if (audata.pos != audata.oldpos)
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1023 {
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1024 audata.oldpos = audata.pos;
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1025 needRedraw |= REDRAW_VISUALIZER;
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1026 }
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1027
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1028 /* Redraw screen, if needed */
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1029 if (needRedraw)
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 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
1032 {
958
985225a93aeb Add error code parameter to dmError() and dmErrorVA().
Matti Hamalainen <ccr@tnsp.org>
parents: 867
diff changeset
1033 dmErrorMsg("Can't lock surface");
690
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1034 goto error_exit;
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1035 }
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1036
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1037 /* Clear the surface, draw copyright etc */
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1038 int fh = TTF_FontHeight(font);
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1039 int eh = screen->h - fh * 4;
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1040
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1041 if (needRedraw & REDRAW_INFO)
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 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
1044 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
1045
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1046 dmDrawTTFTextConst(screen, font, fontcol, 5, 2,
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1047 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
1048
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, 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
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
705
39c03b7dd853 Remove some remnants of Lua mode.
Matti Hamalainen <ccr@tnsp.org>
parents: 691
diff changeset
1053 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
1054 optClipping ? "CLIPPED" : "WRAPPED",
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1055 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
1056 jazzMode ? "jazz" : "edit");
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1057 }
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1058
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1059 /* 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
1060 if (needRedraw & REDRAW_VISUALIZER)
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1061 {
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1062 char *vms;
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1063 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
1064
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1065 switch (viewMode)
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1066 {
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1067 case 0:
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1068 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
1069 vms = "scope";
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1070 break;
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 case 1:
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1073 au_vis_image(bmp, &audata);
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1074 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
1075 vms = "bitmap";
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1076 break;
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1077
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1078 default:
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1079 vms = "?";
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1080 }
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1081
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1082 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
1083 audioPlaying ? "PLAYING" : "STOPPED",
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1084 vms, optAudioFreq, audata.varTime
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1085 );
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1086 }
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 /* Draw the function editor box */
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1089 if (needRedraw & REDRAW_EDITOR)
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1090 {
760
d345a898bda1 Use DMMutex and the appropriate function wrappers.
Matti Hamalainen <ccr@tnsp.org>
parents: 710
diff changeset
1091 dmMutexLock(audata.mutex);
690
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 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
1094 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
1095 dmMapRGB(screen, 200, 255, 200), 100);
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1096
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1097 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
1098 dmMapRGB(screen, 0, 0, 150));
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1099
761
7be7c7c5deaa Large cleanup, breaking everything. Yay.
Matti Hamalainen <ccr@tnsp.org>
parents: 760
diff changeset
1100 if (audata.ctx->err && audata.ctx->errStr != NULL)
7be7c7c5deaa Large cleanup, breaking everything. Yay.
Matti Hamalainen <ccr@tnsp.org>
parents: 760
diff changeset
1101 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
1102
760
d345a898bda1 Use DMMutex and the appropriate function wrappers.
Matti Hamalainen <ccr@tnsp.org>
parents: 710
diff changeset
1103 dmMutexUnlock(audata.mutex);
690
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1104 }
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1105
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1106 if (SDL_MUSTLOCK(screen) != 0)
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1107 SDL_UnlockSurface(screen);
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1108
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1109 SDL_Flip(screen);
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1110 needRedraw = 0;
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 SDL_Delay(50);
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1114 }
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 /* Save history */
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1117 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
1118
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1119 error_exit:
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1120 if (font)
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1121 TTF_CloseFont(font);
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 if (audioPlaying)
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1124 SDL_PauseAudio(1);
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1125
760
d345a898bda1 Use DMMutex and the appropriate function wrappers.
Matti Hamalainen <ccr@tnsp.org>
parents: 710
diff changeset
1126 dmDestroyMutex(audata.mutex);
690
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1127
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1128 if (initSDL)
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1129 SDL_Quit();
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1130
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1131 if (initTTF)
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1132 TTF_Quit();
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1133
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1134 return 0;
84811c6dd32d Added Auval with removed Lua dependancy, using dmeval only.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1135 }