Repository navigation
Expand file tree
/
Copy pathjackmidiout.cpp
More file actions
executable file
·95 lines (71 loc) · 2.11 KB
/
Copy pathjackmidiout.cpp
File metadata and controls
executable file
·95 lines (71 loc) · 2.11 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
#include "jackmidiout.hpp"
int JackMidiOut::i;
jack_client_t* JackMidiOut::client;
jack_port_t * JackMidiOut::inputPort;
jack_port_t * JackMidiOut::outputPort;
JackMidiOut::JackMidiOut()
{
i = 0;
std::cout << "JackMidiOut()" << std::flush;
if ((client = jack_client_open("AutoMate", JackNullOption, NULL)) == 0)
{
std::cout << "jack server not running?" << std::endl;
}
inputPort = jack_port_register (client, "midi_in", JACK_DEFAULT_MIDI_TYPE, JackPortIsInput, 0);
outputPort = jack_port_register (client, "midi_out",JACK_DEFAULT_MIDI_TYPE, JackPortIsOutput, 0);
jack_set_process_callback (client, process, 0);
std::cout << "\t\t\tDone!" << std::endl;
}
JackMidiOut::~JackMidiOut()
{
std::cout << "~JackMidiOut()" << std::endl;
}
void JackMidiOut::activate()
{
std::cout << "activate()" << std::endl;
if (jack_activate(client))
{
std::cout<< "cannot activate client" << std::endl;
}
}
int JackMidiOut::process(jack_nframes_t nframes, void *arg)
{
jack_midi_event_t in_event;
jack_nframes_t event_index = 0;
void* port_buf = jack_port_get_buffer( inputPort, nframes);
// input: get number of events, and process them.
jack_nframes_t event_count = jack_midi_get_event_count(port_buf);
if(event_count > 1)
{
std::cout << "midisine: have " << event_count << " events" << std::endl;
for(i=0; i<event_count; i++)
{
jack_midi_event_get(&in_event, port_buf, i);
std::cout << "event" << i << "time is " << in_event.time << ". 1st byte is " << *(in_event.buffer) << "." << std::endl;
}
}
// output:
void* out_port_buf = jack_port_get_buffer( outputPort, nframes);
unsigned char* buffer;
jack_midi_clear_buffer(out_port_buf);
if(i > 1000)
{
buffer = jack_midi_event_reserve(out_port_buf, 0, 3);
// write note on
buffer[0] = 144; // note on
buffer[1] = 60; // which note
buffer[2] = 127; // velocity
i = 0;
}
if (i > 240)
{
buffer = jack_midi_event_reserve(out_port_buf, 0, 3);
// write note off
buffer[0] = 128; // note off
buffer[1] = 60; // which note
buffer[2] = 127; // velocity
}
// std::cout << "Test" << i << std::endl;
i++;
return 0;
}