2 orgux - a just-for-fun real time synth
3 Copyright (C) 2009 Evan Rinehart
5 This program is free software; you can redistribute it and/or
6 modify it under the terms of the GNU General Public License
7 as published by the Free Software Foundation; either version 2
8 of the License, or (at your option) any later version.
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with this program; if not, write to the Free Software
17 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
20 /* jack test of synth */
28 #include <jack/jack.h>
29 #include <jack/midiport.h>
30 jack_port_t
*input_port
;
31 jack_port_t
*output_port_1
;
32 jack_port_t
*output_port_2
;
36 int process (jack_nframes_t nframes
, void *arg
) {
38 void* port_buf
= jack_port_get_buffer(input_port
, nframes
);
40 jack_default_audio_sample_t
*out1
= (jack_default_audio_sample_t
*)
41 jack_port_get_buffer(output_port_1
, nframes
);
43 jack_default_audio_sample_t
*out2
= (jack_default_audio_sample_t
*)
44 jack_port_get_buffer(output_port_2
, nframes
);
46 jack_midi_event_t in_event
;
47 jack_nframes_t event_count
= jack_midi_get_event_count(port_buf
);
49 unsigned char midi
[3];
50 for(int i
=0; i
< event_count
; i
++){
52 jack_midi_event_get(&in_event
, port_buf
, i
);
53 midi
[0] = in_event
.buffer
[0];
54 midi
[1] = in_event
.buffer
[1];
55 midi
[2] = in_event
.buffer
[2];
57 orgux_schedule(S
, in_event
.time
, midi
);
61 orgux_process(S
, out1
, out2
, nframes
);
67 srate (jack_nframes_t nframes
, void *arg
)
70 printf ("the sample rate is now %lu/sec\n", nframes
);
76 jack_shutdown (void *arg
)
78 printf("jack shutdown\n");
83 error (const char *desc
)
85 fprintf (stderr
, "JACK error: %s\n", desc
);
94 jack_client_t
*client
;
96 jack_set_error_function (error
);
98 if ((client
= jack_client_new ("orgux")) == 0) {
99 fprintf (stderr
, "jack server not running?\n");
103 S
= orgux_init(jack_get_sample_rate(client
));
105 jack_set_process_callback (client
, process
, 0);
106 jack_set_sample_rate_callback (client
, srate
, 0);
107 jack_on_shutdown (client
, jack_shutdown
, 0);
109 input_port
= jack_port_register(client
, "midi-in",
110 JACK_DEFAULT_MIDI_TYPE
, JackPortIsInput
, 0);
111 output_port_1
= jack_port_register (client
, "out-1",
112 JACK_DEFAULT_AUDIO_TYPE
, JackPortIsOutput
, 0);
113 output_port_2
= jack_port_register (client
, "out-2",
114 JACK_DEFAULT_AUDIO_TYPE
, JackPortIsOutput
, 0);
116 if (jack_activate (client
)) {
117 fprintf (stderr
, "cannot activate client");
127 jack_client_close (client
);