GithubHelp home page GithubHelp logo

ibanknatoprad / learning-to-play-the-piano-with-a-python-bot Goto Github PK

View Code? Open in Web Editor NEW

This project forked from mlurbe97/learning-to-play-the-piano-with-a-python-bot

0.0 0.0 0.0 15.92 MB

https://github.com/barionleg/P8IAnnoAI Thisproject is based on my interest in learning to play the piano in my spare time. As everyone knows, learning to play an instrument is difficult and requires a lot of time and dedication. In my case, I am a computer engineer and for lack of time I decided to start a project to start playing the piano using a

Home Page: https://rpiai.com/raspberrypi/music/

License: GNU General Public License v3.0

Python 100.00%

learning-to-play-the-piano-with-a-python-bot's Introduction

Learning to play the Piano with a Python Bot

https://ibanknatoprad.github.io/Learning-to-play-the-Piano-with-a-Python-Bot/doc/images/froide_232.gif

image

AUTHOR

ABSTRACT

This project is based on my interest in learning to play the piano in my spare time. As everyone knows, learning to play an instrument is difficult and requires a lot of time and dedication. In my case, I am a computer engineer and for lack of time I decided to start a project to learn playing the piano using a software teacher implemented with LED lights on each piano key. My interest in this software has increased throughout the development and has ended up becoming a bot that plays the piano.

PROGRAMS AVAILABLE ON THIS PROJECT

PIANO PLAYING BOT

  • Program pianoPlayPi.py is the program to play with Servo motors.
  • Folder music_sheets contains example music sheets to play with previous program.
  • Actual version of the code supports only multiple notes with same tempo in the same thread. Multi-thread is supported for simulate two virtual hands with their own music sheet. Additionally, the actual implementation corresponds to two notes for each servo motor because the actual prototype doesn't have enough space between piano keys.

VIRTUAL PIANO

  • Program buzzerPi.py is a program to play songs with a passive buzzer using the frequencies of piano notes. To play multiple notes at the same time you need as many as notes are wanted to play at the same time.
  • Actual version of the code only supports one note each time.

LEARNING TO PLAY THE PIANO

  • Program ledPi.py is a program to learn to play the piano using a servo controller for switching LEDs, each LED corresponds to one note, you need as many LEDs as notes are wanted to play.
  • This program was the first implementation and was designed to learn to play the piano by placing a LED on top of each key to play it every time a LED was turned on.
  • Actual version of the code supports multiple notes with same tempo in the same thread. No multi-thread support yet.

GOOGLE ASSISTANT SUPPORT

The bot can be executed from google assistant, creating commands from a google account and linking the controller device as a home IoT device to launch orders such as: "OK Google, play Bethoven's Fifth Symphony on the piano". Example:
IMAGE ALT TEXT HERE

DOCUMENTATION AND SET UP

SOFTWARE REQUISITES

  • Install python3 for develop (Ubuntu/Debian based systems):

    sudo apt install python3-dev python3-pip python3-tk build-essential libi2c-dev i2c-tools libffi-dev

  • Install libs for python 3:

    sudo -H python3 -m pip install adafruit-circuitpython-busdevice adafruit-circuitpython-servokit adafruit-circuitpython-pca9685 PCA9685-driver RPi.GPIO

MIDICOMP

  • This lib translates a mid file into txt values, that can be interpreted by the programs.
git clone https://github.com/markc/midicomp
mkdir midicomp/build
cd midicomp/build
cmake ..
make
sudo make install #(optional)

HARDWARE REQUISITES

  • Raspberry Pi (any model) or other similar board with support of GPIO ports and python3. Buy on amazon
  • Cables to connect anything with the GPIO ports. Buy on amazon

If you want to play pianoPlayPi.py program you need:

  • Servo motors as many as notes you want to play. Buy on amazon
  • PCA9685 16 Channel PWM Servo Driver, more than one if you want to support more than 16 servos at the same time. Buy on amazon

If you want to play buzzerPi.py program you need:

  • As many passive Buzzers as notes you want to play at the same time. Buy on amazon

If you want to play ledPi.py program you need:

SET UP HARDWARE CONNECTIONS

  • buzzerPi.py: The following image shows how to connect one buzzer to the Raspberry Pi. If you have more than one, you have to connect each one to one of the available GPIO ports of your board and enable it in the code.

  • ledPi.py: The following image shows how to connect one LED to the channel 0 of the controller. If you have more than one, you have to connect each one to each controller channel.

  • pianoPlayPi.py: The following image shows how to connect one servo motor to the channel 0 of the controller. If you have more than one, you have to connect each one to each controller channel.

HOW TO USE

  • Set execution permissions:

    chmod +x program.py

  • Usage:

    python3 program.py music_sheets/music_sheet.txt

    or:

    ./program.py music_sheets/music_sheet.txt

NOTE: Replace "program" with the name of the program you want to execute and "music_sheet" with the name of the song you want to play from the folder "music_sheets".

  • ONLY IN pianoPlayPi.pay FOR DUAL HAND EMULATION WITH THREADS:

    python3 pianoPlayPi.py music_sheets/music_sheet_hand_1.txt music_sheets/music_sheet_hand_2.txt

    or:

    ./pianoPlayPi.py music_sheets/music_sheet_hand_1.txt music_sheets/music_sheet_hand_2.txt

NOTE: Music sheets for dual hand simulated piano, as in real life, shouldn't contains the same notes (or piano keys) at the same time, there is no reason to play with two hands the same notes.

