This commit delivers three key improvements focused on user experience and bug fixing.
Browse files1. **Add Rich Info Text to 8-bit Synthesizer UI**
2. **Detect and Log Stereo MIDI Information**
3. **Fix Stereo Loss in "Convert to Solo Piano":**
- Resolved a critical bug where enabling "Convert to Solo Piano" would collapse stereo MIDI files into mono.
Files changed (2)
- app.py+115-15
- src/TMIDIX.py+26-12
528 unmodified lines529530531532533534659 unmodified lines1194119511961197119811991149 unmodified lines23492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371528 unmodified linesreturn None# =================================================================================================# === Stage 1: Audio to MIDI Transcription Functions ===# =================================================================================================659 unmodified lines# For MIDI files, we start at 0% and directly proceed to the rendering steps.update_progress(0, "MIDI file detected, skipping transcription...")print("MIDI file detected. Skipping transcription. Proceeding directly to rendering.")midi_path_for_rendering = input_file_pathelse:temp_dir = "output/temp_transcribe" # Define temp_dir early for the fallback1149 unmodified lines# Define the 8-bit UI components in one place for easy referencegr.Markdown("### 8-bit Synthesizer Settings")with gr.Accordion("8-bit Synthesizer Settings", open=True, visible=False) as synth_8bit_settings:s8bit_preset_selector = gr.Dropdown(choices=["Custom", "Auto-Recommend (Analyze MIDI)"] + list(S8BIT_PRESETS.keys()), value="Custom", label="Style Preset",info="Select a preset to auto-fill the settings below. Choose 'Custom' for manual control.\nFor reference and entertainment only. These presets are not guaranteed to be perfectly accurate.")s8bit_waveform_type = gr.Dropdown(['Square', 'Sawtooth', 'Triangle'], value='Square', label="Waveform Type")s8bit_pulse_width = gr.Slider(0.01, 0.99, value=0.5, step=0.01, label="Pulse Width (Square Wave Only)")s8bit_envelope_type = gr.Dropdown(['Plucky (AD Envelope)', 'Sustained (Full Decay)'], value='Plucky (AD Envelope)', label="Envelope Type")s8bit_decay_time_s = gr.Slider(0.01, 1.0, value=0.1, step=0.01, label="Decay Time (s)")s8bit_vibrato_rate = gr.Slider(0, 20, value=5, label="Vibrato Rate (Hz)")s8bit_vibrato_depth = gr.Slider(0, 50, value=0, label="Vibrato Depth (Hz)")s8bit_bass_boost_level = gr.Slider(0.0, 1.0, value=0.0, step=0.05, label="Bass Boost Level", info="Adjusts the volume of the sub-octave. 0 is off.")s8bit_smooth_notes_level = gr.Slider(0.0, 1.0, value=0.0, step=0.05, label="Smooth Notes Level", info="Level of fade-in/out to reduce clicks. 0=off, 1=max.")s8bit_continuous_vibrato_level = gr.Slider(0.0, 1.0, value=0.0, step=0.05, label="Continuous Vibrato Level", info="Controls vibrato continuity. 0=resets per note, 1=fully continuous.")# --- New accordion for advanced effects ---with gr.Accordion("Advanced Synthesis & FX", open=False):s8bit_noise_level = gr.Slider(0.0, 1.0, value=0.0, step=0.05, label="Noise Level", info="Mixes in white noise. Great for percussion or adding 'air'.")s8bit_distortion_level = gr.Slider(0.0, 0.9, value=0.0, step=0.05, label="Distortion Level", info="Applies wave-shaping distortion for a grittier, harsher sound.")s8bit_fm_modulation_depth = gr.Slider(0.0, 1.0, value=0.0, step=0.05, label="FM Depth", info="Depth of Frequency Modulation. Creates complex, metallic, or bell-like tones.")s8bit_fm_modulation_rate = gr.Slider(0.0, 500.0, value=0.0, step=1.0, label="FM Rate", info="Rate of Frequency Modulation. Higher values create brighter, more complex harmonics.")# Create a dictionary mapping key names to the actual Gradio componentsui_component_map = locals()528 unmodified lines529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572659 unmodified lines12321233123412351236123712381239124012411149 unmodified lines239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471528 unmodified linesreturn Nonedef is_stereo_midi(midi_path: str) -> bool:"""Checks if a MIDI file contains the specific stereo panning control changes(hard left and hard right) created by the merge_midis function.Args:midi_path (str): The file path to the MIDI file.Returns:bool: True if both hard-left (0) and hard-right (127) pan controls are found, False otherwise."""try:midi_data = pretty_midi.PrettyMIDI(midi_path)found_left_pan = Falsefound_right_pan = Falsefor instrument in midi_data.instruments:for control_change in instrument.control_changes:# MIDI Controller Number 10 is for Panning.if control_change.number == 10:if control_change.value == 0:found_left_pan = Trueelif control_change.value == 127:found_right_pan = True# Optimization: If we've already found both, no need to check further.if found_left_pan and found_right_pan:return Truereturn found_left_pan and found_right_panexcept Exception as e:# If the MIDI file is invalid or another error occurs, assume it's not our special stereo format.print(f"Could not analyze MIDI for stereo info: {e}")return False# =================================================================================================# === Stage 1: Audio to MIDI Transcription Functions ===# =================================================================================================659 unmodified lines# For MIDI files, we start at 0% and directly proceed to the rendering steps.update_progress(0, "MIDI file detected, skipping transcription...")print("MIDI file detected. Skipping transcription. Proceeding directly to rendering.")if is_stereo_midi(input_file_path):print("\nINFO: Stereo pan information (Left/Right) detected in the input MIDI. It will be rendered in stereo.\n")midi_path_for_rendering = input_file_pathelse:temp_dir = "output/temp_transcribe" # Define temp_dir early for the fallback1149 unmodified lines# Define the 8-bit UI components in one place for easy referencegr.Markdown("### 8-bit Synthesizer Settings")with gr.Accordion("8-bit Synthesizer Settings", open=True, visible=False) as synth_8bit_settings:s8bit_preset_selector = gr.Dropdown(choices=["Custom", "Auto-Recommend (Analyze MIDI)"] + list(S8BIT_PRESETS.keys()),value="Custom",label="Style Preset",info="Select a preset to auto-fill the settings below. Choose 'Custom' for manual control or 'Auto-Recommend' to analyze the MIDI.\nFor reference and entertainment only. These presets are not guaranteed to be perfectly accurate.")s8bit_waveform_type = gr.Dropdown(['Square', 'Sawtooth', 'Triangle'],value='Square',label="Waveform Type",info="The fundamental timbre of the sound. Square is bright and hollow (classic NES), Sawtooth is aggressive and buzzy, Triangle is soft and flute-like.")s8bit_pulse_width = gr.Slider(0.01, 0.99, value=0.5, step=0.01,label="Pulse Width (Square Wave Only)",info="Changes the character of the Square wave. Low values (~0.1) are thin and nasal, while mid values (~0.5) are full and round.")s8bit_envelope_type = gr.Dropdown(['Plucky (AD Envelope)', 'Sustained (Full Decay)'],value='Plucky (AD Envelope)',label="Envelope Type",info="Shapes the volume of each note. 'Plucky' is a short, percussive sound. 'Sustained' holds the note for its full duration.")s8bit_decay_time_s = gr.Slider(0.01, 1.0, value=0.1, step=0.01,label="Decay Time (s)",info="For the 'Plucky' envelope, this is the time it takes for a note to fade to silence. Low values are short and staccato; high values are longer and more resonant.")s8bit_vibrato_rate = gr.Slider(0, 20, value=5,label="Vibrato Rate (Hz)",info="The SPEED of the pitch wobble. Low values create a slow, gentle waver. High values create a fast, frantic buzz.")s8bit_vibrato_depth = gr.Slider(0, 50, value=0,label="Vibrato Depth (Hz)",info="The INTENSITY of the pitch wobble. Low values are subtle or off. High values create a dramatic, siren-like pitch bend.")s8bit_bass_boost_level = gr.Slider(0.0, 1.0, value=0.0, step=0.05,label="Bass Boost Level",info="Mixes in a sub-octave (a square wave one octave lower). Low values have no effect; high values add significant weight and power.")s8bit_smooth_notes_level = gr.Slider(0.0, 1.0, value=0.0, step=0.05,label="Smooth Notes Level",info="Applies a tiny fade-in/out to reduce clicking. Low values (or 0) give a hard, abrupt attack. High values give a softer, cleaner onset.")s8bit_continuous_vibrato_level = gr.Slider(0.0, 1.0, value=0.0, step=0.05,label="Continuous Vibrato Level",info="Controls vibrato continuity across notes. Low values (0) reset vibrato on each note (bouncy). High values (1) create a smooth, connected 'singing' vibrato.")# --- New accordion for advanced effects ---with gr.Accordion("Advanced Synthesis & FX", open=False):s8bit_noise_level = gr.Slider(0.0, 1.0, value=0.0, step=0.05,label="Noise Level",info="Mixes in white noise with the main waveform. Low values are clean; high values add 'grit', 'air', or a hissing quality, useful for percussion.")s8bit_distortion_level = gr.Slider(0.0, 0.9, value=0.0, step=0.05,label="Distortion Level",info="Applies wave-shaping to make the sound harsher. Low values are clean; high values create a crushed, 'fuzzy', and aggressive tone.")s8bit_fm_modulation_depth = gr.Slider(0.0, 1.0, value=0.0, step=0.05,label="FM Depth",info="Frequency Modulation intensity. At low values, there is no effect. At high values, it creates complex, metallic, or bell-like tones.")s8bit_fm_modulation_rate = gr.Slider(0.0, 500.0, value=0.0, step=1.0,label="FM Rate",info="Frequency Modulation speed. Low values create a slow 'wobble'. High values create fast modulation, resulting in bright, dissonant harmonics.")# Create a dictionary mapping key names to the actual Gradio componentsui_component_map = locals()
6047 unmodified lines604860496050605160526053605460556056605760586059606060616062606360646065606660676068606960706071607260736074607560766077607860796047 unmodified linespatches_index=6,keep_drums=False,):cscore = chordify_score([1000, escore_notes])sp_escore_notes = []for c in cscore:seen = []chord = []for cc in c:if cc[channels_index] != 9:if cc[pitches_index] not in seen:cc[channels_index] = 0cc[patches_index] = 0chord.append(cc)seen.append(cc[pitches_index])else:if keep_drums:if cc[pitches_index]+128 not in seen:chord.append(cc)seen.append(cc[pitches_index]+128)sp_escore_notes.append(chord)6047 unmodified lines60486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936047 unmodified linespatches_index=6,keep_drums=False,):"""A modified version of TMIDIX.solo_piano_escore_notes that preserves theoriginal MIDI channel of each note. This allows stereo panning information,which is often channel-dependent, to be maintained during the conversionto a solo piano performance."""cscore = chordify_score([1000, escore_notes])sp_escore_notes = []for c in cscore:# --- Use a set to store (pitch, channel) tuples for uniqueness ---seen_notes = set()chord = []for cc in c:if cc[channels_index] != 9: # If not a drum channel# Create a unique identifier for each note using both pitch and channelnote_id = (cc[pitches_index], cc[channels_index])# Check if this specific pitch-channel combination has been seenif note_id not in seen_notes:# The original function forced the channel to 0, destroying stereo separation.# We comment out that line and ONLY change the instrument patch.# cc[channels_index] = 0 <-- THIS LINE IS REMOVED# Force the instrument patch to 0 (Acoustic Grand Piano)cc[patches_index] = 0 # Set patch to Grand Pianochord.append(cc)seen_notes.add(note_id) # Add the unique ID to the setelse: # If it is a drum channelif keep_drums:# Apply the same logic for drums to be safedrum_id = (cc[pitches_index] + 128, cc[channels_index])if drum_id not in seen_notes:chord.append(cc)seen_notes.add(drum_id)sp_escore_notes.append(chord)
app.py+115-15
src/TMIDIX.py+26-12