Skip to content

Commit 534b649

Browse files
committed
Updated code
1 parent 3fd10b7 commit 534b649

15 files changed

+108
-34
lines changed

README.md

Lines changed: 20 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ This project is based on my interest in learning to play the piano in my spare t
1515
### PIANO PLAYING BOT
1616

1717
- Program *pianoPlayPi.py* is the program to play with Servo motors.
18-
- Folder *partitures* contains example music sheets to play with previous program.
18+
- Folder *music_sheets* contains example music sheets to play with previous program.
1919
- **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.**
2020

2121
### VIRTUAL PIANO
@@ -34,8 +34,6 @@ This project is based on my interest in learning to play the piano in my spare t
3434
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:<br/>
3535
[![IMAGE ALT TEXT HERE](http://img.youtube.com/vi/NDVJ9Sw2ylI/0.jpg)](https://www.youtube.com/watch?v=NDVJ9Sw2ylI)
3636

37-
38-
3937
## **DOCUMENTATION AND SET UP**
4038

4139
### **SOFTWARE REQUISITES**
@@ -46,7 +44,20 @@ This project is based on my interest in learning to play the piano in my spare t
4644

4745
- Install libs for python 3:
4846

49-
```sudo python3 -m pip install adafruit-circuitpython-busdevice adafruit-circuitpython-servokit adafruit-circuitpython-pca9685 PCA9685-driver RPi.GPIO```
47+
```sudo -H python3 -m pip install adafruit-circuitpython-busdevice adafruit-circuitpython-servokit adafruit-circuitpython-pca9685 PCA9685-driver RPi.GPIO```
48+
49+
### MIDICOMP
50+
51+
- This lib translates a mid file into txt values, that can be interpreted by the programs.
52+
53+
```
54+
git clone https://github.com/markc/midicomp
55+
mkdir midicomp/build
56+
cd midicomp/build
57+
cmake ..
58+
make
59+
sudo make install #(optional)
60+
```
5061

5162
### **HARDWARE REQUISITES**
5263

@@ -88,21 +99,21 @@ If you want to play *ledPi.py* program you need:
8899

89100
- Usage:
90101

91-
```python3 program.py partitures/partiture.txt```
102+
```python3 program.py music_sheets/music_sheet.txt```
92103

93104
or:
94105

95-
```./program.py partitures/partiture.txt```
106+
```./program.py music_sheets/music_sheet.txt```
96107

97-
**NOTE: Replace "program" with the name of the program you want to execute and "partiture" with the name of the song you want to play from the folder "partitures".**
108+
**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".**
98109

99110
- ONLY IN *pianoPlayPi.pay* FOR DUAL HAND EMULATION WITH THREADS:
100111

101-
```python3 pianoPlayPi.py partitures/partiture_hand_1.txt partitures/partiture_hand_2.txt```
112+
```python3 pianoPlayPi.py music_sheets/music_sheet_hand_1.txt music_sheets/music_sheet_hand_2.txt```
102113

103114
or:
104115

105-
```./pianoPlayPi.py partitures/partiture_hand_1.txt partitures/partiture_hand_2.txt```
116+
```./pianoPlayPi.py music_sheets/music_sheet_hand_1.txt music_sheets/music_sheet_hand_2.txt```
106117

107118
**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.**
108119

File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.

pianoPlayPi.py

Lines changed: 25 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@
146146
# usage function #
147147
########################################
148148
def usage(program_name):
149-
print("Usage:\n\tpython3 "+program_name+" partitures/partiture.txt\nor:\n\t./"+program_name+" partitures/partiture.txt");
149+
print("Usage:\n\tpython3 "+program_name+" music_sheets/music_sheet.txt\nor:\n\t./"+program_name+" music_sheets/music_sheet.txt");
150150
#end usage function.
151151

152152
########################################
@@ -171,13 +171,13 @@ def reset():
171171
#end reset function.
172172

173173
########################################
174-
# get_partitures function #
174+
# get_music_sheets function #
175175
########################################
176-
def get_partiture(partiture):
176+
def get_music_sheet(music_sheet):
177177
try:
178-
song_file = open(partiture,"r");
178+
song_file = open(music_sheet,"r");
179179
except:
180-
print("No partiture called partitures/"+str(partiture)+" found.");
180+
print("No music_sheet called music_sheets/"+str(music_sheet)+" found.");
181181
sys.exit(1);
182182
song_content = song_file.read().split("\n");
183183
for notes in song_content:
@@ -191,16 +191,16 @@ def get_partiture(partiture):
191191
song.append(list_notes);
192192
except:
193193
continue;
194-
#end get_partitures function.
194+
#end get_music_sheets function.
195195

196196
########################################
197-
# get_partituresAcomp function #
197+
# get_music_sheetsAcomp function #
198198
########################################
199-
def get_partitureAcomp(partiture):
199+
def get_music_sheetAcomp(music_sheet):
200200
try:
201-
song_file = open(partiture,"r");
201+
song_file = open(music_sheet,"r");
202202
except:
203-
print("No partiture called partitures/"+str(partiture)+" found.");
203+
print("No music_sheet called music_sheets/"+str(music_sheet)+" found.");
204204
sys.exit(1);
205205
song_content = song_file.read().split("\n");
206206
for notes in song_content:
@@ -214,10 +214,10 @@ def get_partitureAcomp(partiture):
214214
song2.append(list_notes);
215215
except:
216216
continue;
217-
#end get_partituresAcomp function.
217+
#end get_music_sheetsAcomp function.
218218

219219
#########################################
220-
# Read arguments and get partitures #
220+
# Read arguments and get music_sheets #
221221
#########################################
222222

223223
# Get program name.
@@ -226,32 +226,32 @@ def get_partitureAcomp(partiture):
226226
# Get number of arguments.
227227
num_args = len(sys.argv);
228228

229-
# Exit program if no partiture are selected.
229+
# Exit program if no music_sheet are selected.
230230
if num_args <= 1:
231-
print("No partiture selected");
231+
print("No music_sheet selected");
232232
usage(program_name);
233233
sys.exit(1);
234234

235-
# Get partiture name.
236-
partiture = sys.argv[1];
235+
# Get music_sheet name.
236+
music_sheet = sys.argv[1];
237237

238-
# Get second partiture name if is available.
238+
# Get second music_sheet name if is available.
239239
if num_args == 3:
240-
partiture2 = sys.argv[2];
240+
music_sheet2 = sys.argv[2];
241241

242-
# If partiture name is reset, reset motors and end program.
243-
if partiture == "reset":
242+
# If music_sheet name is reset, reset motors and end program.
243+
if music_sheet == "reset":
244244
reset();
245245
print("Reset notes");
246246
sys.exit(1);
247247

248-
# Get the partiture.
249-
get_partiture(partiture);
248+
# Get the music_sheet.
249+
get_music_sheet(music_sheet);
250250

251-
# Get the second partiture if is available.
251+
# Get the second music_sheet if is available.
252252
if num_args == 3:
253-
get_partitureAcomp(partiture2);
254-
#end Read arguments and get partitures.
253+
get_music_sheetAcomp(music_sheet2);
254+
#end Read arguments and get music_sheets.
255255

256256
#########################################
257257
# Play Song Threaded #

reponame.txt

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
88 88
2+
88 ""
3+
88
4+
88 ,adPPYba, ,adPPYYba, 8b,dPPYba, 8b,dPPYba, 88 8b,dPPYba, ,adPPYb,d8
5+
88 a8P_____88 "" `Y8 88P' "Y8 88P' `"8a 88 88P' `"8a a8" `Y88
6+
88 8PP""""""" ,adPPPPP88 88 88 88 88 88 88 8b 88
7+
88 "8b, ,aa 88, ,88 88 88 88 88 88 88 "8a, ,d88
8+
88888888888 `"Ybbd8"' `"8bbdP"Y8 88 88 88 88 88 88 `"YbbdP"Y8
9+
aa, ,88
10+
"Y8bbdP"
11+
12+
88
13+
,d 88
14+
88 88
15+
MM88MMM ,adPPYba, 8b,dPPYba, 88 ,adPPYYba, 8b d8
16+
88 a8" "8a 88P' "8a 88 "" `Y8 `8b d8'
17+
88 8b d8 88 d8 88 ,adPPPPP88 `8b d8'
18+
88, "8a, ,a8" 88b, ,a8" 88 88, ,88 `8b,d8'
19+
"Y888 `"YbbdP"' 88`YbbdP"' 88 `"8bbdP"Y8 Y88'
20+
88 d8'
21+
88 d8'
22+
23+
88 88888888ba 88
24+
,d 88 88 "8b ""
25+
88 88 88 ,8P
26+
MM88MMM 88,dPPYba, ,adPPYba, 88aaaaaa8P' 88 ,adPPYYba, 8b,dPPYba, ,adPPYba,
27+
88 88P' "8a a8P_____88 88""""""' 88 "" `Y8 88P' `"8a a8" "8a
28+
88 88 88 8PP""""""" 88 88 ,adPPPPP88 88 88 8b d8
29+
88, 88 88 "8b, ,aa 88 88 88, ,88 88 88 "8a, ,a8"
30+
"Y888 88 88 `"Ybbd8"' 88 88 `"8bbdP"Y8 88 88 `"YbbdP"'
31+
32+
33+
34+
88 88
35+
"" ,d 88
36+
88 88
37+
8b db d8 88 MM88MMM 88,dPPYba, ,adPPYYba,
38+
`8b d88b d8' 88 88 88P' "8a "" `Y8
39+
`8b d8'`8b d8' 88 88 88 88 ,adPPPPP88
40+
`8bd8' `8bd8' 88 88, 88 88 88, ,88
41+
YP YP 88 "Y888 88 88 `"8bbdP"Y8
42+
43+
44+
45+
88888888ba 88
46+
88 "8b ,d 88
47+
88 ,8P 88 88
48+
88aaaaaa8P' 8b d8 MM88MMM 88,dPPYba, ,adPPYba, 8b,dPPYba,
49+
88""""""' `8b d8' 88 88P' "8a a8" "8a 88P' `"8a
50+
88 `8b d8' 88 88 88 8b d8 88 88
51+
88 `8b,d8' 88, 88 88 "8a, ,a8" 88 88
52+
88 Y88' "Y888 88 88 `"YbbdP"' 88 88
53+
d8'
54+
d8'
55+
56+
88888888ba
57+
88 "8b ,d
58+
88 ,8P 88
59+
88aaaaaa8P' ,adPPYba, MM88MMM
60+
88""""""8b, a8" "8a 88
61+
88 `8b 8b d8 88
62+
88 a8P "8a, ,a8" 88,
63+
88888888P" `"YbbdP"' "Y888

0 commit comments

Comments
 (0)