/[paths]/src/paths.c
ViewVC logotype

Contents of /src/paths.c

Parent Directory Parent Directory | Revision Log Revision Log


Revision 77 - (show annotations)
Fri Aug 31 04:11:58 2012 UTC (6 years, 10 months ago) by ben
File MIME type: text/plain
File size: 3304 byte(s)
fix layout, fix lol routes
1 #include <stdlib.h>
2 #include <string.h>
3 #include <gtk/gtk.h>
4 #include <jack/jack.h>
5 #include "main.h"
6 #include "graph.h"
7 #include "route.h"
8 #include "egg_view.h"
9
10 void on_stop_clicked(GtkButton *button, gpointer user_data)
11 {
12 struct app *app = user_data;
13 GtkToggleToolButton *play;
14
15 jack_client_t* client = app->jack->client;
16
17 /* use play button functionnality for stopping */
18 play = GTK_TOGGLE_TOOL_BUTTON(gtk_builder_get_object (app->ui, "play"));
19 gtk_toggle_tool_button_set_active (play, FALSE);
20
21 jack_transport_locate(client, 0); /* go to frame 0 */
22 }
23
24 void on_play_toggled(GtkToggleToolButton *togglebutton, gpointer user_data)
25 {
26 struct app *app = user_data;
27 jack_client_t* client = app->jack->client;
28 jack_position_t tpos;
29 jack_transport_state_t tstate;
30 gboolean playing;
31
32 tstate = jack_transport_query(client, &tpos);
33 playing = (tstate == JackTransportRolling || tstate == JackTransportLooping);
34 if (!playing) {
35 jack_transport_start(client);
36 } else {
37 jack_transport_stop(client);
38 }
39 /* playing is out of date, use opposite */
40 gtk_toggle_tool_button_set_active(togglebutton, !playing);
41 }
42
43 void on_new_activate(GtkMenuItem *menuitem, gpointer user_data)
44 {
45 struct app *app = user_data;
46 GtkNotebook *notebook = GTK_NOTEBOOK(gtk_builder_get_object(app->ui, "notebook"));
47 GtkWidget *scrolled = gtk_scrolled_window_new(NULL, NULL);
48 GtkWidget *view = egg_view_new();
49 char name[32];
50 int i;
51
52 struct instrument *inst = malloc(sizeof (*inst));
53 memset(inst, 0, sizeof(*inst));
54 struct voice *voice1 = malloc(sizeof (*voice1));
55 memset(voice1, 0, sizeof(*voice1));
56 struct voice *voice2 = malloc(sizeof (*voice2));
57 memset(voice2, 0, sizeof(*voice2));
58
59 /* FIXME: deep free these on bookmark close */
60 inst->voices[0] = voice1;
61 inst->voices[1] = voice2;
62 inst->count = 2;
63
64 /* jack stuff */
65 snprintf(name, 32, "out %d", app->count);
66 inst->out = jack_port_register(app->jack->client, name, JACK_DEFAULT_MIDI_TYPE, JackPortIsOutput, 0);
67 if (inst->out == NULL) {
68 error("could not register a jack midi out port");
69 exit(EXIT_FAILURE);
70 }
71
72 /* backend stuff */
73 inst->graph = graph_new(10);
74 graph_randomize2(inst->graph, 3);
75
76 /* voices */
77 voice1->route = route_new_random(inst->graph, 50);
78 voice1->count = 50;
79
80 voice2->route = route_new_random(inst->graph, 50);
81 voice2->count = 50;
82
83 /* context */
84 app->instruments[app->count] = inst;
85 app->count++;
86
87 /* graphical stuff */
88 inst->graph->egg = view;
89 egg_view_bind(view, inst->graph);
90 gtk_container_add(GTK_CONTAINER(scrolled), GTK_WIDGET(view));
91 gtk_notebook_append_page(notebook, scrolled, NULL);
92 gtk_widget_show_all(scrolled);
93 }
94
95 void on_open_activate(GtkMenuItem *menuitem, gpointer user_data)
96 {
97 struct app *app = user_data;
98 }
99
100 void on_save_activate(GtkMenuItem *menuitem, gpointer user_data)
101 {
102 struct app *app = user_data;
103 }
104 void on_save_as_activate(GtkMenuItem *menuitem, gpointer user_data)
105 {
106 struct app *app = user_data;
107 }
108
109 static void quit(struct app* app)
110 {
111 /* ensure to stop playing */
112 /* popup a save dialog if needed */
113
114 /* else quit graphical event loop */
115 gtk_main_quit();
116 }
117
118 void on_quit_activate(GtkMenuItem *menuitem, gpointer user_data)
119 {
120 struct app *app = user_data;
121 quit(app);
122 }
123
124 void on_window_destroy(GtkWidget *window, gpointer user_data)
125 {
126 struct app *app = user_data;
127 quit(app);
128 }

  ViewVC Help
Powered by ViewVC 1.1.26