7 public static uint32 no_xruns
;
9 public static int jackpanel_xrun_callback (void *panel
) {
14 public abstract class JackpanelBase
: Alignment
{
17 protected string client_name
;
18 protected jack_client_t
* client
;
19 protected jack_status_t status
;
20 protected string time_in_frames
;
21 protected string time_in_bbt
;
22 protected string time_h_min_sec
;
23 protected Pid jackd_pid
;
26 config
= new
Configuration ();
29 protected bool restart_jack () {
32 return initialize_jack ();
35 protected bool start_jack_client () {
36 client
= jack_client_open (client_name
, jack_options_t
.JackNoStartServer
, ref status
);
39 stderr
.printf ("jack_client_open() failed, status = 0x%2.0x\n", status
);
40 if ((status
& jack_status_t
.JackServerFailed
) != 0) {
41 stderr
.printf ("Unable to connect to JACK server\n");
49 protected void stop_jack_client () {
51 jack_deactivate (client
);
52 jack_client_close (client
);
57 protected void stop_jack () {
58 if (jackd_pid
!= (GLib
.Pid
)0) {
59 Posix
.kill ((Posix
.pid_t
)jackd_pid
, Posix
.SIGTERM
);
60 jackd_pid
= (GLib
.Pid
)0;
64 protected bool start_jack () {
65 string jackdrc_filename
= Environment
.get_home_dir () + Path
.DIR_SEPARATOR_S
+ ".jackdrc";
67 if (FileUtils
.test (jackdrc_filename
, FileTest
.EXISTS
) &&
68 FileUtils
.test (jackdrc_filename
, FileTest
.IS_REGULAR
)) {
69 FileUtils
.get_contents (jackdrc_filename
, out jackdrc
);
72 config
.from_command_line (jackdrc
);
75 string cmdline
= config
.to_command_line();
76 stdout
.printf ("Starting jack with command line: %s\n", cmdline
);
77 Shell
.parse_argv (cmdline
, out argv
);
79 for (int i
= 0; i
< argv
.length
; i
++) {
80 stdout
.printf ("argument: %d: %s\n", i
, argv
[i
]);
83 bool jack_started
= Process
.spawn_async (null, argv
, null, 0, null, out jackd_pid
);
85 ChildWatch
.add (jackd_pid
, (pid
, status
) => {
86 stdout
.printf ("Process %d with status %d\n", (int)pid
, (int)status
);
99 protected bool initialize_jack () {
101 if (!start_jack_client ()) {
103 Thread
.usleep (2000000);
105 if (!start_jack_client ()) {
113 if ((status
& jack_status_t
.JackServerStarted
) != 0) {
114 stderr
.printf ("JACK server started\n");
116 if ((status
& jack_status_t
.JackNameNotUnique
) != 0) {
117 client_name
= jack_get_client_name(client
);
118 stderr
.printf ("unique name `%s' assigned\n", client_name
);
122 jack_set_xrun_callback (client
, jackpanel_xrun_callback
, (void *)this
);
124 if (jack_activate (client
) != 0) {
125 stderr
.printf ("cannot activate client");
132 protected abstract void on_transport_stopped ();
133 protected abstract void on_transport_rolling ();
135 protected void show_time (PanelDisplayBase display
) {
136 jack_position_t current
= jack_position_t ();
137 jack_transport_state_t transport_state
;
138 jack_nframes_t frame_time
;
140 transport_state
= jack_transport_query (client
, ref current
);
141 frame_time
= jack_frame_time (client
);
143 var time_seconds
= (int)current
.frame
/ (int)current
.frame_rate
;
144 time_h_min_sec
= "%02d:%02d:%02d".printf (time_seconds
/ 3600, (time_seconds
% 3600) / 60, time_seconds
% 60);
145 time_in_frames
= "%u".printf ((jack_nframes_t
)current
.frame
);
147 switch (transport_state
) {
148 case jack_transport_state_t
.JackTransportStopped
:
149 on_transport_stopped ();
151 case jack_transport_state_t
.JackTransportRolling
:
152 on_transport_rolling ();
154 case jack_transport_state_t
.JackTransportStarting
:
155 //stdout.printf ("state: Starting");
158 stderr
.printf ("jack transport state: [unknown]");
162 if ((current
.valid
& jack_position_bits_t
.JackPositionBBT
) != 0) {
163 time_in_bbt
= "%3u|%u|%04u".printf (current
.bar
, current
.beat
, current
.tick
);
164 display
.time_alt
= time_in_bbt
;
166 display
.time_alt
= time_in_frames
;
169 display
.time
= time_h_min_sec
;
173 } //namespace Jackpanel