FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
keytarboard/jackEngine.cpp at master · noedigcode/keytarboard · GitHub
noedigcode
/
keytarboard
Public
Notifications
You must be signed in to change notification settings
Fork
0
Star
1
Code
Issues
0
Pull requests
0
Actions
Projects
Security and quality
0
Insights
Additional navigation options
Code
Issues
Pull requests
Actions
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
keytarboard
/
jackEngine.cpp
Copy path
More file actions
More file actions
Latest commit
History
History
History
177 lines (138 loc) · 4.98 KB
Breadcrumbs
keytarboard
/
jackEngine.cpp
Copy path
File metadata and controls
177 lines (138 loc) · 4.98 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
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
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
#
include
"
jackEngine.h
"
#
include
<
stdio.h
>
#
include
<
iostream
>
bool
jack_process_busy =
false
;
int
jack_process_disable =
0
;
//
Non-zero value = disabled
// ============================================================================
//
gidJackClient class
// ============================================================================
jackEngine::jackEngine
(QObject *parent) :
QObject(parent)
{
this
->
clientActive
=
false
;
buffer =
midiBuffer
();
}
void
jackEngine::jackPortConnectCallback
(
jack_port_id_t
a,
jack_port_id_t
b,
int
connect,
void
* arg)
{
}
void
jackEngine::jackPortRegistrationCallback
(
jack_port_id_t
port,
int
registered,
void
*arg)
{
}
int
jackEngine::jackProcessCallback
(
jack_nframes_t
nframes,
void
*arg)
{
jack_process_busy =
true
;
if
(jack_process_disable) {
jack_process_busy =
false
;
return
0
;
}
//
--------------------------------
jackEngine* e = (jackEngine*)arg;
void
* portBuffer =
jack_port_get_buffer
( e->
midi_output_port
, nframes );
jack_midi_clear_buffer
(portBuffer);
//
for each event in our buffer...
for
(
int
size=e->
buffer
.
canRead
(); size>
0
; size=e->
buffer
.
canRead
()) {
//
Get Jack output buffer
jack_midi_data_t
* out_buffer =
jack_midi_event_reserve
( portBuffer,
0
, size);
//
Copy buffer data to output buffer
e->
buffer
.
read
(out_buffer);
}
//
--------------------------------
jack_process_busy =
false
;
return
0
;
}
void
jackEngine::startJackTransport
()
{
jack_transport_start
(client);
}
void
jackEngine::stopJackTransport
()
{
jack_transport_stop
(client);
}
bool
jackEngine::isTransportStopped
()
{
return
jack_transport_query
(client,
NULL
) == JackTransportStopped;
}
bool
jackEngine::clientIsActive
()
{
return
this
->
clientActive
;
}
QString
jackEngine::clientName
()
{
return
ourJackClientName;
}
/*
Pauses (pause=true) or unpauses (pause=false) the Jack process callback function.
* When pause=true, the Jack process callback is disabled and this function blocks
* until the current execution of the process callback (if any) competes, before
* returning, thus ensuring that the process callback will not execute until this
* function is called again with pause=false.
*/
void
jackEngine::pauseJackProcessing
(
bool
pause)
{
/*
When jack_process_disable is non-zero, Jack process is disabled. Here it is
* incremented or decremented, accounting for the fact that this function might
* be called multiple times within nested functions. Only once all of the callers
* have also called this function with pause=false, will it reach zero, enabling
* the Jack process callback again.
*/
if
(pause) {
jack_process_disable++;
while
(jack_process_busy) {}
}
else
{
if
(jack_process_disable) {
jack_process_disable--;
}
}
}
bool
jackEngine::InitJackClient
(QString name)
{
//
Try to become a client of the jack server
if
( (client =
jack_client_open
(name.
toLocal8Bit
(), JackNullOption,
NULL
)) ==
NULL
) {
userMessage
(
"
JACK: Error becoming client.
"
);
this
->
clientActive
=
false
;
return
false
;
}
else
{
ourJackClientName =
jack_get_client_name
(client);
//
jack_client_open modifies the given name if another client already uses it.
userMessage
(
"
JACK: Client created:
"
+ ourJackClientName);
this
->
clientActive
=
true
;
}
//
Set up midi input port
//
setOurMidiInputPortName( ourJackClientName + ":" +
//
QString::fromLocal8Bit(GID_JACK_MIDI_IN_PORT_NAME));
//
Set up callback functions
jack_set_port_connect_callback
(client, jackEngine::jackPortConnectCallback,
this
);
jack_set_port_registration_callback
(client, jackEngine::jackPortRegistrationCallback,
this
);
jack_set_process_callback
(client, jackEngine::jackProcessCallback,
this
);
//
Set up output midi port
midi_output_port =
jack_port_register
( client,
JACKENGINE_MIDI_OUT_PORT_NAME
,
JACK_DEFAULT_MIDI_TYPE
,
JackPortIsOutput,
0
);
nframes =
jack_get_buffer_size
(client);
//
Activate the client
if
(
jack_activate
(client)) {
userMessage
(
"
JACK: Cannot activate client.
"
);
jack_free
(client);
this
->
clientActive
=
false
;
return
false
;
}
else
{
userMessage
(
"
JACK: Activated client.
"
);
this
->
clientActive
=
true
;
}
return
true
;
}
void
jackEngine::stopJackClient
()
{
if
(
clientIsActive
()) {
jack_client_close
(client);
this
->
clientActive
=
false
;
}
}
//
Works exactly the same as the midiBuffer write function.
int
jackEngine::addMidiEventToBuffer
(
unsigned
char
*data,
int
size)
{
return
buffer.
write
(data, size);
}
//
Print error message to stdout, and abort app.
void
jackEngine::error_abort
(QString msg)
{
std::cout <<
"
\n
"
<<
"
Konfyt ERROR, ABORTING: gidJackClient:
"
<< msg.
toLocal8Bit
().
constData
();
abort
();
}
Back
|
FazBrowse Home
|
New Git URL