Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Question: mido.filename Not Set With Save to New File - True? #589

@JeffRocchio

Description

@JeffRocchio

Using the docs @ https://mido.readthedocs.io/en/stable/files/midi.html#creating-a-new-file I:

  • Create a new midi file object-instance.
  • I Append a track and write data to that.
  • Then I save the file to my hard drive.
  • If, immediately after, I query the newly saved mido.midifile object for it's filename: mido.MidiFile.filename I get the result "None."

I'm here just looking for a confirm that is correct behavior (i.e., I need to keep my user-supplied filename around for later use even after the midi file object save).

My actual code snips:

class OutputMIDI:
    def __init__(self, outputFile):
        self.midiOut = mido.MidiFile()
        self.outFilePath = outputFile

    def timeshiftTrack(self, track):
        pass # <-- figure this out. I think this should be a private function that gets called by appendTrack().

    def appendTrack(self, track):
        self.midiOut.tracks.append(track)

    def writeFile(self):
        print(f'Writing File - outfile = {self.outFilePath}')
        self.midiOut.save(self.outFilePath)
        # Just test if the save updates the object's filename param:
        print(f'File Written - outfile = {self.midiOut.filename}')

After building the outputMIDI, when I call writeFile() I get:

Writing File - outfile = /home/jroc/Dropbox/projects/Audio_AddCountIn_MIDI/test-21a.mid
File Written - outfile = None

NOTE: The file is actually written to disk and is fine.

And Thank You for creating mido!

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions