Add instrument argument
This commit is contained in:
parent
bb4a9485df
commit
2d8cd7fd79
@ -18,5 +18,5 @@ file 363.png
|
||||
where duration is in seconds
|
||||
|
||||
```bash
|
||||
ffmpeg -f concat -i concat.txt -vf "fps=25,format=yuv420p" -vsync vfr output.webm
|
||||
ffmpeg -y -f concat -i concat.txt -vf "fps=25,format=yuv420p" -vsync vfr output.webm
|
||||
```
|
@ -2,7 +2,7 @@
|
||||
|
||||
IN=$1
|
||||
[[ $IN ]]|| IN="concat.txt"
|
||||
FILES=$(cat $IN | grep file | awk '{print $2}')
|
||||
FILES=$(cat $IN | grep file | awk '{print $2}' | uniq)
|
||||
|
||||
echo $FILES
|
||||
|
||||
|
@ -53,12 +53,20 @@ def separate_instruments(input_midi_path, output_folder):
|
||||
return outputs
|
||||
|
||||
|
||||
def change_instrument(input, output):
|
||||
def change_instrument(input, output, instrument=None):
|
||||
s = music21.converter.parse(input)
|
||||
|
||||
if instrument is None:
|
||||
instrument = music21.instrument.Piano()
|
||||
|
||||
i=0
|
||||
for el in s.recurse():
|
||||
if 'Instrument' in el.classes: # or 'Piano'
|
||||
el.activeSite.replace(el, music21.instrument.Piano())
|
||||
try:
|
||||
el.activeSite.replace(el, instrument)
|
||||
except music21.exceptions21.StreamException:
|
||||
i+=1
|
||||
print(f"caught StreamException [{i}]")
|
||||
|
||||
s.write('midi', output)
|
||||
|
||||
@ -74,7 +82,7 @@ def create_audios(files, dest="out"):
|
||||
print(f"Converted {basename(el)}.mp3")
|
||||
|
||||
|
||||
def __main__(SCORE, OUT):
|
||||
def __main__(SCORE, OUT, instrument=None):
|
||||
os.makedirs(OUT, exist_ok=True)
|
||||
|
||||
if SCORE.split(".")[-1] == "mscz":
|
||||
@ -90,7 +98,7 @@ def __main__(SCORE, OUT):
|
||||
midi_files = separate_instruments(MIDI_SCORE, OUT)
|
||||
|
||||
for file in midi_files:
|
||||
change_instrument(file, file)
|
||||
change_instrument(file, file, instrument=instrument)
|
||||
|
||||
print("=== Creating audios ===")
|
||||
create_audios(midi_files, OUT)
|
||||
@ -102,8 +110,21 @@ def __main__(SCORE, OUT):
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
if len(sys.argv) < 3:
|
||||
if len(sys.argv) != 3 and not (len(sys.argv) == 5 and sys.argv[3] == "--instrument"):
|
||||
print(f"Usage: {sys.argv[0]} <file.mscz> <out/>")
|
||||
exit(1)
|
||||
|
||||
__main__(sys.argv[1], sys.argv[2])
|
||||
instrument=None
|
||||
if len(sys.argv) > 3:
|
||||
match sys.argv[4]:
|
||||
case "piano":
|
||||
instrument = music21.instrument.Piano()
|
||||
case "organ":
|
||||
instrument = music21.instrument.Organ()
|
||||
case "flute":
|
||||
instrument = music21.instrument.Flute()
|
||||
case _:
|
||||
print("Invalid instrument '", sys.argv[4], "'")
|
||||
exit(1)
|
||||
|
||||
__main__(sys.argv[1], sys.argv[2], instrument=instrument)
|
@ -3,7 +3,15 @@
|
||||
AUDIOS=out
|
||||
BASE_NAME="instrument_"
|
||||
BASE_OUT_NAME="combined_"
|
||||
VOLUME_2="0.1"
|
||||
VOLUME_2="0.3"
|
||||
ADDITIONAL=$1
|
||||
|
||||
usage () {
|
||||
echo "Usage: $0 <soliste.mp3>"
|
||||
exit 1
|
||||
}
|
||||
|
||||
[[ $ADDITIONAL ]] || usage
|
||||
|
||||
|
||||
combine () {
|
||||
@ -23,7 +31,11 @@ output_file () {
|
||||
echo "${AUDIOS}/${BASE_OUT_NAME}$1.mp3"
|
||||
}
|
||||
|
||||
combine "$(input_file 1)" "$(input_file 3)" "$(output_file 1)"
|
||||
combine "$(input_file 2)" "$(input_file 3)" "$(output_file 2)"
|
||||
combine "$(input_file 3)" "$(input_file 1)" "$(output_file 3)"
|
||||
combine "$(input_file 4)" "$(input_file 1)" "$(output_file 4)"
|
||||
additional () {
|
||||
echo $ADDITIONAL
|
||||
}
|
||||
|
||||
combine "$(input_file 1)" "$(additional 3)" "$(output_file 1)"
|
||||
combine "$(input_file 2)" "$(additional 3)" "$(output_file 2)"
|
||||
combine "$(input_file 3)" "$(additional 1)" "$(output_file 3)"
|
||||
combine "$(input_file 4)" "$(additional 1)" "$(output_file 4)"
|
||||
|
Loading…
Reference in New Issue
Block a user