/usr/share/perl5/Audio/Nama/Config_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 | # ------ Config subroutines ------
package Audio::Nama;
use Modern::Perl;
no warnings 'uninitialized';
# global variables
our (
%opts, # command line options
$project_root, # directory
$project_name, # startup value
@config_vars, # vars to read from namarc
$sampling_frequency, # set from 'frequency' abbreviation in namarc
$default, # default namarc
$custom_pl, # user customizations
$debug,
$debug2,
);
# exclusive to this module
our (
%subst, # substitutions
);
## configuration file
sub global_config {
# return text of config file, in the following order
# or priority:
#
# 1. the file designated by the -f command line argument
# 2. .namarc in the current project directory, i.e. ~/nama/untitled/.namarc
# 3. .namarc in the home directory, i.e. ~/.namarc
# 4. .namarc in the project root directory, i.e. ~/nama/.namarc
if( $opts{f} ){
print("reading config file $opts{f}\n");
return read_file($opts{f});
}
my @search_path = (project_dir(), $ENV{HOME}, project_root() );
my $c = 0;
map{
if (-d $_) {
my $config = join_path($_, config_file());
if( -f $config or -l $config){
say "Found config file: $config";
my $yml = read_file($config);
return $yml;
}
}
} ( @search_path)
}
# sub global_config {
# read_file( join_path($ENV{HOME}, config_file()));
# }
sub read_config {
# read and process the configuration file
#
# use the embedded default file if none other is present
$debug2 and print "&read_config\n";
my $config = shift;
my $yml = length $config > 100 ? $config : $default;
strip_all( $yml );
my %cfg = %{ yaml_in($yml) };
*subst = \%{ $cfg{abbreviations} }; # alias
walk_tree(\%cfg);
walk_tree(\%cfg); # second pass completes substitutions
assign_var( \%cfg, @config_vars);
$project_root = $opts{d} if $opts{d};
$project_root = expand_tilde($project_root);
$sampling_frequency = $cfg{abbreviations}{frequency};
}
sub walk_tree {
#$debug2 and print "&walk_tree\n";
my $ref = shift;
map { substitute($ref, $_) }
grep {$_ ne q(abbreviations)}
keys %{ $ref };
}
sub substitute{
my ($parent, $key) = @_;
my $val = $parent->{$key};
#$debug and print qq(key: $key val: $val\n);
ref $val and walk_tree($val)
or map{$parent->{$key} =~ s/$_/$subst{$_}/} keys %subst;
}
sub first_run {
return if $opts{f};
my $config = config_file();
$config = "$ENV{HOME}/$config" unless -e $config;
$debug and print "config: $config\n";
if ( ! -e $config and ! -l $config ) {
# check for missing components
my $missing;
my @a = `which analyseplugin`;
@a or print( <<WARN
LADSPA helper program 'analyseplugin' not found
in $ENV{PATH}, your shell's list of executable
directories. You will probably have more fun with the LADSPA
libraries and executables installed. http://ladspa.org
WARN
) and sleeper (0.6) and $missing++;
my @b = `which ecasound`;
@b or print( <<WARN
Ecasound executable program 'ecasound' not found
in $ENV{PATH}, your shell's list of executable
directories. This suite depends on the Ecasound
libraries and executables for all audio processing!
WARN
) and sleeper (0.6) and $missing++;
if ( $missing ) {
print "You lack $missing main parts of this suite.
Do you want to continue? [N] ";
$missing and
my $reply = <STDIN>;
chomp $reply;
print("Goodbye.\n"), exit unless $reply =~ /y/i;
}
print <<HELLO;
Aloha. Welcome to Nama and Ecasound.
HELLO
sleeper (0.6);
print "Configuration file $config not found.
May I create it for you? [yes] ";
my $make_namarc = <STDIN>;
sleep 1;
print <<PROJECT_ROOT;
Nama places all sound and control files under the
project root directory, by default $ENV{HOME}/nama.
PROJECT_ROOT
print "Would you like to create $ENV{HOME}/nama? [yes] ";
my $reply = <STDIN>;
chomp $reply;
if ($reply !~ /n/i){
# write project root path into default namarc
$default =~ s/^project_root.*$/project_root: $ENV{HOME}\/nama/m;
# create path nama/untitled/.wav
#
# this creates directories for
# - project root
# - project name 'untitled', the default project, and
# - project untitled's hidden directory for holding WAV files
mkpath( join_path($ENV{HOME}, qw(nama untitled .wav)) );
write_file(user_customization_file(), $custom_pl);
} else {
print <<OTHER;
Please make sure to set the project_root directory in
.namarc, or on the command line using the -d option.
OTHER
}
if ($make_namarc !~ /n/i){
write_file($config, $default);
}
sleep 1;
print "\n.... Done!\n\nPlease edit $config and restart Nama.\n\n";
print "Exiting.\n";
exit;
}
}
1;
__END__
|