From f1cba920ae59d213094da55eac056576d0a98fcf Mon Sep 17 00:00:00 2001 From: Fridtjof Petersen <65158001+petersen-f@users.noreply.github.com> Date: Fri, 14 May 2021 20:52:55 +0200 Subject: [PATCH 1/2] Create 2_step(1).ipynb --- Incremental Scripts/2_step(1).ipynb | 322 ++++++++++++++++++++++++++++ 1 file changed, 322 insertions(+) create mode 100644 Incremental Scripts/2_step(1).ipynb 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 From 7ef441691f523888a1cdbad835ac978450f3466b Mon Sep 17 00:00:00 2001 From: Fridtjof Petersen <65158001+petersen-f@users.noreply.github.com> Date: Wed, 19 May 2021 12:16:56 +0200 Subject: [PATCH 2/2] added test --- piano_package/test/__init__.py | 0 .../test/__pycache__/__init__.cpython-36.pyc | Bin 0 -> 160 bytes .../test/__pycache__/__init__.cpython-39.pyc | Bin 0 -> 168 bytes .../__pycache__/test_piano.cpython-36.pyc | Bin 0 -> 3520 bytes .../__pycache__/test_piano.cpython-39.pyc | Bin 0 -> 3151 bytes piano_package/test/test_piano.py | 116 ++++++++++++++++++ 6 files changed, 116 insertions(+) create mode 100644 piano_package/test/__init__.py create mode 100644 piano_package/test/__pycache__/__init__.cpython-36.pyc create mode 100644 piano_package/test/__pycache__/__init__.cpython-39.pyc create mode 100644 piano_package/test/__pycache__/test_piano.cpython-36.pyc create mode 100644 piano_package/test/__pycache__/test_piano.cpython-39.pyc create mode 100644 piano_package/test/test_piano.py 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 0000000000000000000000000000000000000000..a6965f47709a527ab1790e211af6291cf4f88d95 GIT binary patch literal 160 zcmXr!<>hjEvLt~42p)q77+?f49Dul(1xTbY1T$zd`mJOr0tq9CU%ts!F`>n&Ma5t; z#y>CBr6{v3RY6xFw9GN4ATu#9-!H!;wK$+CKPxr41R@e&keHmEn4TH~lqiXbkI&4@ aEQycTE2zB1VUwGmQks)$2ePIZh#3GXMJkd2 literal 0 HcmV?d00001 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 0000000000000000000000000000000000000000..cb17f497ff1548944f03097288b442f1c35eb058 GIT binary patch literal 168 zcmYe~<>g`k0-dKz5!f_dN8xZb}VfZLQe;>($R!FDlBP zig0DgdWYOWlNeAyohbd}x7yci1vJRKP#}Yp!_4zcKZ|mZJ<@QUe9k{tR1*J4spkGB zdzIY*wfxe^Vu##;P7G4|Dkyyo)P5#m>}Mehxfe=52YJG<6fN(gAl&ss6rBEE)XB9! z_5z)J4E5oBItV>~st?9!a1`h#V-$`N)``&vKE`Me>QlN?cQMi@z6%KS6E7Uc5#H1b zJ$K>-Zp^{S;%Btcz?}z3_l9xk3HGO>H>hqVzOg?+`V9Lc>>eNM;G?PbI4YcFpDBmhGwm>Q zn0>B1%fiY_ji{>-ZB}>t%M+JqFrK+kRiiwhr``aaUamR&7(JOFr(-(1ZaBy8WP3Ip zonEeUhqd4^xTCw^Fu9|*;An7%z2InaM{B`xn>*SIjyv4ZX^81owJ10Aa1ciM01f;p zRCAFwn?=O{h4Yzn?12}pxIut$*!^YhPNE{MwKMc4D2Vc*PbwRdE!hA~hB!myjxG?E zp*M;{92iE~nH!FyW!g&)js8u+>m=@hk;0w49U%~_U3U;6c zZRmgnUFd-gU&A->Eqn*x!w;|v4`B~}gr7!xZ?yQMw8i&#`}tVKT2+l}cv`A89V-4- zo0NX5Q;!?FT)QoS!8xc^e-fjm+8rU*;skdkkQ0b#mlM=)39;RTpj593V2`oZ>k`OV zCDcw?4I$R%1mvrd9=63o%XJa8>j`bCPQE=tY$8EjRI9~8%M#j7GY~~=^K*%6bqvNT z>e4azxkS`5nB0b_mczGLvGHRJg?KgRBO2Kkozf;hdCLLooLl@=bLH!p=1^Y$- literal 0 HcmV?d00001 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 0000000000000000000000000000000000000000..fb7d9da21265d320690b2f4fea3179e45340553c GIT binary patch literal 3151 zcmcJRPjA~c7{(>}PZY0Nw%ATFYy)%~0yM!a$!<3cLv72}EiJb6A_QPnk+zlCl1Ir2 z79^+j+V9W~yW|7x%ji1nu&=PwNQvY~FV_hW6Fu*%A74IvVKLm>YiZSZu!gjY+Ap=BjvBCjX^@0%Yqo#g+h z9X0+U?`o$J9p%d)56{V+S!6(3phGP%pdQpJYEXxD*m$c24cH`5F=}uh7dvPI?fkm zMx4ZX94_N5EEybD&M`t!xXF+e&&t$moF?=Cpq^B*MY=@R8mDs{u2vRIQI>p_Th}SR zJSka`P8Q0q2Kk4&J0^E#lOfkGbf`n)oqk@s)9;MC+MGE1tA1C%)h>)%v`Dqg_gBIOoFpHNcE1G#q_B1E2)HAf4Vd{49F`>-jd6@#> ztf;TUd=c!@E&^q?hWAO{-!GzX&tDO4R*vT{66E3d3R%b2tE=JpIu4VxY{i#2y&&CH zDPSE&m*E_pQ(QTKGV^5pbI~rRz$k=3Y}p>&`z9GQ{lG9=H(#Fd4nKJy`~PU4W?5ek z*GLUVFK^nt0ieq|9uZTI$9CB=o!(PL%pOoZ`%S5~d(Wg?j|09@L=KSE2?y9;OSzK@ z(6)P$IAv7ZRzyZsR9{dXDc9!!(u88MLzddHW!1MUY}+P%Ddkoc*s@zgmfBI&k*Gj6 zam3dpyES$gRrY1<@O840J4db3ea|Bx2Bvb`!W?&S@i`~ zcFX4g#VwZFab(qJ*h8*XKVrv20hV1HR^YC~M3G$i=*Z>{MZvNER`Zt5^V_bx)gG^d zi44Nzjw^S7C+d*ZiKv6A0>SH0b)MgL<(8T7I+(~HLS~J`#7?(WSBnNV1Z%PZ0RFjO`mNt%O5cd`s!AU`&A3}RU5~B zPFHoWU$sTIuR7^*jOwH(FseQg7}d&2h3WQHC#RgQIyMz_Rrdv5b<$^;!IqOO{cub7 z8NNGEog8wE>g14DGf?#ruV$cHIVv%jp3tyKhevdv$AW4g2W73;|Mv@BenY