File: global.h

package info (click to toggle)
gramophone2 0.8.13a-3.5
  • links: PTS
  • area: main
  • in suites: trixie
  • size: 556 kB
  • sloc: ansic: 2,707; yacc: 1,873; lex: 308; makefile: 33
file content (213 lines) | stat: -rw-r--r-- 6,223 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
/*		
 *		GRAMophone II, a grammar based algorithmic musical composition tool
 *		-------------------------------------------------------------------
 *
 *		global.h
 *
 *		Copyright (c) 2007, Giovanni Ferranti <giovanni@giovanniferranti.it>
 *
 * 		GRAMophone II is free software; you can redistribute it and/or modify
 * 		it under the terms of the GNU General Public License as published by
 * 		the Free Software Foundation; either version 2 of the License, or
 * 		(at your option) any later version.
 *
 * 		This program is distributed in the hope that it will be useful,
 * 		but WITHOUT ANY WARRANTY; without even the implied warranty of
 * 		MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
 * 		GNU Library General Public License for more details.
 *
 *		You should have received a copy of the GNU General Public License along
 *		with this program; if not, write to the Free Software Foundation, Inc.,
 *		51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
 *		-------------------------------------------------------------------
 */
 
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "midifile.h"

#define	VERSION				"0.8.13a"
#define DEFAULT_FILENAME	"composition.mid"
#define MAX_FILENAME_LENGTH	256
#define MAX_ITERATIONS		50000	//numero massimo di iterazioni
#define	MAX_STR				4096
#define NUM_GLOBAL_PARAMS	7
#define NUM_LOCAL_PARAMS	6
#define NUM_VARS			1024	//numero massimo di variabili, sia globali
									//sia locali
#define NUM_PLAYERS			128		//numero massimo di players
#define NUM_CTRL			22
#define VAR_LENGTH			31
#define NUM_MACRO			65536
#define NUM_PRODS			1024
#define DIM_EXP				512
#define	DIM_MIDI_CODE		1024
#define MAX_RECURSION		50
#define DIM_BUFFER			10240
#define MAX_CHORD			50
#define DIM_RTGD_BUFFER		256

/* 
 * TEMP VARS
 */

char string_buf[MAX_STR], idTemp[MAX_STR];
unsigned int note[5], rest;
unsigned int chord[MAX_CHORD][5];

/*
 * WORK VARS
 */

unsigned char isGlobal, globalWritten;
unsigned int varCount, macroCount, playerCount, prev_duration, stringCount, level;

/*
 * COMMAND LINE OPT
 */

FILE *midi;
char namefile[MAX_FILENAME_LENGTH];
unsigned char checkOption, debugOption;

/*
 * MIDI DATA
 */

char data[4];

/*
 * DATA STRUCTURES
 */

unsigned int global_resolution, global_iterations;
unsigned char grammarOption; //1 - Chomsky; 2 - Lindenmayer
char *strings[MAX_STR];
enum var_type {OCT=1, VEL, DUR, REL, BYTEDATA};

enum default_prm {DEFOCT, DEFVEL, DEFDUR, DEFREL, DEFINSTR, CHN, DEFMSB};

unsigned int global_params[NUM_GLOBAL_PARAMS];
			//0 - Octave; 1 - Velocity
			//2 - Duration; 3 - Release
			//4 - Instrument; 5 - Channel;
			//6 - Msb

unsigned char loc_par_flag[10]; 
			//0 - grammar
			//1 - iterations
			//2 - time signature
			//3 - octave
			//4 - velocity
			//5 - duration
			//6 - release
			//7 - msb
			//8 - instrument
			//9 - channel

//GrammyVM ASM

enum GrammyAsm {_ADD=1, _SUB, _MUL, _DIV, _MOD, _INC, _DEC, _OR, _AND, _NOT, _EQ, 
				_NE, _LT, _LE, _GT, _GE, _SP, _PRD, _PRD_ALT, _CHK, _ELSE, _GOTO, _EXP, _UPDATE,
				_ENDEXP, _MOV, _NOTEON, _REST, _EMPTY, _TRN, _INV, _RTRGD, _RTGINV, 
		 		_RND, _ENDMELOP, _REP, _ENDREP, _CHORD, _ENDCHORD, _UMIN, _PRNT, _STR};

