-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathjack.cpp
More file actions
executable file
·124 lines (95 loc) · 3.27 KB
/
jack.cpp
File metadata and controls
executable file
·124 lines (95 loc) · 3.27 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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
/* Program AutoMate: A musical automation tool
Author: Harry van Haaren
E-mail: harryhaaren@gmail.com
Copyright (C) 2010 Harry van Haaren
AutoMate is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
AutoMate is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with AutoMate. If not, see <http://www.gnu.org/licenses/>. */
#include "jack.hpp"
Jack::Jack()
{
bpm = 120.0;
std::cout << "Creating Jack Client..." << std::flush;
if ((client = jack_client_open("AutoMate", JackNullOption, NULL)) == 0)
{
std::cout << "\nError: could not create client.\tJACK 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, staticProcess, static_cast<void*>(this));
std::cout << "\t\t\tDone!" << std::endl;
}
Jack::~Jack()
{
}
void Jack::setTrackVector(AutomationTrack* array)
{
// keep a copy of array's address
arrayPointer = array;
}
void Jack::activate()
{
std::cout << "Activating JACK client..." << std::flush;
if (jack_activate(client))
{
std::cout << "Cannot activate client" << std::endl;
exit(1);
}
std::cout << "\t\tDone!" << std::endl;
}
int Jack::staticProcess(jack_nframes_t nframes, void *arg)
{
return static_cast<Jack*>(arg)->process(nframes);
}
int Jack::process(jack_nframes_t nframes)
{
jack_position_t positionQuery;
jack_transport_state_t transportQuery;
// get output port buffers
void* out_port_buf = jack_port_get_buffer( outputPort, nframes);
unsigned char* buffer;
jack_midi_clear_buffer(out_port_buf);
transportQuery = jack_transport_query ( client, &positionQuery );
jack_nframes_t frame = jack_get_sample_rate ( client );
/*
// if transport rolling
if( (transportQuery & JackTransportRolling) && (positionQuery.valid & JackPositionBBT) && (positionQuery.tick == 0) )
{
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
*
}
*/
// update the widget regardless of if its active or not
if(transportQuery & JackTransportRolling)
for (int i = 0; i < 4; i++)
arrayPointer[i].setTime( transportQuery, positionQuery );
if(transportQuery & JackTransportRolling && (positionQuery.valid & JackPositionBBT) && (positionQuery.tick % 100 == 0))
{
// For testing only one track, insert 1 instead of 4
for (int i = 0; i < 4; i++)
{
// check if the thing is "enabled" or "active"
if( arrayPointer[i].getActive() )
{
buffer = jack_midi_event_reserve(out_port_buf, 0, 3);
// write CC change
buffer[0] = 144 + arrayPointer[i].getChannel();
buffer[1] = arrayPointer[i].getCC();
buffer[2] = arrayPointer[i].getValue() * 127;
}
}
}
return 0;
}