{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "0",
   "metadata": {},
   "outputs": [],
   "source": [
    "import mido"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "1",
   "metadata": {},
   "outputs": [],
   "source": [
    "# Load MIDI file\n",
    "mid = mido.MidiFile('la_bamba_richie_valens.mid')\n",
    "\n",
    "# First, let's see all track names\n",
    "print(\"Track names:\")\n",
    "for i, track in enumerate(mid.tracks):\n",
    "    track_name = None\n",
    "    for msg in track:\n",
    "        if msg.type == 'track_name':\n",
    "            track_name = msg.name\n",
    "            break\n",
    "    print(f\"Track {i}: {track_name}\")\n",
    "\n",
    "# Process tracks with \"(+12 semitones)\" in the name\n",
    "for i, track in enumerate(mid.tracks):\n",
    "    # Find track name\n",
    "    track_name = None\n",
    "    for msg in track:\n",
    "        if msg.type == 'track_name':\n",
    "            track_name = msg.name\n",
    "            break\n",
    "    \n",
    "    # Check if this track should be pitched down\n",
    "    if track_name and \"Bass\" in track_name:\n",
    "        print(f\"Processing track {i}: {track_name}\")\n",
    "\n",
    "        # Pitch down all notes in this track\n",
    "        for msg in track:\n",
    "            if msg.type in ['note_on', 'note_off'] and hasattr(msg, 'note'):\n",
    "                msg.note = max(0, msg.note - 12)  # Pitch down 1 octave\n",
    "        \n",
    "\n",
    "# Save the modified file\n",
    "mid.save('output_test.mid')\n",
    "print(\"File saved as output.mid\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "2",
   "metadata": {},
   "outputs": [],
   "source": [
    "import mido\n",
    "\n",
    "# Load original file and analyze the bass track\n",
    "print(\"=== ORIGINAL FILE ===\")\n",
    "mid_original = mido.MidiFile('la_bamba_richie_valens.mid')\n",
    "track_8 = mid_original.tracks[9]  # E.Bass track\n",
    "\n",
    "original_notes = []\n",
    "for msg in track_8:\n",
    "    if msg.type in ['note_on', 'note_off'] and hasattr(msg, 'note'):\n",
    "        original_notes.append(msg.note)\n",
    "\n",
    "if original_notes:\n",
    "    print(f\"Original E.Bass notes range: {min(original_notes)} to {max(original_notes)}\")\n",
    "    print(f\"Sample notes: {sorted(set(original_notes))[:10]}\")\n",
    "\n",
    "# Load processed file and analyze\n",
    "print(\"\\n=== PROCESSED FILE ===\")\n",
    "mid_processed = mido.MidiFile('output_test.mid')\n",
    "track_8_processed = mid_processed.tracks[8]\n",
    "\n",
    "processed_notes = []\n",
    "for msg in track_8_processed:\n",
    "    if msg.type in ['note_on', 'note_off'] and hasattr(msg, 'note'):\n",
    "        processed_notes.append(msg.note)\n",
    "\n",
    "if processed_notes:\n",
    "    print(f\"Processed E.Bass notes range: {min(processed_notes)} to {max(processed_notes)}\")\n",
    "    print(f\"Sample notes: {sorted(set(processed_notes))[:10]}\")\n",
    "\n",
    "# For reference, typical bass ranges:\n",
    "print(\"\\n=== REFERENCE ===\")\n",
    "print(\"Typical electric bass range: 28-67 (E1 to G4)\")\n",
    "print(\"If GarageBand still shows +12, your notes might still be too high\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "3",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "suno_clean",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.10.15"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
