#!/usr/bin/perl -w use warnings; use strict; # muxsa-rl # # part of muxsa, https://git-nks-public.tik.uni-stuttgart.de/edu/muxsa # # Audacity (https://www.audacityteam.org/) is an audio recoder/editor. # This script _r_enumbers _l_abels in Audacity. # Usage: muxsa-rl labeltext,labeltext,labeltext,... # where labeltext is # - an integer, which will be padded with zeros to four digits # - two integers separated by minus, which will be considered as a range # - one integer followed by * and text, will set so many labels to text # - any other text, which will be copied verbatim # # Example: muxsa-rl 0,5-7,42,END # will set the first label in Audacity's label track to "0000", # followed by "0005", "0006", "0007", "0042", and "END" # # NB: this script assumes that muxsa-vr is running in another shell, # to capture Audacity's scripting replies # ############################################################################ # # MIT License # # Copyright (c) 2025 Sebastian Kiesel # # Permission is hereby granted, free of charge, to any person obtaining a # copy of this software and associated documentation files (the "Software"), # to deal in the Software without restriction, including without limitation # the rights to use, copy, modify, merge, publish, distribute, sublicense, # and/or sell copies of the Software, and to permit persons to whom the # Software is furnished to do so, subject to the following conditions: # # The above copyright notice and this permission notice shall be included # in all copies or substantial portions of the Software. # # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL # THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR # OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, # ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR # OTHER DEALINGS IN THE SOFTWARE. # ############################################################################ my @labels; foreach my $sequence (@ARGV){ foreach my $section ( split(/,/, $sequence) ){ if( $section=~/^([0-9]+)$/ ){ push(@labels, sprintf("%04i",$section)); } elsif( $section=~/^([0-9]+)-([0-9]+)$/ ){ for( my $i=$1 ; $i<=$2 ; $i++ ){ push(@labels, sprintf("%04i",$i)); } } elsif( $section=~/^([0-9]+)\*(.*)$/ ){ for( my $i=0 ; $i<$1 ; $i++ ){ push(@labels, $2); } } else{ push(@labels, $section); } } } my $audacity_pipe_path = "/tmp/audacity_script_pipe.to." . $<; print("Trying to open script pipe to Audacity: " . $audacity_pipe_path . "\n"); my $aph; open( $aph , ">", $audacity_pipe_path) or die("Cannot open " . $audacity_pipe_path . " for writing: " . $!); for( my $i = 0 ; $i < scalar @labels ; $i++ ){ my $command = sprintf("SetLabel: Label=%d Selected=0 Text=\"%s\"\n", $i, $labels[$i] ); print("Will send to Audacity: " . $command ); print($aph $command); } close($aph); print("Sent " . scalar @labels . " SetLabel commands. Goodbye.\n"); # EOF ############################################################################