import gradio as gr from fastapi import FastAPI, Request import json # THIS VERSION WORKS # AND SENDS BACK A NOTE A FIFTH HIGHER THAN THE INPUT NOT ON THE SELECTED PORT # # ✅ Create FastAPI App app = FastAPI() # ✅ MIDI Processing Function in Python @app.post("/midi_input") async def process_midi(request: Request): try: midi_data = await request.json() note = midi_data["note"] velocity = midi_data["velocity"] print(f"🎹 Received MIDI Note: {note}, Velocity: {velocity}") # 🚀 Process MIDI data (example: Transpose + Generate New Notes) generated_note = (note + 5) % 128 # Transpose up by 3 semitones generated_velocity = min(velocity + 10, 127) # Increase velocity slightly # ✅ Send MIDI Response Back to Client return { "status": "success", "generated_note": generated_note, "generated_velocity": generated_velocity, "original_note": note } except Exception as e: print(f"🚨 Error processing MIDI: {str(e)}") return {"status": "error", "message": str(e)} # ✅ JavaScript to Capture and Send MIDI Data midi_js = """