/
Jack.pm
165 lines (148 loc) · 5.48 KB
/
Jack.pm
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
#!/usr/bin/perl
package Jack;
use strict;
use warnings;
sub Start {
my $project = shift;
$project->Start_Jack_Server;
$project->Start_Jack_OSC;
}
sub Stop {
my $project = shift;
$project->Stop_Jack_Server;
$project->Stop_Jack_OSC;
}
sub Start_Jack_Server {
my $project = shift;
# JACK server
#---------------------------------
my $pid_jackd = qx(pgrep jackd);
if (!$pid_jackd) {
print "Strange ...JACK server is not running ?? Starting it\n";
my $command = "$project->{jack}{start} 2>&1 &";
system ($command) if $command;
sleep 1;
$pid_jackd = qx(pgrep jackd);
}
else {
print "JACK server running with PID $pid_jackd";
#verify jack parameters
my $params = qx(ps $pid_jackd);
die "JACK server doesn't have project parameters, please check.\nExpected : $project->{jack}{start}\nFound :\n$params"
unless $params =~ $project->{jack}{start};
print "JACK server parameters ok\n";
}
$project->{JACK}{PID} = $pid_jackd;
}
sub Start_Jack_OSC {
my $project = shift;
# JACK OSC
#---------------------------------
my $pid_jackosc;
my $port_jackosc;
my @lines = qx(pgrep -a jack-osc);
if ($project->{'jack-osc'}{enable}) {
if ($#lines > 0) {
die "Error: multiple jack-osc instances found\n";
}
elsif ($#lines == -1) {
print "jack-osc server is not running, starting it on oscport $project->{'jack-osc'}{osc_port}\n";
my $command = "jack-osc -p $project->{'jack-osc'}{osc_port} >/dev/null 2>&1 &";
system ($command);
sleep 1;
$pid_jackosc = qx(pgrep jack-osc);
chomp $pid_jackosc;
die "Jack error: could not start jack-osc\n" unless $pid_jackosc;
}
elsif ($#lines == 0) {
if ( $lines[0] =~ /(\d+?) jack-osc -p (\d+?)$/ ) {
$pid_jackosc = $1;
$port_jackosc = $2;
die "jack-osc is not running on the expected oscport : $lines[0]\n" unless $port_jackosc eq $project->{'jack-osc'}{osc_port};
}
else {
die "jack-osc doesn\'t have expected parameters : $lines[0]\n";
}
}
print "jack-osc server running with PID $pid_jackosc on oscport $project->{'jack-osc'}{osc_port}\n";
$project->{'jack-osc'}{PID} = $pid_jackosc;
}
}
sub Stop_Jack_OSC {
my $project = shift;
return unless $project->{'jack-osc'}{enable};
# by PID
if (defined $project->{'jack-osc'}{PID}) {
print "Stopping jack-osc with PID $project->{'jack-osc'}{PID}\n";
kill 'KILL',$project->{'jack-osc'}{PID};
}
# or brute
else {
print "Force killall jack-osc\n";
my $blob = `killall jack-osc`;
}
}
sub Start_a2jmidid {
my $project = shift;
return unless $project->{a2jmidid}{enable};
#a2jmidid
#---------------------------------
if ($project->{a2jmidid}{enable}) {
my $pid_a2jmidid = qx(pgrep -f a2jmidid);
if (!$pid_a2jmidid) {
system('a2jmidid -e > /dev/null 2>&1 &');
sleep 1;
$pid_a2jmidid = qx(pgrep -f a2jmidid);
die "Jack error: could not start a2jmidid\n" unless $pid_a2jmidid;
}
print "a2jmidid running with PID $pid_a2jmidid";
$project->{a2jmidid}{PID} = $pid_a2jmidid;
}
}
sub Stop_a2jmidid {
my $project = shift;
return unless $project->{a2jmidid}{enable};
# by PID
if (defined $project->{a2jmidid}{PID}) {
print "Stopping a2jmidid with PID $project->{a2jmidid}{PID}\n";
kill 'KILL',$project->{a2jmidid}{PID};
}
# or brute
else {
print "Force killall a2jmidid\n";
my $blob = `killall a2jmidid`;
}
}
sub get_jack_hardware_io_list {
my $hardware_io_list;
my @buffer = `jack_lsp -pt`;
while (my $line = shift @buffer) {
chomp $line;
my $properties = shift @buffer;
my $type = shift @buffer;
push @{$hardware_io_list->{hardware_audio_inputs}} , $line if ($properties =~ /output/) and ($properties =~ /physical/) and ($type =~ /audio/);
push @{$hardware_io_list->{hardware_audio_outputs}} , $line if ($properties =~ /input/) and ($properties =~ /physical/) and ($type =~ /audio/);
push @{$hardware_io_list->{hardware_midi_inputs}} , $line if ($properties =~ /output/) and ($properties =~ /physical/) and ($type =~ /midi/);
push @{$hardware_io_list->{hardware_midi_outputs}} , $line if ($properties =~ /input/) and ($properties =~ /physical/) and ($type =~ /midi/);
}
return $hardware_io_list;
}
sub get_jack_io_list_by_type {
my $io_list;
my @buffer = `jack_lsp -pt`;
while (my $line = shift @buffer) {
chomp $line;
my $properties = shift @buffer;
my $type = shift @buffer;
push @{$io_list->{hardware_audio_inputs}} , $line if ($properties =~ /output/) and ($properties =~ /physical/) and ($type =~ /audio/);
push @{$io_list->{hardware_audio_outputs}} , $line if ($properties =~ /input/) and ($properties =~ /physical/) and ($type =~ /audio/);
push @{$io_list->{hardware_midi_inputs}} , $line if ($properties =~ /output/) and ($properties =~ /physical/) and ($type =~ /midi/);
push @{$io_list->{hardware_midi_outputs}} , $line if ($properties =~ /input/) and ($properties =~ /physical/) and ($type =~ /midi/);
push @{$io_list->{software_audio_inputs}} , $line if ($properties =~ /input/) and ($properties !~ /physical/) and ($type =~ /audio/);
push @{$io_list->{software_audio_outputs}} , $line if ($properties =~ /output/) and ($properties !~ /physical/) and ($type =~ /audio/);
push @{$io_list->{software_midi_inputs}} , $line if ($properties =~ /input/) and ($properties !~ /physical/) and ($type =~ /midi/);
push @{$io_list->{software_midi_outputs}} , $line if ($properties =~ /output/) and ($properties !~ /physical/) and ($type =~ /midi/);
}
return $io_list;
}
1;