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

Contents of /src/main.c

Parent Directory Parent Directory | Revision Log Revision Log


Revision 17 - (show annotations)
Sat Aug 18 01:02:58 2012 UTC (7 years, 2 months ago) by ben
File MIME type: text/plain
File size: 2679 byte(s)
add dummy jack_shutdown handler
1 #include <stdio.h>
2 #include <stdlib.h>
3 #include <string.h>
4
5 #include <jack/jack.h>
6 #include <jack/midiport.h>
7
8 #include <config.h>
9 #include "graph.h"
10
11 #define MAX_PATHS 128
12
13 #define error(str) puts(str)
14
15 struct jack {
16 jack_port_t *output_ports[MAX_PATHS];
17 jack_client_t *client;
18 };
19
20 struct path {
21 struct node* route;
22 int count;
23 int cur;
24 };
25
26 struct context {
27 struct path paths[MAX_PATHS];
28 struct graph *graph;
29 struct jack *jack;
30 };
31
32 static int jack_process_callback(jack_nframes_t nframes, void *ctx)
33 {
34 struct context *context;
35 int i;
36
37 context = ctx;
38 i = context->paths[0].cur;
39
40 if (nframes <= 0)
41 return 0;
42
43 printf("%p\n", &context->paths[0].route[i]);
44
45 context->paths[0].cur = (i + 1) % context->paths[0].count;
46 return 0;
47 }
48
49 static int jack_sync_callback(jack_transport_state_t state, jack_position_t *position, void *ctx)
50 {
51 struct context *context;
52
53 context = ctx;
54
55 if (state == JackTransportStarting) {
56 /* seek in path (???) according to position->frame */
57 } else if (state == JackTransportStopped) {
58 /* pause */
59 }
60
61 return 1;
62 }
63
64 void jack_shutdown(void* context)
65 {
66 puts("jack vanished...");
67 }
68
69 int main (int argc, char *argv[])
70 {
71 struct context context;
72
73 struct path path;
74 struct graph *graph;
75
76 struct jack jack;
77
78 int err;
79
80 /* create random graph */
81 graph = graph_new(100);
82 graph_randomize2(graph, 3);
83
84 /* initialize context */
85 memset(&context, 0, sizeof(context));
86 context.graph = graph;
87 context.jack = &jack;
88
89 /* create a random route */
90 path.route = graph->nodes;
91 path.count = graph->count;
92 context.paths[0] = path;
93
94 /* init jack */
95 jack.client = jack_client_open(PACKAGE_NAME, JackNullOption, NULL);
96 if (jack.client == NULL) {
97 error("could not connect to jackd");
98 exit(EXIT_FAILURE);
99 }
100
101 err = jack_set_process_callback(jack.client, jack_process_callback, &context);
102
103 if (err) {
104 error("could not set jack process callback");
105 exit(EXIT_FAILURE);
106 }
107
108 err = jack_set_sync_callback(jack.client, jack_sync_callback, &context);
109
110 if (err) {
111 error("could not set jack sync callback");
112 exit(EXIT_FAILURE);
113 }
114
115 jack_on_shutdown(jack.client, jack_shutdown, &context);
116
117 /* allocate one jack port (midi out) */
118 jack.output_ports[0] = jack_port_register(jack.client, "out", JACK_DEFAULT_MIDI_TYPE, JackPortIsOutput, 0);
119
120 if (jack.output_ports[0] == NULL) {
121 error("could not register jack midi out port");
122 exit(EXIT_FAILURE);
123 }
124
125 /* activate jack */
126 if (jack_activate(jack.client)) {
127 error("could not activate jack client");
128 exit(EXIT_FAILURE);
129 }
130
131 /* start playing (event loop) */
132 sleep(10);
133
134 /* close jack */
135 jack_client_close (jack.client);
136
137 /* exit */
138 graph_destroy(graph);
139
140 exit(EXIT_SUCCESS);
141 }

  ViewVC Help
Powered by ViewVC 1.1.26