File: meterec.h

package info (click to toggle)
meterec 0.8~ds0-1
  • links: PTS, VCS
  • area: main
  • in suites: wheezy
  • size: 516 kB
  • sloc: ansic: 1,862; sh: 1,228; makefile: 11
file content (249 lines) | stat: -rw-r--r-- 6,079 bytes parent folder | download
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
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
/*

  meterec.h 
  Console based multi track digital peak meter and recorder for JACK
  Copyright (C) 2010 Fabrice Lebas
  
  This program 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 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., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.

*/



/* maximum number of connections per port - no known limit*/
#define MAX_CONS 24

/* maximum number of ports - no known limit, only extra memory used */
#define MAX_PORTS 24

/* maximum number of tracks - no known limit, only extra memory used */
#define MAX_TRACKS MAX_PORTS

/* maximum number of takes - no known limit, only extra memory used */
#define MAX_TAKES 100

/* size of disk wait buffer, must be power of two */
#define DISK_SIZE 131072

/* size of disk buffers */
#define BUF_SIZE 4096

/*number of seek indexes*/
#define MAX_INDEX 12

/* commands */
#define STOP 0
#define START 1
#define RESTART 2
#define PAUSE 3 

/* status */
#define OFF 0
#define STARTING 1
#define ONGOING 2
#define STARVING 3
#define STOPING 4
#define PAUSED 5

/* type of recording */
#define REC 1
#define DUB 2
#define OVR 4
#define MAX_REC OVR*2

/* display colors */
#define DEFAULT 0
#define GREEN 1
#define YELLOW 2
#define RED 3
#define BLUE 4


/*
note : 
- take 0 is before the session start, there will never be data in take 0
- track 0 is the first track, displayed as 1 
*/

/*
note : 
- a session contains several takes
- a take contains one or several tracks that where recorded at the same time.
  - in a take, the number of tracks will vary depending on the number of ports beeing recorded during that take.
  - in a take, the number of tracks beeing used for playback can be less than the total number of tracks in the take.
- current take contains tracks beeing recorded during this run.
- port refers to jack in/out port.
  - an in port can be recorded during the current take. it will then be a track of this take, potentially played back duing next(s) take(s).
  - an out port can playback previous take track, as long as this previous take contains a track mapped to that port.


=PP-----|01
=PP-----|02
=-P----P|03
=-P-----|04
=--PP---|05
=--PP---|06
=----P--|07
=-----PP|08recording
01234567

take 0 cannot contain any track. This is the state of the session when first started.
take 1 contains 2 tracks that are mapped on port 1 and 2
take 2 contains 4 tracks that are mapped on port 1, 2, 3 and 4
take 3 contains 2 tracks that are mapped on port 5 and 6
take 4 contains 2 tracks that are mapped on port 5 and 6
take 5 contains 1 track that is mapped on port 7
take 6 contains 1 track that is mapped on port 8
take 7 contains 2 tracks that are mapped on port 8 and 3

*/

struct time_s 
{
	unsigned int h,m,s,ms,frm,rate;
};

struct take_s
{
  unsigned int ntrack; /* number of tracks in this take */
  
  unsigned int track_port_map[MAX_TRACKS]; /* track maps to a port : track_port_map[track] = port */
  unsigned int port_has_track[MAX_PORTS]; /* port has a track assigned : port_has_track[port] = 1/0 */ 
  unsigned int port_has_lock[MAX_PORTS]; /* port is marked locked for playback on this take : port_has_lock[port] = 1/0 */

  char *take_file;
  SNDFILE *take_fd;
  SF_INFO info;
  
  float *buf ;
 
};


struct port_s
{

  jack_port_t *input;
  jack_port_t *output;
  
  unsigned int portmap;
  char *connections[MAX_CONS];
  char *name;
  
  float *write_disk_buffer;
  float *read_disk_buffer;
  
  float peak_in;
  float max_in;
  float peak_out;

  float db_in;
  float db_max_in;
  float db_out;
  
  int dkmax_in;
  int dkpeak_in;
  int dktime_in;
  
  int record;
  int mute;
  int monitor;

  unsigned int playback_take;

};

struct seek_s 
{
  pthread_mutex_t mutex ;

  jack_nframes_t index[MAX_INDEX];
  
  /* request from keyboard thread to disk thread */
  jack_nframes_t disk_playhead_target;
  int files_reopen; 
  
  /* request of disk thread to jack process */
  unsigned int jack_buffer_target;
  jack_nframes_t playhead_target;
  
  /* do not allow severeal pending seek requests */
  unsigned int keyboard_lock;
  
};

struct meterec_s
{
  FILE *fd_log ;

  char *session_file;
  char *setup_file;
  char *conf_file;
  char *log_file;

  unsigned int record_sts;
  unsigned int record_cmd;

  unsigned int playback_sts;
  unsigned int playback_cmd; 
  
  unsigned int curses_sts;
  unsigned int config_sts;
  unsigned int jack_sts;
  
  
  int connect_ports;
  
  unsigned int n_ports;
  struct port_s ports[MAX_PORTS];
  
  unsigned int n_takes;
  struct take_s takes[MAX_TAKES];

  unsigned int n_tracks;

  jack_client_t *client;
  jack_nframes_t jack_buffsize;

  jack_port_t *monitor;
  
  struct seek_s seek;
  
  unsigned int output_fmt;
  char *output_ext;

  unsigned int write_disk_buffer_thread_pos;
  unsigned int write_disk_buffer_process_pos;
  unsigned int write_disk_buffer_overflow;

  unsigned int read_disk_buffer_thread_pos;
  unsigned int read_disk_buffer_process_pos;
  unsigned int read_disk_buffer_overflow;

};

void stop(void);
void exit_on_error(char * reason);
void compute_takes_to_playback(struct meterec_s *meterec);
void compute_tracks_to_record(struct meterec_s *meterec);
void connect_any_port(jack_client_t *client, char *port_name, unsigned int port);
void time_frm(struct time_s * time);
void time_sprint(struct time_s * time, char * string);
void time_hms(struct time_s * time);

void create_input_port(jack_client_t *client, unsigned int port);
void create_output_port(jack_client_t *client, unsigned int port);
void create_monitor_port(jack_client_t *client);