1 /* gjacktransport - .rc interface
2 * Copyright (C) 2007, 2010 Robin Gareus <robin@gareus.org>
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2, or (at your option)
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software Foundation,
16 * Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
23 #ifndef GJACKTRANSPORTRC
24 # define GJACKTRANSPORTRC "gjacktransportrc"
27 #ifdef PACKAGE_SYSCONFIGDIR
28 # define SYSCFGDIR PACKAGE_SYSCONFIGDIR
30 # define SYSCFGDIR "/etc"
37 #include <sys/types.h>
42 #include "gjacktransport.h"
43 #include "framerate.h"
45 /* test if file exists and is a regular file - returns 1 if ok */
46 int testfile (char *filename
) {
48 int result
= stat(filename
, &s
);
49 if (result
!= 0) return 0; /* stat() failed */
50 if (S_ISREG(s
.st_mode
)) return 1; /* is a regular file - ok */
54 extern FrameRate
*fffr
;
55 extern FrameRate
*uffr
;
56 extern FrameRate
*jffr
;
58 extern gint key_cfg
[MAX_KEYBINDING
];
62 extern gjtdata stg
[MAX_MEM
];
63 extern GtkWidget
*window1
;
66 extern int want_quiet
;
68 /* restore config functions - see callbacks.c */
69 void select_mem (int newmem
);
70 void showhide (char *togglebtn
, char *widget
, gboolean display
);
71 gboolean
ishidden (char *widget
); //toggle-btn name
72 void dothejack (gboolean onoff
);
73 void update_spinbtns(void);
75 gint my_root_x
, my_root_y
, my_width
, my_height
;
77 int parse_rc(const char*key
, const char *value
) {
78 if (!strncmp(key
,"memory_",7)) {
79 int mymem
= atoi(key
+7);
80 if (mymem
< 1 || mymem
> MAX_MEM
) return -1;
82 if (!strcmp(key
+9,"_start")) {
83 stg
[mymem
].start
=strtod(value
, NULL
);
84 } else if (!strcmp(key
+9,"_end")) {
85 stg
[mymem
].end
=strtod(value
, NULL
);
86 } else if (!strcmp(key
+9,"_unit")) {
87 stg
[mymem
].unit
=atoi(value
);
90 printf("Warning: unhandled mem: %s=%f\n",key
+7,strtod(value
, NULL
));
94 } else if (!strncmp(key
,"keybinding_",11)) {
95 int mykey
= atoi(key
+11);
96 if (mykey
< 1 || mykey
> MAX_KEYBINDING
) return -1;
98 key_cfg
[mykey
]=atoi(value
);
99 } else if (!strcmp(key
,"syncsource")) {
100 dothejack(atoi(value
));
101 } else if (!strcmp(key
,"cur_mem")) {
102 select_mem(atoi(value
)-1);
103 } else if (!strcmp(key
,"seek_stride")) {
104 stride
=strtod(value
, NULL
);
105 } else if (!strcmp(key
,"tb_status")) {
106 showhide("checkbutton5","statusbar1",atoi(value
));
107 } else if (!strcmp(key
,"tb_zoom")) {
108 showhide("checkbutton3","handlebox3",atoi(value
));
109 } else if (!strcmp(key
,"tb_memory")) {
110 showhide("checkbutton7","handlebox4",atoi(value
));
111 } else if (!strcmp(key
,"tb_all")) {
112 showhide("checkbutton6","table1",atoi(value
));
113 } else if (!strcmp(key
,"tb_transport")) {
114 showhide("checkbutton4","handlebox1",atoi(value
));
115 } else if (!strcmp(key
,"tb_unit")) {
116 showhide("checkbutton2","handlebox2",atoi(value
));
117 } else if (!strcmp(key
,"tb_timelabels")) {
118 showhide("checkbutton8","hbox_labels",atoi(value
));
119 } else if (!strcmp(key
,"FR_mode")) {
120 if (atoi(value
)) fffr
=jffr
; // XXX
122 } else if (!strcmp(key
,"FR_flags")) {
123 uffr
->flags
=atoi(value
);
124 } else if (!strcmp(key
,"win_x")) {
125 my_root_x
=atoi(value
);
126 } else if (!strcmp(key
,"win_y")) {
127 my_root_y
=atoi(value
);
128 } else if (!strcmp(key
,"win_w")) {
129 my_width
=atoi(value
);
130 } else if (!strcmp(key
,"win_h")) {
131 my_height
=atoi(value
);
132 } else if (!strcmp(key
,"no_lash")) {
136 fprintf (stderr
, "WARNING: unhandled Config parameter Key = '%s' \n", key
);
142 #define MAX_LINE_LEN 256
144 void read_rc(const char *fn
) {
146 gtk_window_get_size (GTK_WINDOW(window1
), &my_width
, &my_height
);
147 gtk_window_get_position (GTK_WINDOW(window1
), &my_root_x
, &my_root_y
);
149 char line
[MAX_LINE_LEN
];
153 printf("reading .rc: '%s'\n", fn
);
155 if (!(config_fp
= fopen(fn
, "r"))) {
157 fprintf(stderr
,"reading configfile failed: %s (%s)\n",fn
,strerror(errno
));
160 while( fgets( line
, MAX_LINE_LEN
-1, config_fp
) != NULL
) {
161 char *item
, *token
, *value
;
163 line
[MAX_LINE_LEN
-1]=0;
164 token
= strtok(line
, "\t =\n\r");
166 if(token
== NULL
|| token
[0] == '#' || token
[0] == ';') continue;
168 token
= strtok(NULL
, "\t =\n\r");
172 printf("WARNING: ignored line in config file. %s:%d\n",fn
,lineno
);
175 printf("ERROR parsing config file. %s:%d\n",fn
,lineno
);
180 if (parse_rc(item
,value
)) {
182 printf("WARNING: ignored error in config file. %s:%d\n",fn
,lineno
);
184 printf("ERROR parsing config file. %s:%d\n",fn
,lineno
);
188 free(item
); free(value
);
193 if (my_width
> 0 && my_height
> 0)
194 gtk_window_resize(GTK_WINDOW(window1
),my_width
,my_height
);
195 if (my_root_x
> 0 && my_root_y
> 0)
196 gtk_window_move(GTK_WINDOW(window1
),my_root_x
,my_root_y
);
199 void load_rc (void) {
201 char filename
[PATH_MAX
];
202 if ((strlen(SYSCFGDIR
) + strlen(GJACKTRANSPORTRC
) + 2) < PATH_MAX
) {
203 sprintf(filename
, "%s/%s", SYSCFGDIR
, GJACKTRANSPORTRC
);
204 if (testfile(filename
)) read_rc(filename
);
206 home
= getenv("HOME");
207 if (home
&& (strlen(home
) + strlen(GJACKTRANSPORTRC
) + 2) < PATH_MAX
) {
208 sprintf(filename
, "%s/.%s", home
, GJACKTRANSPORTRC
);
209 if (testfile(filename
)) read_rc(filename
);
211 if (strlen(GJACKTRANSPORTRC
) + 2 < PATH_MAX
) {
212 sprintf(filename
, "./%s", GJACKTRANSPORTRC
);
213 if (testfile(filename
)) read_rc(filename
);
217 void write_rc(const char *fn
) {
220 if (!(fp
= fopen(fn
, "w"))) {
222 fprintf(stderr
,"writing configfile failed: %s (%s)\n",fn
,strerror(errno
));
225 gtk_window_get_size (GTK_WINDOW(window1
), &my_width
, &my_height
);
226 gtk_window_get_position (GTK_WINDOW(window1
), &my_root_x
, &my_root_y
);
228 fprintf(fp
, "# config file for gjacktransport\n#\n# lines beginning with '#' or ';' are ignored.\n#\n");
229 fprintf(fp
, "# @sysconfdir@/gjacktransportrc\n# $HOME/.gjacktransportrc\n# ./gjacktransportrc\n#\n");
231 fprintf(fp
, "\n# PRESET/MEMORY #\n; load-memory preset: 01..06\n");
232 fprintf(fp
, "cur_mem=%02i\n", mem
+1);
234 fprintf(fp
, "\n; mem-id 01..06\n; start/end values are in seconds\n; unit: hour:0, min:1, sec:2, audio-frames:3 - display only\n");
235 for (i
=0; i
< MAX_MEM
; i
++) {
236 fprintf(fp
, "memory_%02i_start=%f\n", i
+1, stg
[i
].start
);
237 fprintf(fp
, "memory_%02i_end=%f\n", i
+1, stg
[i
].end
);
238 fprintf(fp
, "memory_%02i_unit=%i\n\n", i
+1, stg
[i
].unit
);
241 fprintf(fp
, "\n# KEYBINDINGS #\n");
242 const char *kbc
[MAX_KEYBINDING
] = {
243 /* TODO : sync w/ callbacks.c -> .h*/
244 "play/pause", "fast-rew", "fast-ffw", "play", "pause", "rewind", "skip-start", "skip-end"
247 for (i
=0; i
< MAX_KEYBINDING
; i
++) {
248 fprintf(fp
,"; %s\n", kbc
[i
]);
249 fprintf(fp
,"keybinding_%i=%i\n",i
+1, key_cfg
[i
]);
252 fprintf(fp
, "\n\n# SHOW/HIDE TOOL-BARS #\n");
253 fprintf(fp
, "tb_all=%i\n", ishidden("checkbutton6")?1:0);
254 fprintf(fp
, "tb_status=%i\n", ishidden("checkbutton5")?1:0);
255 fprintf(fp
, "tb_zoom=%i\n", ishidden("checkbutton3")?1:0);
256 fprintf(fp
, "tb_memory=%i\n", ishidden("checkbutton7")?1:0);
257 fprintf(fp
, "tb_transport=%i\n", ishidden("checkbutton4")?1:0);
258 fprintf(fp
, "tb_unit=%i\n", ishidden("checkbutton2")?1:0);
259 fprintf(fp
, "tb_timelabels=%i\n", ishidden("checkbutton8")?1:0);
261 fprintf(fp
, "\n\n# WINDOW POSITION/SIZE #\n");
262 fprintf(fp
, "win_x=%i\n", my_root_x
);
263 fprintf(fp
, "win_y=%i\n", my_root_y
);
264 fprintf(fp
, "win_w=%i\n", my_width
);
265 fprintf(fp
, "win_h=%i\n", my_height
);
267 fprintf(fp
, "\n\n# MISC #\n");
268 fprintf(fp
, "; set to 1 to auto-connect to JACK\n");
269 fprintf(fp
, "syncsource=%i\n", jack_connected()?1:0);
270 fprintf(fp
, "\n; 1: use JACK video-framerate (if set by time-master)\n");
271 fprintf(fp
, "FR_mode=%i\n", (jffr
==fffr
)?1:0);
272 fprintf(fp
, "\n; seek-stride (in seconds)\n");
273 fprintf(fp
, "seek_stride=%f\n", stride
);
274 fprintf(fp
, "\n; do not try to use LASH\n");
275 fprintf(fp
, "no_lash=%i\n", no_lash
?1:0);
280 fprintf(stderr
,"written config: %s\n",fn
);