Move check for empty string in @notes item from stdin/synths.pl to module

Also added newline in Internationale's background.sh shell script
This commit is contained in:
Job Bautista 2022-05-01 22:29:36 +08:00
parent c72baa025d
commit 27b0775933
3 changed files with 37 additions and 31 deletions

View File

@ -73,19 +73,23 @@ our $synthSampleRate=48000;
sub createSynths {
foreach my $note (@notes) {
my @currentNote = split(':', $note);
print '"|sox -r ', $synthSampleRate, ' -n -p synth ',
POSIX::floor($currentNote[0]*1000)/1000;
my @pitches = split('/', uc $currentNote[1]);
for my $currentSynthAndPitch (iterate(0,$maxSynthChannels-1)) {
print ' ', $synthtype[$currentSynthAndPitch];
if(exists($pitches[$currentSynthAndPitch])) {
print ' ', $pitches[$currentSynthAndPitch];
} else {
print ' ', $pitches[-1];
if ($note ne "") { # We don't want to print a forever synth
my @currentNote = split(':', $note);
print '"|sox -r ', $synthSampleRate, ' -n -p synth ',
POSIX::floor($currentNote[0]*1000)/1000;
my @pitches = split('/', uc $currentNote[1]);
for my $currentSynthAndPitch (iterate(0,$maxSynthChannels-1)) {
print ' ', $synthtype[$currentSynthAndPitch];
if(exists($pitches[$currentSynthAndPitch])) {
print ' ', $pitches[$currentSynthAndPitch];
} else {
print ' ', $pitches[-1];
}
}
}
print '"', "\n";
print '"', "\n";
} else {
print "\n"; # For compatibility with libsox.sh scripts that differentiated
} # loop and non-loop parts
}
@notes = (); # You usually want to reset the notes array after calling this
}
@ -106,22 +110,26 @@ our $maxSamplesChannels=1;
sub createSamples {
foreach my $note (@notes) {
my @currentNote = split(':', $note);
my @pitches = split('/', uc $currentNote[1]);
if($maxSamplesChannels == 1) {
print '"|sox ', $samplesDir, '/', uc $pitches[0], '.* -p ',
'trim 0 ', POSIX::floor($currentNote[0]*1000)/1000, '"', "\n";
} else {
print '"|sox -M ';
if ($note ne "") {
my @currentNote = split(':', $note);
my @pitches = split('/', uc $currentNote[1]);
if($maxSamplesChannels == 1) {
print '"|sox ', $samplesDir, '/', uc $pitches[0], '.* -p ',
'trim 0 ', POSIX::floor($currentNote[0]*1000)/1000, '"', "\n";
} else {
print '"|sox -M ';
for my $currentSample (iterate(0,$maxSamplesChannels-1)) {
if(exists($pitches[$currentSample])) {
print $samplesDir, '/', uc $pitches[$currentSample], '.* ';
} else {
print $samplesDir, '/', uc $pitches[-1], '.* ';
if(exists($pitches[$currentSample])) {
print $samplesDir, '/', uc $pitches[$currentSample], '.* ';
} else {
print $samplesDir, '/', uc $pitches[-1], '.* ';
}
}
print '-p trim 0 ',
POSIX::floor($currentNote[0]*1000)/1000, '"', "\n";
}
print '-p trim 0 ',
POSIX::floor($currentNote[0]*1000)/1000, '"', "\n";
} else {
print "\n";
}
}
@notes = (); # You usually want to reset the notes array after calling this

View File

@ -11,4 +11,4 @@ DIR="background"
$DIR/verse6 \
$DIR/verse7 \
$DIR/chorus/1 $DIR/chorus/2 \
) | ../stdin/samples.pl 100 4 2 ../piano/ff
) | ../stdin/samples.pl 100 4 2 ../piano/ff

View File

@ -44,11 +44,9 @@ setDefaultSynthType(@synths);
our @notestemp=<STDIN>;
for my $note (@notestemp) {
if ($note ne "\n") { # Check first if string is just a trailing newline,
$note =~ s/(\$\w+)/$1/ee; # Evaluate variable names in stdin
$note =~ s/\R\z//; # Remove trailing newlines, else xargs will get confused
push (@notes, $note);
} # we don't want to print a forever synth after all
$note =~ s/(\$\w+)/$1/ee; # Evaluate variable names in stdin
$note =~ s/\R\z//; # Remove trailing newlines, else xargs will get confused
push (@notes, $note);
}
createSynths();