/usr/share/perl5/Audio/Nama/Initialize_subs.pm is in nama 1.078-1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
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 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 | # ----------- Initialize --------
package Audio::Nama;
use Modern::Perl; use Carp;
our (
$ui,
%opts,
%jack,
$jack_running,
$midish_enable,
$project_name,
$debug,
$debug2,
$banner,
$project_root,
$ladspa_sample_rate,
%devices,
$fake_jack_lsp,
$use_jack_plumbing,
@ecasound_pids,
$e,
$user_customization_file,
$sock,
$ecasound_tcp_port,
$hires,
$waveform_viewer,
);
sub initialize_interfaces {
$debug2 and print "&prepare\n";
say $banner;
if ($opts{D}){
$debug = 1;
$debug2 = 1;
}
if ( ! $opts{t} and Audio::Nama::Graphical::initialize_tk() ){
$ui = Audio::Nama::Graphical->new();
} else {
say "Unable to load perl Tk module. Starting in console mode." if $opts{g};
$ui = Audio::Nama::Text->new();
can_load( modules =>{ Event => undef})
or die "Perl Module 'Event' not found. Please install it and try again. Stopping.";
;
import Event qw(loop unloop unloop_all);
}
can_load( modules => {AnyEvent => undef})
or die "Perl Module 'AnyEvent' not found. Please install it and try again. Stopping.";
choose_sleep_routine();
$project_name = shift @ARGV;
$debug and print "project name: $project_name\n";
$debug and print("\%opts\n======\n", yaml_out(\%opts)); ;
read_config(global_config()); # from .namarc if we have one
setup_user_customization();
start_ecasound();
$debug and print "reading config file\n";
if ($opts{d}){
print "project_root $opts{d} specified on command line\n";
$project_root = $opts{d};
}
if ($opts{p}){
$project_root = getcwd();
print "placing all files in current working directory ($project_root)\n";
}
# capture the sample frequency from .namarc
($ladspa_sample_rate) = $devices{jack}{signal_format} =~ /(\d+)(,i)?$/;
# skip initializations if user (test) supplies project
# directory
first_run() unless $opts{d};
prepare_static_effects_data() unless $opts{S};
get_ecasound_iam_keywords();
load_keywords(); # for autocompletion
chdir $project_root # for filename autocompletion
or warn "$project_root: chdir failed: $!\n";
$ui->init_gui;
$ui->transport_gui;
$ui->time_gui;
# fake JACK for testing environment
if( $opts{J}){
%jack = %{ jack_ports($fake_jack_lsp) };
$jack_running = 1;
}
# periodically check if JACK is running, and get client/port list
poll_jack() unless $opts{J} or $opts{A};
sleeper(0.2); # allow time for first polling
# we will start jack.plumbing only when we need it
if( $use_jack_plumbing
and $jack_running
and process_is_running('jack.plumbing')
){
say "\nJack.plumbing daemon detected!";
print "\nAttempting to stop it (will restart as needed)... ";
kill_jack_plumbing();
sleeper(0.2);
if( process_is_running('jack.plumbing') )
{
say qq(\n\nUnable to stop jack.plumbing daemon.
Please do one of the following, then restart Nama:
- kill the jack.plumbing daemon ("killall jack.plumbing")
- set "use_jack_plumbing: 0" in .namarc
Exiting.);
exit;
}
else { say "Stopped." }
}
start_midish() if $midish_enable;
# set up autosave
schedule_autosave() unless debugging_options();
initialize_terminal() unless $opts{T};
# set default project to "untitled"
if (! $project_name ){
$project_name = "untitled";
$opts{c}++;
}
print "\nproject_name: $project_name\n";
load_project( name => $project_name, create => $opts{c}) ;
restore_effect_chains();
restore_effect_profiles();
1;
}
sub debugging_options {
grep{$_} $debug, @opts{qw(R D J A E T)};
}
sub start_ecasound {
my @existing_pids = split " ", qx(pgrep ecasound);
select_ecasound_interface();
sleeper(0.2);
@ecasound_pids = grep{ my $pid = $_;
! grep{ $pid == $_ } @existing_pids
} split " ", qx(pgrep ecasound);
}
sub select_ecasound_interface {
return if $opts{E} or $opts{A};
if ( can_load( modules => { 'Audio::Ecasound' => undef } )
and ! $opts{n} ){
say "\nUsing Ecasound via Audio::Ecasound (libecasoundc).";
{ no warnings qw(redefine);
*eval_iam = \&eval_iam_libecasoundc; }
$e = Audio::Ecasound->new();
} else {
no warnings qw(redefine);
launch_ecasound_server($ecasound_tcp_port);
init_ecasound_socket($ecasound_tcp_port);
*eval_iam = \&eval_iam_neteci;
}
}
sub choose_sleep_routine {
if ( can_load(modules => {'Time::HiRes'=> undef} ) )
{ *sleeper = *finesleep;
$hires++; }
else { *sleeper = *select_sleep }
}
sub finesleep {
my $sec = shift;
Time::HiRes::usleep($sec * 1e6);
}
sub select_sleep {
my $seconds = shift;
select( undef, undef, undef, $seconds );
}
sub toggle_transport {
if (engine_running()){ stop_transport() }
else { start_transport() }
}
{
my $default_port = 2868; # Ecasound's default
sub launch_ecasound_server {
# we'll try to communicate with an existing ecasound
# process provided:
#
# started with --server option
# --server-tcp-port option matches --or--
# nama is using Ecasound's default port 2868
my $port = shift // $default_port;
my $command = "ecasound -K -C --server --server-tcp-port=$port";
my $redirect = ">/dev/null &";
my $ps = qx(ps ax);
say("Using existing Ecasound server"), return
if $ps =~ /ecasound/
and $ps =~ /--server/
and ($ps =~ /tcp-port=$port/ or $port == $default_port);
say "Starting Ecasound server";
system("$command $redirect") == 0 or carp "system $command failed: $?\n";
sleep 1;
}
sub init_ecasound_socket {
my $port = shift // $default_port;
say "Creating socket on port $port.";
$sock = new IO::Socket::INET (
PeerAddr => 'localhost',
PeerPort => $port,
Proto => 'tcp',
);
die "Could not create socket: $!\n" unless $sock;
}
sub ecasound_pid {
my ($ps) = grep{ /ecasound/ and /server/ } qx(ps ax);
my ($pid) = split " ", $ps;
$pid if $sock; # conditional on using socket i.e. Net-ECI
}
sub eval_iam { } # stub
sub eval_iam_neteci {
my $cmd = shift;
$cmd =~ s/\s*$//s; # remove trailing white space
$sock->send("$cmd\r\n");
my $buf;
$sock->recv($buf, 65536);
my ($return_value, $length, $type, $reply) =
$buf =~ /(\d+)# digits
\ # space
(\d+)# digits
\ # space
([^\r\n]+) # a line of text, probably one character
\r\n # newline
(.+) # rest of string
/sx; # s-flag: . matches newline
if( ! $return_value == 256 ){
my $debug++;
$debug and say "ECI command: $cmd";
$debug and say "Ecasound reply (256 bytes): ", substr($buf,0,256);
$debug and say qq(
length: $length
type: $type
full return value: $return_value);
die "illegal return value, stopped" ;
}
$reply =~ s/\s+$//;
given($type){
when ('e'){ carp $reply }
default{ return $reply }
}
}
}
sub eval_iam_libecasoundc{
#$debug2 and print "&eval_iam\n";
my $command = shift;
$debug and print "iam command: $command\n";
my (@result) = $e->eci($command);
$debug and print "result: @result\n" unless $command =~ /register/;
my $errmsg = $e->errmsg();
if( $errmsg ){
$e->errmsg('');
# ecasound already prints error on STDOUT
# carp "ecasound reports an error:\n$errmsg\n";
}
"@result";
}
1;
__END__
|