0

that's the way I get note:

def read_notes_from_file(file):
  notes = []
  song = converter.parse(file)
  notes_in_song = None
  try:
      s2 = instrument.partitionByInstrument(song)
      notes_in_song = s2.parts[0].recurse()
  except:
      notes_in_song = song.flat.notes
  for element in notes_in_song:
      if isinstance(element, note.Note):
          notes.append(str(element.pitch))
      elif isinstance(element, chord.Chord):
          notes.append('.'.join(str(n) for n in element.normalOrder))

  return notes

that's the way I create midi:

def create_midi(prediction_output, filename):
    offset = 0
    output_notes = []
    for item in prediction_output:
        pattern = item[0]

        if ('.' in pattern) or pattern.isdigit():
            notes_in_chord = pattern.split('.')
            notes = []
            for current_note in notes_in_chord:
                new_note = note.Note(int(current_note))
                new_note.storedInstrument = instrument.Piano()
                notes.append(new_note)
            new_chord = chord.Chord(notes)
            new_chord.offset = offset
            output_notes.append(new_chord)

        else:
            new_note = note.Note(pattern)
            new_note.offset = offset
            new_note.storedInstrument = instrument.Piano()
            output_notes.append(new_note)

        offset += 0.5

    midi_stream = stream.Stream(output_notes)
    midi_stream.write('midi', fp='{}.mid'.format(filename))

that's the note I input into create_midi:

['G1', 'G6', 'C#5', '9.0.2.4', 'E-7', '2.5.7.9', 'C#6', '7.9.1.2', '11.2.4.7', '4.9.10', '3.5.7.11', '8.9.0', '11.2.3', '5.7.10', '7.0', '6.10.11', '2.3.5.9', '2.8', '5.11', '2.4.5', '5.6.7', '5.7.9.11', '1.2.5.8', '6.7.11.1.2', '1.5.8.9', '2', '3.4.8', '10.11.3.6', '4.5.8.9', '3.6.7', '4.5.7.11', '4.5.9', '3.7.11', '3.5.7.8', '5.9', '5.7.10.11', '2.4.6.10', '5.7.10.11', '10.11.0.2.3', '3.4.8', '11.4', '10.0.4.5', '5.8', '11.2.4.6', '2.6.7', '3.6.7.8.9', '4.5.8', '5.8.11.1', '2.5.7', '11.1.4', '1.4.6.9', '11.1', '4.6.7.11', '11.3.6.7', '2.4.6.9', '2.4', '2.8', '4.8.11', '11.2.5', '2.4.6.10', '10.11.3.6', '2.6.10', '5.8.10.0.1', '2.5.8.10', '0.6', '3.7.10.11', '3.6', '3.6.10', '2.4.6', '5.11', '11.0.4.7', '10.2.5', '11.1.2', '3.6.9', '5.6.9', '5.7.9.11.2', '5.8.10.1', '1.2.4.6.9', '6.7.11.2', '3.5.8.9', '2.3.7.10', '3.6', '6.8.9.11.1', '1.4.7.9.10', '2.5.8.10', '6.10.11', '1.4.7', '4.5.8', '6.8.9.1', '5.8', '2.3.6.9', '3.4.6.8.11', '11.2.4.7', '10.1', '11.3.4.6', '4.5.7', '3.6.9', '11.2.4.7', '5.7.10', '3.7.10']

that's the note I get after input the midi created from note above into read_notes_from_file:

['G4', 'G4', 'C4', 'A4', 'E4', 'D4', 'C4', 'G4', 'C#4', 'E4', 'E-4', 'G#4', 'C#4', 'F4', 'G4', 'F#4', 'D4', 'D4', 'F4', 'D4', 'F4', 'F4', 'C#4', 'F#4', 'C#4', 'D4', 'E-4', 'C#4', 'E4', 'E-4', 'E4', 'E4', 'E-4', 'E-4', 'F4', 'F4', 'D4', 'F4', 'C#4', 'E-4', 'C#4', 'C#4', 'F4', 'C#4', 'D4', 'E-4', 'E4', 'F4', 'D4', 'C#4', 'C#4', 'C#4', 'E4', 'C#4', 'D4', 'D4', 'D4', 'E4', 'C#4', 'D4', 'C#4', 'D4', 'F4', 'D4', 'C4', 'E-4', 'E-4', 'E-4', 'D4', 'F4', 'C#4', 'C#4', 'C#4', 'E-4', 'F4', 'F4', 'F4', 'C#4', 'F#4', 'E-4', 'D4', 'E-4', 'F#4', 'C#4', 'D4', 'F#4', 'C#4', 'E4', 'F#4', 'F4', 'D4', 'E-4', 'C#4', 'C#4', 'C#4', 'E4', 'E-4', 'C#4', 'F4', 'E-4']

they just become notes from a chord, i don't know how to deal with it .it there anything wrong into the code?

  • Offset's the timing counter, right? And when you say `'C#5', '9.0.2.4'`, you want it to play 9 half-steps above C#, the root of C#, D#, then E# right? I think when you do `int(current_note)` you need to add that root C# MIDI value to all of them. It probably has a function... I don't know that app tho. So you'd have to look for one, or find a MIDI table online and roll-your own. – Doyousketch2 Jun 19 '21 at 09:14

1 Answers1

0

If you add print(pattern) after pattern = item[0] you'll see that you're trimming your input in an unexpected way. C# becomes C, and 2.5.7 becomes 2. That is why the chords are being exported as single notes.

Jacob Walls
  • 873
  • 3
  • 15