//Errors

enum error_msg {UNTERMINATED_STR, EOF_ERR, TOO_DEEPLY, DISCOGRAPHY_NOT_FOUND,
				EXPECTED, MEMORY_ERR, ALREADY, GRAMMAR_EXPECTED, RES_OUT,
				IT_OUT, OUT, NUMERATOR_OUT, FRACTION_DEN_ERR, OCTAVE_OUT,
				TEMPO_OUT, PLAYER_EXPECTED, VAR_NOT_DECLARED, TOO_LONG,
				CHN_OUT, TOO_MANY_PLAYERS, TOO_MANY_VARS, TYPE_ERR,
				TOO_MANY_MACROS, TOO_MANY_NOTE_PAR, REPEAT_ERR, SILENT_ERR,
				TOO_MANY_STRINGS, ELSE_WITHOUT_CONDITION};

unsigned char glob_num, glob_den;
char *title, *copyright; 
unsigned int tempo;

typedef struct note_vars_value *pnote_var;

typedef struct note_vars_value {
  char *name;
  unsigned char type;
  unsigned int value;
} note_var;

note_var global_vars[NUM_VARS];

typedef struct Expression *pExp;

typedef struct Expression {	
  unsigned int expcode[DIM_EXP][5];
} expression;

typedef struct grammarProduction *pProd;

typedef struct grammarProduction {
  char name[VAR_LENGTH];	
  unsigned int ec; //Expression Counter
  unsigned int cc; //Code Counter
  unsigned int numOr;
  unsigned int numOrAlt;  
  unsigned char terminal;
  unsigned int idTerminal;
  pExp exp;
  unsigned int midicode[DIM_MIDI_CODE][10];
  unsigned char created_by_body;
  unsigned int iterationCounter;
  unsigned char visited;
} production;

typedef struct virtual_player *pPlayer;

typedef struct virtual_player {
  char *identifier;
  int local_params[NUM_LOCAL_PARAMS];
  unsigned char num, den;
  unsigned char grammar;
  unsigned int iterations;
  note_var local_vars[NUM_VARS];
  pProd productions[NUM_PRODS];
} player;

pPlayer players[NUM_PLAYERS];

typedef struct macro_data *pmacro;

typedef struct macro_data {
  char *name, *data;
} macro;

macro macros[NUM_MACRO];

void usageError(void);
unsigned int hash(char *v, unsigned char sentinel);
void initGRAMophone(void);
void init_local_flag(void);
void init_player(void);
int grammyvm();
void print_local_params(unsigned char i);
void print_composition_info();
void print_global_params();
void sntx_err(unsigned int error, char *msg);
void dhInsert(pnote_var noteVar, char *text, unsigned char sentinel, unsigned char created_by_body);
pnote_var dhSearch(char *v, unsigned char sentinel);
char *dhSearch2(char *v);
void code_update(unsigned int cc, unsigned int _goto);
void gen_code(unsigned int op, unsigned int op1);
void gen_code2(unsigned int op);
void gen_code3(unsigned int op, unsigned type, unsigned op1);
void gen_code4(unsigned int op, unsigned op1, unsigned op2, unsigned type);
void gen_note_code(unsigned int op, unsigned int note, unsigned int type1,
		   unsigned int op1, unsigned int type2, unsigned int op2,
		   unsigned int type3, unsigned int op3, unsigned int type4,
		   unsigned int op4);
void gen_exp1_code(unsigned int op, unsigned int type1, unsigned int op1,
		   unsigned int type2, unsigned int op2);
void gen_exp2_code(unsigned int op, unsigned int op1, unsigned int type,
		   unsigned int op2);
void gen_exp3_code(unsigned int op, unsigned int type, unsigned int op1);
void gen_exp4_code(unsigned int op);