allow to configure SMPTE font.
[gjacktransport.git] / src / main.c
blob61f42f9299e05c4d4cb70aa04c2aa5911981fd46
1 /* gjacktransport - jack transport slider
2 * Copyright (C) 2006 Robin Gareus <robin AT 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 of the License, or
7 * (at your option) any later version.
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
16 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
19 #ifdef HAVE_CONFIG_H
20 # include <config.h>
21 #endif
23 #include <stdio.h>
24 #include <gtk/gtk.h>
25 #include <getopt.h>
26 #include <libintl.h>
28 #include "interface.h"
29 #include "support.h"
30 #include "gjack.h"
31 #include "gjacktransport.h"
32 #include "framerate.h"
34 char *program_name;
35 GtkWidget *window1;
36 FrameRate *jffr; //< jack video FPS
37 FrameRate *uffr; //< user set FPS
38 FrameRate *fffr; //< pointer to currently used.
40 gjtdata *stg; // settings
41 int mem = 0; // current mem
42 double stride = 10; // seek stride (in seconds)
43 int want_quiet = 0;
44 int no_lash = 0; // don't try to use LASH
45 int max_mem = 6;
46 int setup_done = 0;
47 char *smpte_font = NULL;
49 #ifdef HAVE_LASH
50 # include <lash/lash.h>
51 void lash_setup(void); //< prototype - fn defined in lash.c
52 lash_client_t *lash_client = NULL;
53 #endif
54 void lash_process(void);
56 // prototypes - defined in callbacks.c
57 gboolean gpolljack (gpointer data);
58 void initialize_gjt (void);
59 void update_spinbtns(void);
60 void update_combotxt (int pos);
61 gboolean limit_height (gpointer data);
63 // prototypes - defined in resourceconfig.c
64 void load_rc (void);
65 void try_load_rc_file (char *filename);
67 static GdkPixmap *gjt_icon_pixmap;
68 static GdkBitmap *gjt_icon_mask;
69 #include "gjt_icon.xpm"
72 static void usage (int status) {
73 printf("%s - JACK transport slider.\n",program_name);
74 printf("usage: %s [Options] [start-marker [end-marker]]\n",program_name);
75 printf (""
76 "Options:\n"
77 " -h, --help display this help and exit\n"
78 " -V, --version print version information and exit\n"
79 " -q, --quiet, --silent inhibit usual output\n"
81 "unit for start/end markers: seconds. (eg 10 60.5)\n"
83 exit(status);
86 static void printversion (void) {
87 printf ("gjacktransport %s\n (C) GPL 2007, 2010 Robin Gareus <robin@gareus.org>\n", VERSION);
90 gboolean glashproc (gpointer data) {
91 lash_process();
92 return(TRUE);
96 static struct option const long_options[] =
98 {"help", no_argument, 0, 'h'},
99 {"quiet", no_argument, 0, 'q'},
100 {"silent", no_argument, 0, 'q'},
101 {"version", no_argument, 0, 'V'},
102 {NULL, 0, NULL, 0}
106 static int
107 decode_switches (int argc, char **argv)
109 int c;
110 while ((c = getopt_long (argc, argv,
111 "q" /* quiet or silent */
112 "L" /* no lash */
113 "h" /* help */
114 "V", /* version */
115 long_options, (int *) 0)) != EOF)
117 switch (c) {
118 case 'q': /* --quiet, --silent */
119 want_quiet = 1;
120 break;
121 case 'L': /* --nolash */
122 no_lash = 1;
123 break;
124 case 'V':
125 printversion();
126 exit(0);
127 case 'h':
128 usage (0);
129 default:
130 usage (EXIT_FAILURE);
133 return optind;
137 int main (int argc, char *argv[]) {
138 GtkWidget *w;
139 program_name = argv[0];
141 #ifdef ENABLE_NLS
142 bindtextdomain (GETTEXT_PACKAGE, PACKAGE_LOCALE_DIR);
143 bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8");
144 textdomain (GETTEXT_PACKAGE);
145 #endif
147 gtk_init(&argc, &argv);
148 #ifdef HAVE_LASH
149 lash_args_t *lash_args = lash_extract_args(&argc, &argv);
150 #endif
152 initialize_gjt();
154 int i = decode_switches (argc, argv);
155 if (argc > i+2 ) usage(1);
157 window1 = create_window1();
159 w = lookup_widget(window1,"combobox1");
160 gtk_combo_box_set_active (GTK_COMBO_BOX(w),6);
161 w = lookup_widget(window1,"combobox2");
162 gtk_combo_box_set_active (GTK_COMBO_BOX(w),2);
163 w = lookup_widget(window1,"combobox3");
164 gtk_combo_box_set_active (GTK_COMBO_BOX(w),0);
165 w = lookup_widget(window1,"combobox4");
166 gtk_combo_box_set_active (GTK_COMBO_BOX(w),0);
167 w = lookup_widget(window1,"combobox5");
168 gtk_combo_box_set_active (GTK_COMBO_BOX(w),0);
170 load_rc();
172 if (argc-i == 2) {
173 /* set start end end marker */
174 mem=0;
175 stg[0].unit=UNIT_SEC;
176 stg[0].start=strtod(argv[i],NULL); //* unit_table[stg[0].unit];
177 stg[0].end=strtod(argv[i+1],NULL); //* unit_table[stg[0].unit];
178 } else if (argc-i == 1) {
179 /* set end marker only */
180 mem=0;
181 stg[0].unit=UNIT_SEC;
182 stg[0].end=strtod(argv[i],NULL);; //* unit_table[stg[0].unit];
185 for (i=0;i<max_mem; i++) {
186 update_combotxt(i);
189 if (mem >= max_mem) mem=max_mem-1;
190 if (mem < 0) mem=0;
191 gtk_combo_box_set_active (GTK_COMBO_BOX(w),mem);
192 update_spinbtns();
193 if (smpte_font)
194 gtk_widget_modify_font (
195 lookup_widget(window1,"label_smpte"),
196 pango_font_description_from_string (smpte_font));
199 #ifdef HAVE_LASH
200 if (!no_lash) {
201 lash_client = lash_init (lash_args, PACKAGE_NAME, 0 | LASH_Config_Data_Set ,LASH_PROTOCOL (2,0));
202 if (!lash_client) {
203 fprintf(stderr, "could not initialise LASH!\n");
204 } else {
205 lash_setup();
206 if (!want_quiet) printf("Connected to LASH.\n");
208 //lash_args_destroy(lash_args);
210 #endif
211 setup_done=1;
213 gtk_widget_show (window1);
214 gjt_icon_pixmap = gdk_pixmap_create_from_xpm_d (window1->window, &gjt_icon_mask, NULL, gjt_icon_xpm);
216 gdk_window_set_icon(window1->window, NULL, gjt_icon_pixmap, gjt_icon_mask);
217 //gdk_pixbuf_unref (window1_icon_pixbuf);
218 gtk_idle_add(limit_height, NULL);
219 g_timeout_add(40,gpolljack,NULL);
220 #ifdef HAVE_LASH
221 if (!no_lash) {
222 g_timeout_add(250,glashproc,NULL);
224 #endif
225 gtk_main ();
227 FR_free(uffr);
228 FR_free(jffr);
229 for (i=0;i<max_mem;i++){
230 if (stg[i].name) free(stg[i].name);
232 free(stg);
233 if (smpte_font) free(smpte_font);
234 return 0;
236 /* vi:set ts=8 sw=2: */