7 #include <jack/transport.h>
15 extern GtkWidget
*window1
;
16 void dothejack (gboolean onoff
);
18 void status_msg (char *msg
) {
21 GtkWidget
*statusbar1
;
22 statusbar1
=lookup_widget(window1
,"statusbar1");
24 snprintf(buf
, PATH_MAX
, "%s", msg
);
25 gtk_statusbar_pop(GTK_STATUSBAR(statusbar1
), context
);
26 gtk_statusbar_push(GTK_STATUSBAR(statusbar1
), context
, buf
);
30 void status_printf (const char *format
, ...) {
34 va_start(arglist
, format
);
35 vsnprintf(text
, PATH_MAX
, format
, arglist
);
46 jack_client_t
*jack_client
= NULL
;
47 jack_nframes_t j_srate
= 48000;
51 extern FrameRate
*uffr
;
52 extern FrameRate
*jffr
;
54 /* when jack shuts down... */
55 void jack_shutdown(void *arg
)
58 status_printf ("jack server shutdown");
59 dothejack(0); //< toggle connected button...
62 extern gdouble unit_table
[UNIT_LAST
];
63 /* when jack changes its samplerate ... */
64 int jack_srate_callback(jack_nframes_t nframes
, void *arg
)
66 status_printf("jack sample rate: %i samples per second.",nframes
);
68 // NOTE: this overrides the factor in the table.
69 // we'll be in trouble... ( oldunit == newunit)
70 // if it changes while the spinbutton's value is displayed in Audioframe units.
71 // but it will most probably never change anyway..
72 unit_table
[UNIT_AUDIOFRAMES
] = (gdouble
) 1.0/j_srate
;
77 int jack_connected(void)
79 if (jack_client
) return (1);
86 status_printf ("already connected to jack..");
92 snprintf(jackid
,16,"gjtctl-%i",i
);
93 jack_client
= jack_client_open (jackid
, JackUseExactName
, NULL
);
94 } while (jack_client
== 0 && i
++<16);
97 status_printf("could not connect to jack server.");
99 jack_on_shutdown (jack_client
, jack_shutdown
, 0);
100 jack_set_sample_rate_callback (jack_client
, jack_srate_callback
, NULL
);
101 status_printf("connected as jack client '%s'",jackid
);
102 jack_srate_callback(jack_get_sample_rate(jack_client
),NULL
); // init j_srate
103 jack_activate (jack_client
);
107 void close_jack(void)
110 jack_deactivate (jack_client
);
111 jack_client_close (jack_client
);
112 status_printf("disconnected from jack.");
117 double jack_poll_time (void)
119 jack_position_t jack_position
;
127 /* Calculate frame. */
128 jack_transport_query(jack_client
, &jack_position
);
129 jack_time
= jack_position
.frame
/ (double) jack_position
.frame_rate
;
130 FR_setsamplerate(jffr
,j_srate
);
132 if (jack_position
.valid
&JackAudioVideoRatio
) {
133 double jfps
= jack_position
.frame_rate
/ (double) jack_position
.audio_frames_per_video_frame
;
134 FR_setdbl(jffr
,jfps
,1);
144 void jack_reposition(double sec
)
146 jack_nframes_t frame
= rint(j_srate
* sec
);
148 jack_transport_locate (jack_client
, frame
);
154 jack_transport_stop (jack_client
);
155 status_printf("paused jack transport.");
162 jack_transport_start (jack_client
);
163 status_printf("jack transport rolling.");
167 int jack_poll_transport_state (void) {
169 switch (jack_transport_query(jack_client
, NULL
)) {
170 case JackTransportRolling
:
172 case JackTransportStopped
: