{ "cells": [ { "cell_type": "markdown", "metadata": { "gradient": { "editing": false, "id": "ac5a4cf0-d9d2-47b5-9633-b53f8d99a4d2", "kernelId": "" }, "id": "SiTIpPjArIyr" }, "source": [ "# Los Angeles MIDI Dataset CHORDS DATA Decoder (ver. 1.0)\n", "\n", "***\n", "\n", "Powered by tegridy-tools: https://github.com/asigalov61/tegridy-tools\n", "\n", "***\n", "\n", "#### Project Los Angeles\n", "\n", "#### Tegridy Code 2024\n", "\n", "***" ] }, { "cell_type": "markdown", "metadata": { "gradient": { "editing": false, "id": "fa0a611c-1803-42ae-bdf6-a49b5a4e781b", "kernelId": "" }, "id": "gOd93yV0sGd2" }, "source": [ "# (SETUP ENVIRONMENT)" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "cellView": "form", "gradient": { "editing": false, "id": "a1a45a91-d909-4fd4-b67a-5e16b971d179", "kernelId": "" }, "id": "fX12Yquyuihc" }, "outputs": [], "source": [ "#@title Install all dependencies (run only once per session)\n", "\n", "!git clone https://github.com/asigalov61/tegridy-tools\n", "!pip install tqdm" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "cellView": "form", "gradient": { "editing": false, "id": "b8207b76-9514-4c07-95db-95a4742e52c5", "kernelId": "" }, "id": "z7n9vnKmug1J" }, "outputs": [], "source": [ "#@title Import all needed modules\n", "\n", "print('Loading core modules... Please wait...')\n", "import os\n", "\n", "import math\n", "import statistics\n", "import random\n", "from collections import Counter\n", "import shutil\n", "import hashlib\n", "from tqdm import tqdm\n", "\n", "print('Creating IO dirs...')\n", "\n", "if not os.path.exists('/content/CHORDS_DATA'):\n", " os.makedirs('/content/CHORDS_DATA')\n", "\n", "print('Loading TMIDIX module...')\n", "os.chdir('/content/tegridy-tools/tegridy-tools')\n", "\n", "import TMIDIX\n", "\n", "print('Done!')\n", "\n", "os.chdir('/content/')\n", "print('Enjoy! :)')" ] }, { "cell_type": "markdown", "source": [ "# (Load sample LAMDa CHORDS DATA file)" ], "metadata": { "id": "ijCbwyQ0JFhN" } }, { "cell_type": "code", "source": [ "chords_data = TMIDIX.Tegridy_Any_Pickle_File_Reader('/content/CHORDS_DATA/LAMDa_CHORDS_DATA_2500')\n", "print('Done!')" ], "metadata": { "id": "o__b6ZQMHUiW" }, "execution_count": null, "outputs": [] }, { "cell_type": "markdown", "source": [ "# (Decode to MIDI)" ], "metadata": { "id": "sd5-yZM0JNK8" } }, { "cell_type": "code", "source": [ "data = random.choice(chords_data)\n", "\n", "file_name = data[0]\n", "song = data[1]\n", "\n", "song_f = []\n", "\n", "time = 0\n", "dur = 0\n", "vel = 90\n", "pitch = 0\n", "channel = 0\n", "\n", "patches = [-1] * 16\n", "\n", "channels = [0] * 16\n", "channels[9] = 1\n", "\n", "for ss in song:\n", "\n", " time += ss[0] * 16\n", "\n", " for i in range(0, len(ss[1:]), 4):\n", "\n", " s = ss[1:][i:i+4]\n", "\n", " dur = s[0] * 16\n", "\n", " patch = s[1]\n", "\n", " if patch < 128:\n", " if patch not in patches:\n", " if 0 in channels:\n", " cha = channels.index(0)\n", " channels[cha] = 1\n", " else:\n", " cha = 15\n", " patches[cha] = patch\n", " channel = patches.index(patch)\n", " else:\n", " channel = patches.index(patch)\n", "\n", " if patch == 128:\n", " channel = 9\n", "\n", " pitch = s[2]\n", "\n", " vel = s[3]\n", "\n", " song_f.append(['note', time, dur, channel, pitch, vel, patch ])\n", "\n", "patches = [0 if x==-1 else x for x in patches]\n", "\n", "\n", "detailed_stats = TMIDIX.Tegridy_ms_SONG_to_MIDI_Converter(song_f,\n", " output_signature = file_name+'.mid',\n", " output_file_name = '/content/Los-Angeles-MIDI-Dataset-Composition',\n", " track_name='Project Los Angeles',\n", " list_of_MIDI_patches=patches\n", " )" ], "metadata": { "id": "pG1-n4qhHt7d" }, "execution_count": null, "outputs": [] }, { "cell_type": "markdown", "metadata": { "id": "YzCMd94Tu_gz" }, "source": [ "# Congrats! You did it! :)" ] } ], "metadata": { "colab": { "machine_shape": "hm", "private_outputs": true, "provenance": [] }, "gpuClass": "standard", "kernelspec": { "display_name": "Python 3 (ipykernel)", "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.9.7" } }, "nbformat": 4, "nbformat_minor": 0 }