~ubuntu-branches/ubuntu/hoary/jamin/hoary

« back to all changes in this revision

Viewing changes to src/mk-stateh.pl

  • Committer: Bazaar Package Importer
  • Author(s): Robert Jordens
  • Date: 2004-01-17 12:14:37 UTC
  • Revision ID: james.westby@ubuntu.com-20040117121437-3idr2e2m3k5jnm9n
Tags: upstream-0.8.0
ImportĀ upstreamĀ versionĀ 0.8.0

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#!/usr/bin/perl -w
 
2
 
 
3
open(SRC, "state-vars.txt") || die "Can't open 'state-vars.txt'";
 
4
open(OUT, "| indent -kr > state.h") || die "Can't invoke indent and write";
 
5
 
 
6
my @symbols;
 
7
my %card;
 
8
my %desc;
 
9
my $id;
 
10
 
 
11
$id = 0;
 
12
 
 
13
while(<SRC>) {
 
14
        next if (/^#/);
 
15
        if (/([a-z-]+)\t+(.+)/) {
 
16
                push @symbols, $1;
 
17
                $card{$1} = 1;
 
18
                $desc{$1} = $2;
 
19
        } elsif (/([a-z-]+)\((\d+)\)\t+(.+)/) {
 
20
                push @symbols, $1;
 
21
                $card{$1} = $2;
 
22
                $desc{$1} = $3;
 
23
        } else {
 
24
                die "Syntax error: $_";
 
25
        }
 
26
}
 
27
 
 
28
print OUT <<EOB;
 
29
#ifndef STATE_H
 
30
#define STATE_H
 
31
 
 
32
/* This is a generated file DO NOT EDIT, see state-vars.txt */
 
33
 
 
34
#include <gtk/gtk.h>
 
35
 
 
36
typedef void(* s_callback_func)(int id, float value);
 
37
 
 
38
typedef struct {
 
39
        int id;
 
40
        float value;
 
41
} s_entry;
 
42
 
 
43
void state_init();
 
44
void s_set_value_ui(int id, float value);
 
45
void s_set_value(int id, float value, int time);
 
46
void s_set_value_block(float *values, int base, int count);
 
47
void s_set_value_no_history(int id, float value);
 
48
void s_set_description(int id, const char *desc);
 
49
void s_clear_history();
 
50
void s_set_callback(int id, s_callback_func callback);
 
51
void s_set_adjustment(int id, GtkAdjustment *adjustment);
 
52
void s_history_add(const char *description);
 
53
void s_undo();
 
54
void s_redo();
 
55
void s_save_session_from_ui (GtkWidget *w, gpointer user_data);
 
56
void s_save_session (const char *fname);
 
57
void s_load_session_from_ui (GtkWidget *w, gpointer user_data);
 
58
void s_load_session (const char *fname);
 
59
void s_set_filename (const char *fname);
 
60
void s_crossfade(const int nframes);
 
61
void s_crossfade_ui();
 
62
void s_suppress_push();
 
63
void s_suppress_pop();
 
64
int s_have_filename();
 
65
 
 
66
#define S_NONE -1
 
67
EOB
 
68
 
 
69
for $sym (@symbols) {
 
70
        $macro = $sym;
 
71
        $macro =~ s/-/_/g;
 
72
        $macro = "\U$macro";
 
73
        if ($card{$sym} == 1) {
 
74
                print OUT "#define S_$macro ".$id++."\n";
 
75
        } else {
 
76
                print OUT "#define S_$macro(n) ($id + n)\n";
 
77
                $id += $card{$sym};
 
78
        }
 
79
}
 
80
 
 
81
print OUT <<EOB;
 
82
#define S_SIZE $id
 
83
 
 
84
typedef struct {
 
85
    char *description;
 
86
    float value[S_SIZE];
 
87
} s_state;
 
88
 
 
89
void s_restore_state(s_state *state);
 
90
void s_crossfade_to_state(s_state *state, float time);
 
91
void s_history_add_state(s_state state);
 
92
 
 
93
extern float s_value[S_SIZE];
 
94
 
 
95
/* fetch currently used value */
 
96
 
 
97
inline static float s_get_value(int id)
 
98
{
 
99
        return s_value[id];
 
100
}
 
101
 
 
102
/* set value with no side effects */
 
103
 
 
104
inline static void s_set_value_ns(int id, float value)
 
105
{
 
106
        s_value[id] = value;
 
107
}
 
108
 
 
109
EOB
 
110
 
 
111
$first = 1;
 
112
print OUT "static const char * const s_description[S_SIZE] = {\n";
 
113
for $sym (@symbols) {
 
114
        if ($card{$sym} > 1) {
 
115
                for ($i = 1; $i <= $card{$sym}; $i++) {
 
116
                        if (!$first) {
 
117
                                print OUT ",";
 
118
                        } else {
 
119
                                $first = 0;
 
120
                        }
 
121
                        print OUT "\"$desc{$sym} $i\"";
 
122
                }
 
123
        } else {
 
124
                if (!$first) {
 
125
                        print OUT ",";
 
126
                } else {
 
127
                        $first = 0;
 
128
                }
 
129
                print OUT "\"$desc{$sym}\"";
 
130
        }
 
131
}
 
132
print OUT "};\n\n";
 
133
 
 
134
$first = 1;
 
135
print OUT "static const char * const s_symbol[S_SIZE] = {\n";
 
136
for $sym (@symbols) {
 
137
        if ($card{$sym} > 1) {
 
138
                for ($i = 0; $i < $card{$sym}; $i++) {
 
139
                        if (!$first) {
 
140
                                print OUT ",";
 
141
                        } else {
 
142
                                $first = 0;
 
143
                        }
 
144
                        print OUT "\"$sym$i\"";
 
145
                }
 
146
        } else {
 
147
                if (!$first) {
 
148
                        print OUT ",";
 
149
                } else {
 
150
                        $first = 0;
 
151
                }
 
152
                print OUT "\"$sym\"";
 
153
        }
 
154
}
 
155
print OUT "};\n\n";
 
156
print OUT "#endif\n";
 
157
 
 
158
close OUT;