1 /*
2     TiMidity++ -- MIDI to WAVE converter and player
3     Copyright (C) 1999-2002 Masanao Izumo <mo@goice.co.jp>
4     Copyright (C) 1995 Tuukka Toivonen <tt@cgs.fi>
5 
6     This program is free software; you can redistribute it and/or modify
7     it under the terms of the GNU General Public License as published by
8     the Free Software Foundation; either version 2 of the License, or
9     (at your option) any later version.
10 
11     This program is distributed in the hope that it will be useful,
12     but WITHOUT ANY WARRANTY; without even the implied warranty of
13     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14     GNU General Public License for more details.
15 
16     You should have received a copy of the GNU General Public License
17     along with this program; if not, write to the Free Software
18     Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
19 
20     quantity.h
21 
22    	by Kentaro Sato	<kentaro@ranvis.com>
23 */
24 
25 #ifndef ___QUANTITY_H_
26 #define ___QUANTITY_H_
27 
28 #define QUANTITY_UNIT_TYPE(u)		QUANTITY_OF_##u, QUANTITY_UNIT_NAME(u##_NUM)
29 #define QUANTITY_UNIT_NAME(name)	QUANTITY_UNIT_##name
30 enum quantity_units {
31 	QUANTITY_UNIT_TYPE(UNDEFINED),		/* type only */
32 	QUANTITY_UNIT_TYPE(DIRECT_INT),		/* internal use */
33 	QUANTITY_UNIT_TYPE(DIRECT_FLOAT),	/* internal use */
34 	QUANTITY_UNIT_TYPE(TREMOLO_SWEEP),			/* int */
35 		QUANTITY_UNIT_NAME(TREMOLO_SWEEP_MS),	/* int */
36 	QUANTITY_UNIT_TYPE(TREMOLO_RATE),			/* int */
37 		QUANTITY_UNIT_NAME(TREMOLO_RATE_MS),	/* int */
38 		QUANTITY_UNIT_NAME(TREMOLO_RATE_HZ),	/* float */
39 	QUANTITY_UNIT_TYPE(VIBRATO_SWEEP),			/* int */
40 		QUANTITY_UNIT_NAME(VIBRATO_SWEEP_MS),	/* int */
41 	QUANTITY_UNIT_TYPE(VIBRATO_RATE),			/* int */
42 		QUANTITY_UNIT_NAME(VIBRATO_RATE_MS),	/* int */
43 		QUANTITY_UNIT_NAME(VIBRATO_RATE_HZ),	/* float */
44 };
45 #undef QUANTITY_UNIT_TYPE
46 #define QUANTITY_UNIT_TYPE(u)		QUANTITY_OF_##u
47 
48 #define INIT_QUANTITY(q)		(q).type = QUANTITY_UNIT_TYPE(UNDEFINED)
49 #define IS_QUANTITY_DEFINED(q)	((q).type != QUANTITY_UNIT_TYPE(UNDEFINED))
50 
51 typedef struct Quantity_ {
52 	uint16			type, unit;
53 	union {
54 		int32			i;
55 		FLOAT_T			f;
56 	} value;
57 } Quantity;
58 
59 extern const char *string_to_quantity(const char *string, Quantity *quantity, uint16 type);
60 extern void int_to_quantity(int32 number, Quantity *quantity, uint16 type);
61 extern void float_to_quantity(FLOAT_T number, Quantity *quantity, uint16 type);
62 extern int32 quantity_to_int(const Quantity *quantity, int32 param);
63 extern FLOAT_T quantity_to_float(const Quantity *quantity, int32 param);
64 
65 #ifdef ___QUANTITY_C_	/* definitions that are only used in quantity.c and will rarely change */
66 
67 typedef int32 (*QuantityToIntProc)(int32 value, int32 param);
68 typedef FLOAT_T (*QuantityToFloatProc)(FLOAT_T value, int32 param);
69 typedef union {
70 	QuantityToIntProc	i;
71 	QuantityToFloatProc	f;
72 } QuantityConvertProc;
73 
74 typedef struct {
75 	const char			*suffix;
76 	uint16				type, id;
77 	int					float_type;		/* is floating-point type */
78 	QuantityConvertProc	convert;
79 } QuantityHint;
80 
81 #endif /* ___QUANTITY_C_ */
82 
83 #endif /* ___QUANTITY_H_ */
84