Closed gildurao closed 2 years ago
I see what is causing this issue here. Let me clarify the parameters of the function export_midi_file
, the first parameter current_chord
is the name of the midi file you want to export as audio files using loaded soundfont files, and the name
parameter is the name of the exported audio file. Here your first parameter should be rf"{defaultPath}\generated_music.mid"
instead of piece
, and if the variable piece
is the name of the exported audio file you want, you can set name=piece
, but actually piece
is a defined class in musicpy, so it is better to use another variable name to avoid naming conflicts.
Or if you actually want to export a piece instance to a midi file, just simply use musicpy's write
function, like this:
write(piece1, name=rf"{defaultPath}\generated_music.mid")
I see what is causing this issue here. Let me clarify the parameters of the function
export_midi_file
, the first parametercurrent_chord
is the name of the midi file you want to export as audio files using loaded soundfont files, and thename
parameter is the name of the exported audio file. Here your first parameter should berf"{defaultPath}\generated_music.mid"
instead ofpiece
, and if the variablepiece
is the name of the exported audio file you want, you can setname=piece
, but actuallypiece
is a defined class in musicpy, so it is better to use another variable name to avoid naming conflicts.
Does this mean I first have to generate an audio file, using export_piece
and then I can use export_midi_file
?
The variable piece here is the output of calling piece
from `musicpy```, I can share a bit
more of my code:
if(musicalParsing == "random"):
# this is a musicpy chord object
musicalOutput = lmusic_parser.random_parsing(output)
piece = sf.mp.piece(
[musicalOutput], [sf2.current_preset_num], random.randint(40, 220), [0], channels=[1]
)
now = datetime.datetime.now()
now = now.strftime('%Y_%m_%d_%H_%M_%S')
sf2.export_midi_file(
piece, name=rf"{defaultPath}\generated_music_{now}.mid")
I will rename the variable, thanks for the tip
No, you can use musicpy's write
function, which can directly output any musicpy data structures to a midi file.
The export_midi_file
function of sf2_loader is to read a midi file, and render it to an audio file using loaded soundfont files, and then export the audio file. The write
function of musicpy is to convert a musicpy data structure (such as note
, chord
, track
, piece
) to a midi file.
No, you can use musicpy's
write
function, which can directly output any musicpy data structures to a midi file. Theexport_midi_file
function of sf2_loader is to read a midi file, and render it to an audio file using loaded soundfont files, and then export the audio file. Thewrite
function of musicpy is to convert a musicpy data structure (such asnote
,chord
,track
,piece
) to a midi file.
Thank you for the clarification! Feel free to close the issue.
You're welcome :)
Hello 👋 ,
Today I tried to export a piece to a midi file, but I am facing the following errors from musicpy and midifiles.
Here is the python code with the export midi call
The variable
piece
is correct because I can generate .wav files correctly.Output of
pip list
:Output of
python --version