1 
2 /*
3  *  Diverse Bristol audio routines.
4  *  Copyright (c) by Nick Copeland <nickycopeland@hotmail.com> 1996,2012
5  *
6  *
7  *   This program is free software; you can redistribute it and/or modify
8  *   it under the terms of the GNU General Public License as published by
9  *   the Free Software Foundation; either version 3 of the License, or
10  *   (at your option) any later version.
11  *
12  *   This program is distributed in the hope that it will be useful,
13  *   but WITHOUT ANY WARRANTY; without even the implied warranty of
14  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15  *   GNU General Public License for more details.
16  *
17  *   You should have received a copy of the GNU General Public License
18  *   along with this program; if not, see <http://www.gnu.org/licenses/>.
19  *
20  */
21 
22 #ifndef __BRISTOL_ARPEG_H
23 #define __BRISTOL_ARPEG_H
24 
25 /*
26  * The access method for arpeggiator, sequencer and chording is the same, it
27  * uses operator 125.
28  */
29 #define BRISTOL_ARPEGGIATOR 64
30 
31 /*
32  * Commands to the arpeggiator code. Poly-2 is a special case done for the
33  * Jupiter8. All notes always sound (done with Unison mode) and the arpeggiator
34  * spreads the available voices over the notes pressed.
35  */
36 #define BRISTOL_ARPEG_ENABLE	0
37 #define BRISTOL_ARPEG_DIR		1
38 #define BRISTOL_ARPEG_RANGE		2
39 #define BRISTOL_ARPEG_RATE		3
40 #define BRISTOL_ARPEG_CLOCK		4
41 #define BRISTOL_ARPEG_TRIGGER	5
42 #define BRISTOL_ARPEG_POLY_2	6 /* Only works with Unison/Arpeg enabled */
43 
44 #define BRISTOL_CHORD_ENABLE	16
45 #define BRISTOL_CHORD_RESEQ		17 /* Relearn chord */
46 #define BRISTOL_CHORD_KEY		18 /* note sent from GUI memory */
47 
48 #define BRISTOL_SEQ_ENABLE		32
49 #define BRISTOL_SEQ_DIR			33
50 #define BRISTOL_SEQ_RANGE		34
51 #define BRISTOL_SEQ_RATE		35
52 #define BRISTOL_SEQ_CLOCK		36
53 #define BRISTOL_SEQ_TRIGGER		37
54 #define BRISTOL_SEQ_RESEQ		38 /* Relearn sequence */
55 #define BRISTOL_SEQ_KEY			39 /* note sent from GUI memory */
56 
57 /* The sequencer uses the same direction flags */
58 #define BRISTOL_ARPEG_DOWN	0
59 #define BRISTOL_ARPEG_UD	1
60 #define BRISTOL_ARPEG_UP	2
61 #define BRISTOL_ARPEG_RND	3
62 
63 /*
64  * This is the real number of steps we can keep.
65  */
66 #define BRISTOL_SEQ_MIN			4
67 #define BRISTOL_CHORD_MAX		8
68 #define BRISTOL_ARPEG_MAX		128
69 #define BRISTOL_SEQ_MAX			256
70 
71 /*
72  * Some flags for runtime stuff
73  */
74 #define BRISTOL_SEQ_LEARN	0x0001
75 #define BRISTOL_CHORD_LEARN	0x0002
76 #define BRISTOL_A_TRIGGER	0x0004 /* Currently internal only */
77 #define BRISTOL_A_CLOCK		0x0008
78 #define BRISTOL_S_TRIGGER	0x0010 /* Currently internal only */
79 #define BRISTOL_S_CLOCK		0x0020
80 #define BRISTOL_POLY_2		0x0040 /* All notes always on, split between keys */
81 #define BRISTOL_REQ_TRIGGER	0x0080
82 #define BRISTOL_DONE_FIRST	0x0100
83 
84 /*
85  * They key id and velocity are stored when learning from a keyboard however
86  * this is not honoured as velocity is inherited from the from the voice, not
87  * from the arpeggiator. Also, when programmed internally they only have a key
88  * id and velocity is fixed. Changes to that are FFS.
89  */
90 typedef struct ArpNote {
91 	int k, v;
92 } arpNote;
93 
94 typedef struct ArpSeq {
95 	int rate; /* Always configured */
96 	int span; /* Configured number of octaves to cover */
97 	int dir; /* Configured sequence direction */
98 	int max;	/* Total number of notes in the sequence (config/learnt) */
99 	int count; /* current scan through the rate */
100 	int step; /* going up or down through the sequence */
101 	//int d_offset; /* sample accurate correction for note events */
102 	int dif; /* Note difference - for sequencer only */
103 	int vdif; /* velocity difference - for sequencer only */
104 	int current; /* current note index */
105 	int octave; /* current octave */
106 	arpNote notes[BRISTOL_SEQ_MAX + 1];
107 } arpSeq;
108 
109 /*
110  * This gets buried into the baudio structure for the emulation
111  */
112 typedef struct Arpeggiator {
113 	unsigned int flags;
114 	/*
115 	 * These is for arpeggiating, sequencing and chording respectively. The
116 	 * chording uses very few parameters and also far fewer notes than in
117 	 * this structure however it is cleaner this way.
118 	 */
119 	arpSeq a;
120 	arpSeq s;
121 	arpSeq c;
122 } arpeggiator;
123 
124 /*
125  * This typedef is used by the GUI so that it can bury the settings into a
126  * normally formatted bristol memory in the sequencer directory and have the
127  * synth reload it automatically.
128  *
129  * Stored notes from the GUI do not carry velocity.
130  */
131 #define BRISTOL_AM_SMAX 0
132 #define BRISTOL_AM_CCOUNT 1
133 typedef struct ArpeggiatorMemory {
134 	float s_max;
135 	float c_count;
136 	float s_dif;
137 	float c_dif;
138 	float sequence[BRISTOL_SEQ_MAX + 1];
139 	float chord[BRISTOL_CHORD_MAX + 1];
140 } arpeggiatorMemory;
141 
142 #endif
143 
144