diff --git a/Incremental Scripts/2_step(1).ipynb b/Incremental Scripts/2_step(1).ipynb new file mode 100644 index 0000000..61687a2 --- /dev/null +++ b/Incremental Scripts/2_step(1).ipynb @@ -0,0 +1,322 @@ +{ + "metadata": { + "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.6.6" + }, + "orig_nbformat": 2, + "kernelspec": { + "name": "python366jvsc74a57bd04fe30445ef53ac03b693547ad1486ea9656bbc56cc52e4778be38c3ffeb725e0", + "display_name": "Python 3.6.6 64-bit" + }, + "metadata": { + "interpreter": { + "hash": "4fe30445ef53ac03b693547ad1486ea9656bbc56cc52e4778be38c3ffeb725e0" + } + } + }, + "nbformat": 4, + "nbformat_minor": 2, + "cells": [ + { + "source": [ + "This thingy will document stuff" + ], + "cell_type": "markdown", + "metadata": {} + }, + { + "cell_type": "code", + "execution_count": 23, + "metadata": {}, + "outputs": [ + { + "output_type": "execute_result", + "data": { + "text/plain": [ + "8" + ] + }, + "metadata": {}, + "execution_count": 23 + } + ], + "source": [ + "import pandas as pd\n", + "\n", + "data = {'key_number' :list(range(1,9)) }\n", + "\n", + "\n", + "key_bindings = pd.DataFrame(data)\n", + "key_bindings\n", + "len(key_bindings)" + ] + }, + { + "cell_type": "code", + "execution_count": 1, + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "name": "stdout", + "text": [ + "pygame 1.9.6\nHello from the pygame community. https://www.pygame.org/contribute.html\n" + ] + } + ], + "source": [ + "from pygame import midi\n", + "\n", + "# initalise reading midi input\n", + "\n", + "midi.init()\n", + "\n", + "input = midi.Input(1)" + ] + }, + { + "cell_type": "code", + "execution_count": 2, + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "name": "stdout", + "text": [ + "Please press key number 1\n", + "Please press key number 2\n", + "Please press key number 2\n", + "Please press key number 3\n", + "Please press key number 3\n", + "Please press key number 4\n", + "Please press key number 4\n", + "Please press key number 5\n", + "Please press key number 5\n", + "Please press key number 6\n", + "Please press key number 6\n", + "Please press key number 7\n", + "Please press key number 7\n", + "Please press key number 8\n", + "Please press key number 8\n", + "Thanks\n" + ] + } + ], + "source": [ + "key_id = list()\n", + "while True:\n", + " if input.poll():\n", + " print(\"Please press key number\",len(key_id)+1)\n", + " key = input.read(100)\n", + " key = key[0][0]\n", + " \n", + " key_num, sensitivity = key[1],key[2]\n", + "\n", + " if sensitivity !=0:\n", + " key_id.append(key_num)\n", + " \n", + " if len(key_id) ==8:\n", + " print(\"Thanks\")\n", + " break\n", + "\n" + ] + }, + { + "cell_type": "code", + "execution_count": 3, + "metadata": {}, + "outputs": [ + { + "output_type": "execute_result", + "data": { + "text/plain": [ + "[112, 113, 114, 115, 116, 117, 118, 119]" + ] + }, + "metadata": {}, + "execution_count": 3 + } + ], + "source": [ + "key_id" + ] + }, + { + "source": [ + "Nice now we need to add this column to the df we have created and print it" + ], + "cell_type": "markdown", + "metadata": {} + }, + { + "cell_type": "code", + "execution_count": 14, + "metadata": {}, + "outputs": [], + "source": [ + "key_bindings.loc[:,\"key_id\"] = key_id\n", + "\n", + "key_bindings.to_csv(\"key_bindings.csv\")" + ] + }, + { + "source": [ + "# Next step" + ], + "cell_type": "markdown", + "metadata": {} + }, + { + "cell_type": "code", + "execution_count": 32, + "metadata": {}, + "outputs": [], + "source": [ + "import os\n", + "\n", + "key_bindings = pd.read_csv('./key_bindings.csv')\n", + "\n", + "note_files = os.listdir('./Notes')\n", + "\n", + "key_bindings.loc[:,\"note_files\"] = note_files\n", + "\n", + "path = key_bindings.iloc[0,3]\n", + "\n", + "\n", + "from PIL import Image\n", + "\n", + "img = Image.open(\"./Notes/\" + path)\n", + "\n", + "img.show()\n" + ] + }, + { + "cell_type": "code", + "execution_count": 1, + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "name": "stdout", + "text": [ + "pygame 1.9.6\n", + "Hello from the pygame community. https://www.pygame.org/contribute.html\n", + "Please press key number 1\n" + ] + }, + { + "output_type": "error", + "ename": "IndexError", + "evalue": "list index out of range", + "traceback": [ + "\u001b[1;31m---------------------------------------------------------------------------\u001b[0m", + "\u001b[1;31mIndexError\u001b[0m Traceback (most recent call last)", + "\u001b[1;32m\u001b[0m in \u001b[0;36m\u001b[1;34m\u001b[0m\n\u001b[0;32m 11\u001b[0m \u001b[1;32mif\u001b[0m \u001b[0minput\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mpoll\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;33m)\u001b[0m \u001b[1;32mand\u001b[0m \u001b[0minput\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mread\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;36m100\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m[\u001b[0m\u001b[1;36m0\u001b[0m\u001b[1;33m]\u001b[0m\u001b[1;33m[\u001b[0m\u001b[1;36m0\u001b[0m\u001b[1;33m]\u001b[0m\u001b[1;33m[\u001b[0m\u001b[1;36m2\u001b[0m\u001b[1;33m]\u001b[0m \u001b[1;33m!=\u001b[0m \u001b[1;36m0\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 12\u001b[0m \u001b[0mprint\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;34m\"Please press key number\"\u001b[0m\u001b[1;33m,\u001b[0m\u001b[0mlen\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mkey_id\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m+\u001b[0m\u001b[1;36m1\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m---> 13\u001b[1;33m \u001b[0mkey\u001b[0m \u001b[1;33m=\u001b[0m \u001b[0minput\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mread\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;36m100\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m[\u001b[0m\u001b[1;36m0\u001b[0m\u001b[1;33m]\u001b[0m\u001b[1;33m[\u001b[0m\u001b[1;36m0\u001b[0m\u001b[1;33m]\u001b[0m\u001b[1;33m[\u001b[0m\u001b[1;36m2\u001b[0m\u001b[1;33m]\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m\u001b[0;32m 14\u001b[0m \u001b[1;31m#key = key\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 15\u001b[0m \u001b[0mprint\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mkey\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n", + "\u001b[1;31mIndexError\u001b[0m: list index out of range" + ] + } + ], + "source": [ + "from pygame import midi\n", + "\n", + "# initalise reading midi input\n", + "\n", + "midi.init()\n", + "\n", + "input = midi.Input(1)\n", + "\n", + "key_id = list()\n", + "while True:\n", + " print(\"Please press key number\",len(key_id)+1)\n", + " if input.poll():\n", + " \n", + " print(\"Please press key number\",len(key_id)+1)\n", + " key = input.read(100)[0][0]\n", + " \n", + " #key_num, sensitivity = key[1],key[2]\n", + "\n", + " #if sensitivity !=0:\n", + " # print(\"Hi\")" + ] + }, + { + "cell_type": "code", + "execution_count": 1, + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "name": "stdout", + "text": [ + "pygame 1.9.6\n", + "Hello from the pygame community. https://www.pygame.org/contribute.html\n", + "112\n" + ] + } + ], + "source": [ + "# This script will take the csv we produced last time and show a picture when a key is pressed down\n", + "\n", + "from PIL import Image\n", + "import pandas as pd\n", + "key_bindings = pd.read_csv('./key_bindings.csv')\n", + "\n", + "\n", + "from pygame import midi\n", + "\n", + "midi.init()\n", + "\n", + "input = midi.Input(1)\n", + "\n", + "\n", + "while True:\n", + " if input.poll():\n", + " midi_key = input.read(100)[0][0]\n", + " key_id, key_sensitivity = midi_key[1], midi_key[2]\n", + "\n", + " if key_sensitivity != 0:\n", + " print(key_id)\n", + " path = key_bindings.loc[key_bindings.loc[:,\"key_id\"] == key_id,\"note_files\"].item()\n", + " break\n" + ] + }, + { + "cell_type": "code", + "execution_count": 10, + "metadata": {}, + "outputs": [ + { + "output_type": "execute_result", + "data": { + "text/plain": [ + "'1_Treble_C4_Natural.png'" + ] + }, + "metadata": {}, + "execution_count": 10 + } + ], + "source": [ + "key_bindings.loc[key_bindings.loc[:,\"key_id\"] == key_id,\"note_files\"]\n", + "\n", + "key_bindings.loc[key_bindings[\"key_id\"]==key_id, \"note_files\"].item()" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [] + } + ] +} \ No newline at end of file diff --git a/piano_package/test/__init__.py b/piano_package/test/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/piano_package/test/__pycache__/__init__.cpython-36.pyc b/piano_package/test/__pycache__/__init__.cpython-36.pyc new file mode 100644 index 0000000..a6965f4 Binary files /dev/null and b/piano_package/test/__pycache__/__init__.cpython-36.pyc differ diff --git a/piano_package/test/__pycache__/__init__.cpython-39.pyc b/piano_package/test/__pycache__/__init__.cpython-39.pyc new file mode 100644 index 0000000..cb17f49 Binary files /dev/null and b/piano_package/test/__pycache__/__init__.cpython-39.pyc differ diff --git a/piano_package/test/__pycache__/test_piano.cpython-36.pyc b/piano_package/test/__pycache__/test_piano.cpython-36.pyc new file mode 100644 index 0000000..9b72ae8 Binary files /dev/null and b/piano_package/test/__pycache__/test_piano.cpython-36.pyc differ diff --git a/piano_package/test/__pycache__/test_piano.cpython-39.pyc b/piano_package/test/__pycache__/test_piano.cpython-39.pyc new file mode 100644 index 0000000..fb7d9da Binary files /dev/null and b/piano_package/test/__pycache__/test_piano.cpython-39.pyc differ diff --git a/piano_package/test/test_piano.py b/piano_package/test/test_piano.py new file mode 100644 index 0000000..6d9c532 --- /dev/null +++ b/piano_package/test/test_piano.py @@ -0,0 +1,116 @@ +import unittest + + +import piano_package as pp + + +class TestNotes(unittest.TestCase): + """ + This test function checks whether the correct notes are loaded with the initialisation function + Because if the wrong notes are loaded, the whole programm doesn't work. + """ + + def test_read_launchpad(self): + device, config_file_df, path = pp.setup_midi(device="launchpad") + + test_list = [ + "1_Treble_C4_Natural.png", + "2_Treble_D4_Natural.png", + "3_Treble_E4_Natural.png", + "4_Treble_F4_Natural.png", + "5_Treble_G4_Natural.png", + "6_Treble_A4_Natural.png", + "7_Treble_B4_Natural.png", + "8_Treble_C5_Natural.png", + ] + self.assertEqual(first=config_file_df.note_files.tolist(), second=test_list) + + def test_read_piano(self): + device, config_file_df, path = pp.setup_midi(device="piano1") + test_list = [ + "16_Note-Bass-C2.png", + "17_Note-Bass-C2s.png", + "17_Note-Bass-D2b.png", + "18_Note-Bass-D2.png", + "19_Note-Bass-D2s.png", + "19_Note-Bass-E2b.png", + "20_Note-Bass-E2.png", + "21_Note-Bass-F2.png", + "22_Note-Bass-F2s.png", + "22_Note-Bass-G2b.png", + "23_Note-Bass-G2.png", + "24_Note-Bass-A2b.png", + "24_Note-Bass-G2s.png", + "25_Note-Bass-A2.png", + "26_Note-Bass-A2s.png", + "26_Note-Bass-B2b.png", + "27_Note-Bass-B2.png", + "28_Note-Bass-C3.png", + "29_Note-Bass-C3s.png", + "29_Note-Bass-D3b.png", + "30_Note-Bass-D3.png", + "31_Note-Bass-D3s.png", + "31_Note-Bass-E3b.png", + "32_Note-Bass-E3.png", + "33_Note-Bass-F3.png", + "34_Note-Bass-F3s.png", + "34_Note-Bass-G3b.png", + "35_Note-Bass-G3.png", + "36_Note-Bass-A3b.png", + "36_Note-Bass-G3s.png", + "36_Note-Treble-A3b.png", + "37_Note-Bass-A3.png", + "37_Note-Treble-A3.png", + "38_Note-Bass-A3s.png", + "38_Note-Bass-B3b.png", + "38_Note-Treble-A3s.png", + "38_Note-Treble-B3b.png", + "39_Note-Bass-B3.png", + "39_Note-Treble-B3.png", + "40_Note-Bass-C4.png", + "40_Note-Treble-C4.png", + "41_Note-Bass-C4s.png", + "41_Note-Bass-D4b.png", + "41_Note-Treble-C4s.png", + "41_Note-Treble-D4b.png", + "42_Note-Bass-D4.png", + "42_Note-Treble-D4.png", + "43_Note-Bass-D4s.png", + "43_Note-Bass-E4b.png", + "43_Note-Treble-D4s.png", + "43_Note-Treble-E4b.png", + "44_Note-Bass-E4.png", + "44_Note-Treble-E4.png", + "45_Note-Treble-F4.png", + "46_Note-Treble-F4s.png", + "46_Note-Treble-G4b.png", + "47_Note-Treble-G4.png", + "48_Note-Treble-A4b.png", + "48_Note-Treble-G4s.png", + "49_Note-Treble-A4.png", + "50_Note-Treble-A4s.png", + "50_Note-Treble-B4b.png", + "51_Note-Treble-B4.png", + "52_Note-Treble-C5.png", + "53_Note-Treble-C5s.png", + "53_Note-Treble-D5b.png", + "54_Note-Treble-D5.png", + "55_Note-Treble-D5s.png", + "55_Note-Treble-E5b.png", + "56_Note-Treble-E5.png", + "57_Note-Treble-F5.png", + "58_Note-Treble-F5s.png", + "58_Note-Treble-G5b.png", + "59_Note-Treble-G5.png", + "60_Note-Treble-A5b.png", + "60_Note-Treble-G5s.png", + "61_Note-Treble-A5.png", + "62_Note-Treble-A5s.png", + "62_Note-Treble-B5b.png", + "63_Note-Treble-B5.png", + ] + self.assertEqual(first=config_file_df.note_files.tolist(), second=test_list) + + +if __name__ == "__main__": + unittest.main()