C:\Users\hp\AppData\Local\Programs\Python\Python312\Lib\site-packages\pretty_midi\pretty_midi.py:100: RuntimeWarning: Tempo, Key or Time signature change events found on non-zero tracks.  This is not a valid type 0 or type 1 MIDI file.  Tempo, Key or Time Signature may be wrong.
  warnings.warn(
Traceback (most recent call last):
  File "C:\Users\hp\Downloads\jil.py", line 182, in <module>
    main()
  File "C:\Users\hp\Downloads\jil.py", line 162, in main
    music21_stream = convert_midi_to_music21(midi_file_path)
                     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\hp\Downloads\jil.py", line 130, in convert_midi_to_music21
    for pm_note in midi_data.notes:
                   ^^^^^^^^^^^^^^^
AttributeError: 'PrettyMIDI' object has no attribute 'notes'

also provide full revised script once you're done thinking:

```
import pretty_midi
from music21 import (
    stream, note, tempo, meter, key, environment,
    dynamics, articulations, converter, pitch as m21pitch, duration as m21duration
)
import argparse
import os
import sys
import tempfile
import logging
import shutil  # Added import for shutil

# Configure logging
logging.basicConfig(level=logging.INFO, format='%(levelname)s: %(message)s')

# Piano keys dictionary for advanced mapping
piano_keys = {
    # Octave 0
    'C0': (16.35, 12), 'C#0/Db0': (17.32, 13), 'D0': (18.35, 14), 'D#0/Eb0': (19.45, 15),
    'E0': (20.60, 16), 'F0': (21.83, 17), 'F#0/Gb0': (23.12, 18), 'G0': (24.50, 19),
    'G#0/Ab0': (25.96, 20), 'A0': (27.50, 21), 'A#0/Bb0': (29.14, 22), 'B0': (30.87, 23),
    
    # Octave 1
    'C1': (32.70, 24), 'C#1/Db1': (34.65, 25), 'D1': (36.71, 26), 'D#1/Eb1': (38.89, 27),
    'E1': (41.20, 28), 'F1': (43.65, 29), 'F#1/Gb1': (46.25, 30), 'G1': (49.00, 31),
    'G#1/Ab1': (51.91, 32), 'A1': (55.00, 33), 'A#1/Bb1': (58.27, 34), 'B1': (61.74, 35),
    
    # Octave 2
    'C2': (65.41, 36), 'C#2/Db2': (69.30, 37), 'D2': (73.42, 38), 'D#2/Eb2': (77.78, 39),
    'E2': (82.41, 40), 'F2': (87.31, 41), 'F#2/Gb2': (92.50, 42), 'G2': (98.00, 43),
    'G#2/Ab2': (103.83, 44), 'A2': (110.00, 45), 'A#2/Bb2': (116.54, 46), 'B2': (123.47, 47),
    
    # Octave 3
    'C3': (130.81, 48), 'C#3/Db3': (138.59, 49), 'D3': (146.83, 50), 'D#3/Eb3': (155.56, 51),
    'E3': (164.81, 52), 'F3': (174.61, 53), 'F#3/Gb3': (185.00, 54), 'G3': (196.00, 55),
    'G#3/Ab3': (207.65, 56), 'A3': (220.00, 57), 'A#3/Bb3': (233.08, 58), 'B3': (246.94, 59),
    
    # Octave 4
    'C4': (261.63, 60), 'C#4/Db4': (277.18, 61), 'D4': (293.66, 62), 'D#4/Eb4': (311.13, 63),
    'E4': (329.63, 64), 'F4': (349.23, 65), 'F#4/Gb4': (369.99, 66), 'G4': (392.00, 67),
    'G#4/Ab4': (415.30, 68), 'A4': (440.00, 69), 'A#4/Bb4': (466.16, 70), 'B4': (493.88, 71),
    
    # Octave 5
    'C5': (523.25, 72), 'C#5/Db5': (554.37, 73), 'D5': (587.33, 74), 'D#5/Eb5': (622.25, 75),
    'E5': (659.26, 76), 'F5': (698.46, 77), 'F#5/Gb5': (739.99, 78), 'G5': (783.99, 79),
    'G#5/Ab5': (830.61, 80), 'A5': (880.00, 81), 'A#5/Bb5': (932.33, 82), 'B5': (987.77, 83),
    
    # Octave 6
    'C6': (1046.50, 84), 'C#6/Db6': (1108.73, 85), 'D6': (1174.66, 86), 'D#6/Eb6': (1244.51, 87),
    'E6': (1318.51, 88), 'F6': (1396.91, 89), 'F#6/Gb6': (1479.98, 90), 'G6': (1567.98, 91),
    'G#6/Ab6': (1661.22, 92), 'A6': (1760.00, 93), 'A#6/Bb6': (1864.66, 94), 'B6': (1975.53, 95),
    
    # Octave 7
    'C7': (2093.00, 96), 'C#7/Db7': (2217.46, 97), 'D7': (2349.32, 98), 'D#7/Eb7': (2489.02, 99),
    'E7': (2637.02, 100), 'F7': (2793.83, 101), 'F#7/Gb7': (2959.96, 102), 'G7': (3135.96, 103),
    'G#7/Ab7': (3322.44, 104), 'A7': (3520.00, 105), 'A#7/Bb7': (3729.31, 106), 'B7': (3951.07, 107),
    
    # Octave 8
    'C8': (4186.01, 108), 'C#8/Db8': (4434.92, 109), 'D8': (4698.63, 110), 'D#8/Eb8': (4978.03, 111),
    'E8': (5274.04, 112), 'F8': (5587.65, 113), 'F#8/Gb8': (5919.91, 114), 'G8': (6271.93, 115),
    'G#8/Ab8': (6644.88, 116), 'A8': (7040.00, 117), 'A#8/Bb8': (7458.62, 118), 'B8': (7902.13, 119)
}

# Reverse the piano_keys dictionary for MIDI number to note name mapping
# Modified to select only the first name before the slash
midi_to_note = {v[1]: k.split('/')[0] for k in piano_keys for v in [piano_keys[k]]}

def get_note_name(midi_number):
    """Retrieve the note name from MIDI number using the piano_keys dictionary."""
    return midi_to_note.get(midi_number, None)

def get_dynamic(velocity):
    """Map MIDI velocity to dynamic markings with more granularity."""
    if velocity >= 115:
        return "fff"  # triple forte
    elif velocity >= 100:
        return "ff"  # forte
    elif velocity >= 85:
        return "f"
    elif velocity >= 70:
        return "mf"
    elif velocity >= 55:
        return "mp"
    elif velocity >= 40:
        return "p"
    elif velocity >= 25:
        return "pp"
    else:
        return "ppp"

def get_articulation(pm_note):
    """Determine articulation based on note properties."""
    velocity = pm_note.velocity
    if velocity >= 100:
        return articulations.Staccato()
    elif velocity <= 30:
        return articulations.Legato()
    else:
        return None

def estimate_key_signature(midi_data):
    """
    Estimate the key signature of the MIDI data by evaluating the most common pitch classes.
    """
    note_counts = {i: 0 for i in range(12)}
    for pm_note in midi_data.notes:
        pitch_class = pm_note.pitch % 12
        note_counts[pitch_class] += 1
    
    # Find the most common pitch classes
    sorted_pitch_classes = sorted(note_counts.items(), key=lambda x: x[1], reverse=True)
    dominant_pitch_class = sorted_pitch_classes[0][0]

    # Basic logic to return a key signature
    if dominant_pitch_class in [0, 5]:  # C or G major
        return key.KeySignature(0)  # No sharps or flats
    elif dominant_pitch_class in [4, 9]:  # E or B major
        return key.KeySignature(1)  # One sharp
    # You can extend this with other conditions for minor and other keys.
    return key.KeySignature(0)

def convert_midi_to_music21(midi_file_path):
    """Convert a MIDI file to a music21 Stream object."""
    midi_data = pretty_midi.PrettyMIDI(midi_file_path)
    stream_obj = stream.Score()

    # Generate a basic music21 Stream from MIDI notes
    part = stream.Part()

    for pm_note in midi_data.notes:
        # Use music21's note class for each MIDI note
        note_obj = note.Note(pm_note.pitch)
        note_obj.duration = m21duration.Duration(pm_note.end - pm_note.start)
        note_obj.quarterLength = pm_note.end - pm_note.start

        # Set the dynamic of the note
        dynamic = get_dynamic(pm_note.velocity)
        note_obj.articulations.append(get_articulation(pm_note))

        part.append(note_obj)

    # Create a Stream and add the Part
    stream_obj.append(part)

    # Add a basic key signature
    key_sig = estimate_key_signature(midi_data)
    part.append(key_sig)
    
    # Return the music21 stream
    return stream_obj

def main():
    # Example MIDI path
    midi_file_path = "Fiction_-_Wotakoi_Love_is_Hard_for_Otaku_Piano.mscz.mid"  # Replace with your actual MIDI file path
    
    # Check if file exists
    if not os.path.isfile(midi_file_path):
        logging.error(f"File {midi_file_path} not found.")
        return

    # Convert MIDI to music21 Stream
    music21_stream = convert_midi_to_music21(midi_file_path)

    # Set up music21 environment to use MuseScore
    us = environment.UserSettings()

    # Set MuseScore path to a specific location
    musescore_executable = r'C:\Program Files\MuseScore 4\bin\MuseScore4.exe'

    # Verify that the specified MuseScore path exists
    if not os.path.isfile(musescore_executable):
        logging.error("Specified MuseScore executable not found at C:\\Program Files\\MuseScore 4\\bin\\MuseScore4.exe. Please check the path.")
        return

    us['musescorePath'] = musescore_executable
    logging.info(f"Using MuseScore executable at: {musescore_executable}")

    # Save and show the generated music21 stream using MuseScore
    music21_stream.show('midi', fp=midi_file_path)

if __name__ == "__main__":
    main()