-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathnote.py
More file actions
122 lines (95 loc) · 3.82 KB
/
note.py
File metadata and controls
122 lines (95 loc) · 3.82 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
#!/usr/bin/python3
# -*- coding: UTF-8 -*-
# Pas d'accent pour mettre toute les chances de mon cote à la compil
########################################################################
# This file is part of wikikircandroid3.
#
# wikikircandroid3 is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# wikikircandroid3 is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
########################################################################
note_dict = { '0':0, '1':35, '2':2, '3':34, '4':4, '5':33,
'a':6, 'b':7, 'c':8, 'd':9, 'e':10, 'f':11,
'g':12, 'h':13, 'i':14, 'j':15, 'k':16, 'l':17,
'm':18, 'n':19, 'o':20, 'p':21, 'q':22, 'r':23,
's':24, 't':25, 'u':26, 'v':27, 'w':28, 'x':29,
'y':30, 'z':31, '6':32, '7':1, '8':3, '9':5
}
# modifie le rythm des notes
correction = 1.4
class Note:
"""
Un objet par ligne:
"""
def __init__(self, line):
self.line = line
self.length = len(line)
self.get_every()
self.progress = 0
self.note = None
self.volume = 0
def get_every(self):
"""Une note est jouee tous les every update_clock=0.03s
Plus la ligne est longue, plus je joue vite
TODO calcul fonction de update_clock ?
"""
global correction
self.every = 6
if self.length < 30:
self.every = 9
if 31 < self.length < 100:
self.every = 8
if 101 < self.length < 200:
self.every = 7
if 201 < self.length < 300:
self.every = 6
if 301 < self.length < 400:
self.every = 5
if 400 < self.length:
self.every = 4
# TODO correction fonction de update_clock
self.every = int(self.every*correction)
def get_note(self):
# A chaque tour de boucle
self.progress += 1
# je joue tous les every
if self.progress % self.every == 1:
# Je joue la note de la lettre en position self.progress
if self.progress < self.length - 1:
if self.line[self.progress] in list(note_dict.keys()):
self.note = note_dict[self.line[self.progress]]
# self.note mis a jour une seule fois
else:
self.note = None
return self.note
def get_volume(self):
# set du volume pour la ligne
n = min(self.length, 500)
self.vol = 0.1 + 0.9 * n/500
return self.vol
if __name__ == "__main__":
from time import sleep
str1 = """La commissaire europeenne chargee des Relations exterieures,
l'Autrichienne Benita Ferrero-Waldner annonce qu'elle espere un
acheminement rapide de l'aide humanitaire mais avertit qu'il n'y aura
aucun effort de reconstruction a Gaza tant que le Hamas sera au pouvoir
ref lien web url http: www.lefigaro.fr international 2009 01 19
01003-20090119ARTFIG00444-retour-au-calme-a-gaza-.php titre Gaza :
Abbas propose un gouvernement avec le Hamas editeur Le Figaro date
19 janvier 2009 consulte le 19 janvier 2009 ref ."""
j = 0
phrase_note = Note(str1)
while j < len(str1):
j += 1
sleep(0.03)
note = phrase_note.get_note()
volume = phrase_note.get_volume()
if note:
print(j, note, volume)