MUSIC SHEETS

I'm trying to find a lib or website that provides music sheets in plain text for bots or in more complex way, develop a machine learning algorithm to recognise notes in pdf or image based music sheets. The idea is to give the piano bot the capacity of play any kind of song without having to rewrite the music sheet specifically for him.

STYLE

Music Sheets for the piano are composed by a file of tuples (note,tempo), where "note" corresponds to the music note to be played and "tempo" the type of the note represented in the following table:

Music symbols Code Style
𝅝 𝅝 dr
𝅝 r
𝅗𝅥 . b+
𝅗𝅥 𝅘𝅥𝅮 b-
𝅗𝅥 b
𝅘𝅥 . n+
𝅘𝅥 𝅘𝅥𝅮 n-
𝅘𝅥 n
𝅘𝅥𝅮 c
𝅘𝅥𝅯 sc
𝅘𝅥𝅱 ssc
𝅘𝅥𝅲 sssc
*Write "b" after the note. Example: "mib" corresponds to note "mi flat".*
*Translate it to flats.*
Silence *Same as the type of the note tempo. Example: "(sil,n)" corresponds to silence with the tempo of quarter note( 𝅘𝅥 ).*

In addition, you can play two or more notes at the same time if they have the same tempo in the same thread, separating them with a tab value key (\t). The file will be like this:

  • For one note:

    do,n
    re,n
    mi,n
    fa,n
    sol,n
    la,n
    si,n
    do2,n
    
    
  • For two (or more) notes with same tempo:

    do,n    do2,n
    re,n    si,n
    mi,n    la,n
    fa,n    sol,n
    sol,n   fa,n
    la,n    mi,n
    si,n    re,n
    do2,n   do,n
    
    

NOTE: Remember that there are no spaces between notes, they are tab key values (\t).

PIANO FREQUENCIES

Key Number Franco-Belgian notation Anglo-Saxon notation Frecuency
88 do7 C8 4186,01
87 si6 B7 3951,07
86 la6/si6 A7/B7 3729,31
85 la6 A7 3520,00
84 sol6/la6 G7/A7 3322,44
83 sol6 G7 3135,96
82 fa6/sol6 F7/G7 2959,96
81 fa6 F7 2793,83
80 mi6 E7 2637,02
79 re6/mi6 D7/E7 2489,02
78 re6 D7 2349,32
77 do6/re6 C7/D7 2217,46
76 do6 C7 2093,00
75 si5 B6 1975,53
74 la5/si5 A6/B6 1864,66
73 la5 A6 1760,00
72 sol5/la5 G6/A6 1661,22
71 sol5 G6 1567,98
70 fa5/sol5 F6/G6 1479,98
69 fa5 F6 1396,91
68 mi5 E6 1318,51
67 re5/mi5 D6/E6 1244,51
66 re5 D6 1174,66
65 do5/re5 C6/D6 1108,73
64 do5 C6 1046,50
63 si4 B5 987,767
62 la4/si4 A5/B5 932,328
61 la4 A5 880,000
60 sol4/la4 G5/A5 830,609
59 sol4 G5 783,991
58 fa4/sol4 F5/G5 739,989
57 fa4 F5 698,456
56 mi4 E5 659,255
55 re4/mi4 D5/E5 622,254
54 re4 D5 587,330
53 do4/re4 C5/D5 554,365
52 do4 C5 523,251
51 si3 B4 493,883
50 la3/si3 A4/B4 466,164
49 la3 A4 440,000
48 sol3/la3 G4/A4 415,305
47 sol3 G4 391,995
46 fa3/sol3 F4/G4 369,994
45 fa3 F4 349,228
44 mi3 E4 329,628
43 re3/mi3 D4/E4 311,127
42 re3 D4 293,665
41 do3/re3 C4/D4 277,183
40 do3 C4 (central do) 261,626
39 si2 B3 246,942
38 la2/si2 A3/B3 233,082
37 la2 A3 220,000
36 sol2/la2 G3/A3 207,652
35 sol2 G3 195,998
34 fa2/sol2 F3/G3 184,997
33 fa2 F3 174,614
32 mi2 E3 164,814
31 re2/mi2 D3/E3 155,563
30 re2 D3 146,832
29 do2/re2 C3/D3 138,591
28 do2 C3 130,813
27 si1 B2 123,471
26 la1/si1 A2/B2 116,541
25 la1 A2 110,000
24 sol1/la1 G2/A2 103,826
23 sol1 G2 97,9989
22 fa1/sol 1 F2/G2 92,4986
21 fa1 F2 87,3071
20 mi1 E2 82,4069
19 re1/mi1 D2/E2 77,7817
18 re1 D2 73,4162
17 do1/re1 C2/D2 69,2957
16 do1 C2 65,4064
15 si0 B1 61,7354
14 la0/si0 A1/B1 58,2705
13 la0 A1 55,0000
12 sol0/la0 G1/A1 51,9130
11 sol0 G1 48,9995
10 fa0/sol0 F1/G1 46,2493
9 fa0 F1 43,6536
8 mi0 E1 41,2035
7 re0/mi0 D1/E1 38,8909
6 re0 D1 36,7081
5 do0/re0 C1/D1 34,6479
4 do0 C1 32,7032
3 si-1 B0 30,8677
2 la-1/si-1 A0/B0 29,1353
1 la-1 A0 27,5000

learning-to-play-the-piano-with-a-python-bot's People

Contributors

barionleg avatar mlurbe97 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.