/[cabestan]/callbacks.c
ViewVC logotype

Contents of /callbacks.c

Parent Directory Parent Directory | Revision Log Revision Log


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

  ViewVC Help
Powered by ViewVC 1.1.26