* first running jack transport client
[jackpanel.git] / jackpanel / Jackpanel.vala
blob588a29172464111ad3cfe4748a787f5eb556fd04
1 using Gtk;
2 using Gdk;
3 using Prolooks;
5 namespace Jackpanel {
7 public class Display : DisplayBase {
8 private string _time;
9 public string time { get { return _time; } set { _time = value; queue_draw (); } }
11 private int inner_height;
13 Display () {
14 width = 182;
15 height = 49;
16 inner_height = height - 13;
17 _time = "00:00:00";
18 set_size_request (width, height);
21 protected override bool draw_contents (Cairo.Context cr, Gdk.EventExpose event) {
22 double x = 32;
23 double y = 16;
24 text(cr, _time, x, y, 16);
25 Cairo.TextExtents ext = Cairo.TextExtents();
26 cr.text_extents (_time, ref ext);
28 Color line_color;
29 Color.parse (text_color_default, out line_color);
30 set_source_from_color (cr, line_color, 0.5);
33 cr.move_to (x, y + ext.y_bearing);
34 cr.rel_line_to (0, ext.height);
35 cr.stroke();
37 cr.move_to (x + ext.x_advance + ext.x_bearing, y + ext.y_bearing);
38 cr.rel_line_to (0, ext.height);
39 cr.stroke();
42 cr.move_to (3, inner_height - 13);
43 cr.rel_line_to (width - 20, 0);
44 cr.stroke();
45 return false;
49 Jackpanel panel;
51 jack_client_t *client;
52 jack_status_t status;
53 jack_transport_state_t transport_state;
54 jack_transport_state_t previous_transport_state;
56 public static int process (uint32 nframes, void *arg)
59 transport_state = jack_transport_query(client, null);
60 if (transport_state != previous_transport_state) {
61 if (transport_state == jack_transport_state_t.JackTransportRolling) {
62 stdout.printf ("transport started\n");
63 } else if (transport_state == jack_transport_state_t.JackTransportStopped) {
64 stdout.printf ("transport stopped\n");
67 previous_transport_state = transport_state;
71 return 0;
74 public static void initialize_jack (string client_name) {
75 client = jack_client_open (client_name, jack_options_t.JackNullOption, ref status);
76 if (client == null) {
77 stderr.printf ("jack_client_open() failed, status = 0x%2.0x\n", status);
78 if ((status & jack_status_t.JackServerFailed) != 0) {
79 stderr.printf ("Unable to connect to JACK server\n");
83 if ((status & jack_status_t.JackServerStarted) != 0) {
84 stderr.printf ("JACK server started\n");
86 if ((status & jack_status_t.JackNameNotUnique) != 0) {
87 client_name = jack_get_client_name(client);
88 stderr.printf ("unique name `%s' assigned\n", client_name);
91 jack_set_process_callback (client, (JackProcessCallback)process, null);
93 if (jack_activate (client) != 0) {
94 stderr.printf ("cannot activate client");
98 public class Jackpanel : Alignment {
99 Jackpanel () {
100 var table = new Table (5, 2, false);
101 var display = new Display ();
102 var to_start = new TransportButton (TransportButton.IconType.TO_START);
103 to_start.height = 20;
104 to_start.width = 31;
106 var fast_backward = new TransportButton (TransportButton.IconType.FAST_BACKWARD);
107 fast_backward.height = 20;
108 fast_backward.width = 31;
110 var play = new TransportButton (TransportButton.IconType.PLAY);
111 play.height = 20;
112 play.width = 31;
114 var stop = new TransportButton (TransportButton.IconType.STOP);
115 stop.height = 20;
116 stop.width = 31;
118 var fast_forward = new TransportButton (TransportButton.IconType.FAST_FORWARD);
119 fast_forward.height = 20;
120 fast_forward.width = 31;
122 table.attach_defaults (display, 0, 5, 0, 1);
124 table.attach_defaults (to_start, 0, 1, 1, 2);
125 table.attach_defaults (fast_backward, 1, 2, 1, 2);
126 table.attach_defaults (fast_forward, 2, 3, 1, 2);
127 table.attach_defaults (stop, 3, 4, 1, 2);
128 table.attach_defaults (play, 4, 5, 1, 2);
130 table.set_col_spacing (0, 4);
131 table.set_col_spacing (1, 4);
132 table.set_col_spacing (2, 10);
133 table.set_col_spacing (3, 4);
135 add (table);
138 static int main (string[] args) {
139 Gtk.init (ref args);
140 var window = new Gtk.Window (Gtk.WindowType.TOPLEVEL);
141 panel = new Jackpanel ();
142 initialize_jack (Path.get_basename(args[0]));
143 window.add (panel);
144 window.destroy += Gtk.main_quit;
145 window.show_all ();
146 Gtk.main ();
147 return 0;
151 } //namespace Jackpanel