/[cabestan]/callbacks.c
ViewVC logotype

Contents of /callbacks.c

Parent Directory Parent Directory | Revision Log Revision Log


Revision 8 - (show annotations)
Tue Oct 6 11:19:53 2009 UTC (8 years, 1 month ago) by ben
File MIME type: text/plain
File size: 3737 byte(s)
removed useless mutexes
1 #include <glib.h>
2 #include <gtk/gtk.h>
3 #include <jack/jack.h>
4 #include <jack/transport.h>
5 #include "cabestan.h"
6
7 /* these globals are used for step forward and step backward */
8 static gboolean stepf_released = TRUE;
9 static gboolean stepr_released = TRUE;
10
11 /* start rolling */
12 void on_play (GtkButton* button, gpointer app_data) {
13 jack_client_t* client = (jack_client_t*)app_data;
14 GtkWidget* pauseimage = NULL;
15 GtkWidget* playimage = NULL;
16 jack_position_t tpos;
17 jack_transport_state_t tstate;
18 gboolean playing;
19
20 tstate = jack_transport_query(client, &tpos);
21 playing = (tstate == JackTransportRolling || tstate == JackTransportLooping);
22 if (!playing) {
23 jack_transport_start(client);
24 pauseimage = gtk_image_new_from_stock(GTK_STOCK_MEDIA_PAUSE, GTK_ICON_SIZE_BUTTON);
25 gtk_button_set_image(GTK_BUTTON(button), pauseimage);
26 playing = TRUE;
27 } else {
28 jack_transport_stop(client);
29 playimage = gtk_image_new_from_stock(GTK_STOCK_MEDIA_PLAY, GTK_ICON_SIZE_BUTTON);
30 gtk_button_set_image(GTK_BUTTON(button), playimage);
31 playing = FALSE;
32 }
33 }
34
35 /* rewind to the beginning (frame 0) */
36 void on_rewind (GtkButton* button, gpointer app_data) {
37 jack_client_t* client = (jack_client_t*)app_data;
38
39 jack_transport_locate(client, 0); /* go to frame 0 */
40 button = NULL;
41 }
42
43 /* step backward, if the stepr button is still pressed */
44 gboolean step_backward (gpointer app_data) {
45 jack_client_t* client = (jack_client_t*)app_data;
46 jack_position_t pos;
47 float rate, loc;
48 static float step = 1.0; /* step for frame forward */
49
50 if (!stepr_released) {
51 jack_transport_query(client, &pos);
52 rate = (float)pos.frame_rate;
53 /* loc = (((float)pos.frame / rate) - step) * rate; */
54 loc = (float)pos.frame - step;
55 if (loc < 0.0f) loc = 0.0f;
56 jack_transport_locate(client, (jack_nframes_t) loc);
57 if (step < 192000.0) /* lock speed */
58 step*=1.1;
59 return TRUE;
60 } else {
61 step = 1.0;
62 return FALSE; /* do not schedule anymore */
63 }
64 }
65
66 /* step forward, if the stepf button is still pressed */
67 gboolean step_forward (gpointer app_data) {
68 jack_client_t* client = (jack_client_t*)app_data;
69 jack_position_t pos;
70 float rate, loc;
71 static float step = 1.0; /* step for frame forward */
72
73 if (!stepf_released) {
74 jack_transport_query(client, &pos);
75 rate = (float)pos.frame_rate;
76 /* loc = (((float)pos.frame / rate) + step) * rate; */
77 loc = (float)pos.frame + step;
78 if (loc < 0.0f) loc = 0.0f;
79 jack_transport_locate(client, (jack_nframes_t) loc);
80 if (step < 192000.0) /* lock speed */
81 step*=1.1;
82 return TRUE;
83 } else {
84 step = 1.0;
85 return FALSE; /* do not schedule anymore */
86 }
87 }
88
89 /* begin continuous setp backward */
90 void on_stepr_pressed (GtkButton* button, gpointer app_data) {
91
92 stepr_released = FALSE;
93
94 g_timeout_add (20, step_backward, app_data); /* 20ms for reactivity */
95
96 button = NULL;
97 }
98
99 /* stop continuous step backward */
100 void on_stepr_released (GtkButton* button, gpointer app_data) {
101 stepr_released = TRUE;
102 button = NULL;
103 app_data = NULL;
104 }
105
106 /* begin continuous step forward */
107 void on_stepf_pressed (GtkButton* button, gpointer app_data) {
108
109 stepf_released = FALSE;
110
111 g_timeout_add (20, step_forward, app_data); /* 20ms for reactivity */
112
113 button = NULL;
114 }
115
116 /* stop the continuous step forward */
117 void on_stepf_released (GtkButton* button, gpointer app_data) {
118 stepf_released = TRUE;
119 button = NULL;
120 app_data = NULL;
121 }
122
123 /* refresh the timeline (one shot) (called every TIMERVALms by main) */
124 gboolean refresh_timeline (gpointer app_data) {
125 AppData* d = (AppData*) app_data;
126 jack_position_t pos;
127 gchar* time;
128
129 jack_transport_query(d->jackd_client, &pos);
130 time = format_time((float)pos.frame / (float)pos.frame_rate);
131 gtk_label_set_markup(GTK_LABEL(d->timeline), time);
132
133 return TRUE;
134 }
135

  ViewVC Help
Powered by ViewVC 1.1.26