Giter VIP home page Giter VIP logo

Comments (5)

Rainbow-Dreamer avatar Rainbow-Dreamer commented on June 9, 2024

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")

from sf2_loader.

gildurao avatar gildurao commented on June 9, 2024

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.

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

from sf2_loader.

Rainbow-Dreamer avatar Rainbow-Dreamer commented on June 9, 2024

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.

from sf2_loader.

gildurao avatar gildurao commented on June 9, 2024

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.

Thank you for the clarification! Feel free to close the issue.

from sf2_loader.

Rainbow-Dreamer avatar Rainbow-Dreamer commented on June 9, 2024

You're welcome :)

from sf2_loader.

Related Issues (16)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.