/[cabestan]/callbacks.c
ViewVC logotype

Diff of /callbacks.c

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 6 by ben, Mon Oct 5 01:58:05 2009 UTC revision 7 by ben, Mon Oct 5 19:15:42 2009 UTC
# Line 1  Line 1 
1    #include <glib.h>
2  #include <gtk/gtk.h>  #include <gtk/gtk.h>
3  #include <jack/jack.h>  #include <jack/jack.h>
4  #include <jack/transport.h>  #include <jack/transport.h>
5  #include "cabestan.h"  #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) {  void on_play (GtkButton* button, gpointer app_data) {
16          jack_client_t* client = (jack_client_t*)app_data;          jack_client_t* client = (jack_client_t*)app_data;
17          GtkWidget* pauseimage = NULL;          GtkWidget* pauseimage = NULL;
# Line 26  void on_play (GtkButton* button, gpointe Line 35  void on_play (GtkButton* button, gpointe
35          }                }      
36  }  }
37    
38    /* rewind to the beginning (frame 0) */
39  void on_rewind (GtkButton* button, gpointer app_data) {  void on_rewind (GtkButton* button, gpointer app_data) {
40          jack_client_t* client = (jack_client_t*)app_data;          jack_client_t* client = (jack_client_t*)app_data;
41    
# Line 33  void on_rewind (GtkButton* button, gpoin Line 43  void on_rewind (GtkButton* button, gpoin
43          button = NULL;          button = NULL;
44  }  }
45    
46  void on_stepf (GtkButton* button, gpointer app_data) {  /* 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;          jack_client_t* client = (jack_client_t*)app_data;
49          jack_position_t pos;          jack_position_t pos;
50          float rate, loc;          float rate, loc;
51            static float step = 1.0; /* step for frame forward */
52    
53          jack_transport_query(client, &pos);          if (!stepr_released) {
54          rate = (float)pos.frame_rate;                  jack_transport_query(client, &pos);
55          loc = (((float)pos.frame / rate) + 0.001) * rate; /* one ms step */                  rate = (float)pos.frame_rate;
56          if (loc < 0.0f) loc = 0.0f;  /*              loc = (((float)pos.frame / rate) - step) * rate; */
57          jack_transport_locate(client, (jack_nframes_t) loc);                  loc = (float)pos.frame - step;
58          button = NULL;                  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  void on_stepr (GtkButton* button, gpointer app_data) {  /* 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;          jack_client_t* client = (jack_client_t*)app_data;
72          jack_position_t pos;          jack_position_t pos;
73          float rate, loc;          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          jack_transport_query(client, &pos);  /* stop the continuous step forward */
126          rate = (float)pos.frame_rate;  void on_stepf_released (GtkButton* button, gpointer app_data) {
127          loc = (((float)pos.frame / rate) - 0.001) * rate; /* one ms step */          g_static_mutex_lock(&stepf);
128          if (loc < 0.0f) loc = 0.0f;          stepf_released = TRUE;
129          jack_transport_locate(client, (jack_nframes_t) loc);          g_static_mutex_unlock(&stepf);
130          button = NULL;          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) {  gboolean refresh_timeline (gpointer app_data) {
136          AppData* d = (AppData*) app_data;          AppData* d = (AppData*) app_data;
137          jack_position_t pos;          jack_position_t pos;

Legend:
Removed from v.6  
changed lines
  Added in v.7

  ViewVC Help
Powered by ViewVC 1.1.26