-
Notifications
You must be signed in to change notification settings - Fork 0
/
stereostrand_main.py
129 lines (92 loc) · 2.87 KB
/
stereostrand_main.py
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
123
124
125
126
127
128
import time
import numpy as np
from midi_connector import midi_connector
from pygame import mixer # Load the required library
from asciimatics.effects import Cycle, Stars
from asciimatics.renderers import FigletText
from asciimatics.scene import Scene
from asciimatics.screen import Screen
#sched
import sched, time
# Startbildschirm
def ascii_greeter(screen):
effects = [
Cycle(
screen,
FigletText("StereoStrand", font='big'),
int(screen.height / 2 - 8)),
Cycle(
screen,
FigletText("ROCKS!", font='big'),
int(screen.height / 2 + 3)),
Stars(screen, 200)
]
screen.play([Scene(effects, 100)],repeat=False)
WINDOW = 100
# CHANNELS = 6
PATH_TO_MP3 = '/home/pi/Sound/STEREOSONG.mp3'
INTERVAL = int(input('\n\nZeitintervall zwischen den Sounds (Pause), z.B. 30 heißt alle 30 min spielts (nur ganze Zahlen, kein Komma!)\n'))
PLAY_TIME = int(input('\n\nWie lange solls spielen (Minuten)?\n'))
MIN_SAMPLE_INTERVAL = float(input('\n\nWie lang soll der MINIMALE Zeitabstand der samples sein? zB 0.2 für 0.2 sek\n'))
MAX_SAMPLE_INTERVAL = float(input('\n\nWie lang soll der MAXIMALE Zeitabstand der samples sein? zB 1 für 1 sek\n'))
SAMPLE_INTERVAL_RATIO = int(MAX_SAMPLE_INTERVAL/MIN_SAMPLE_INTERVAL)
CHANNELS = int(input('\n\nWie viele Midi Kanäle gibts? (8 heißt 8 Kanäle!)\n'))
# BEATS_INTERVAL in sec
INTERVAL=INTERVAL*60
PLAY_TIME = PLAY_TIME*60/MIN_SAMPLE_INTERVAL
COUNTER = 0
#
#
# try:
# INTERVAL = float(INTERVAL)
# except ValueError:
# print('Muss eine Zahl sein!')
# ASCII bild
try:
Screen.wrapper(ascii_greeter)
# klappt nie beim ersten mal???
except:
pass
try:
Screen.wrapper(ascii_greeter)
except:
pass
midi = midi_connector(WINDOW=WINDOW,CHANNELS=CHANNELS)
# initialize midi
midi.init_midi()
print('\nIt`s on!')
print('Press Ctrl+c to abort')
# bis hier OK
def play():
counter = 0
# StartZeit
time_start = time.time()
# load the mp3 sound file
# initialze the mixer for mp3
mixer.init()
mixer.music.load(PATH_TO_MP3)
mixer.music.play()
try:
while counter<PLAY_TIME:
# Das Signal soll random zwischen MIN und MAX gesendet werden
my_rand_int = np.random.randint(SAMPLE_INTERVAL_RATIO)
if my_rand_int == 0:
midi.send_signal()
time.sleep(MIN_SAMPLE_INTERVAL)
counter +=1
# aktuelle Zeit
jetzt_zeit=time.time()
diff_time = jetzt_zeit - time_start
# stop das Lied
mixer.music.stop()
# scheduler
s.enter(INTERVAL, 1000, play, ())
s.run()
except KeyboardInterrupt:
midi.quit_midi()
#TODO
# hier brauchts noch ein scheduler der alle 30 min play macht
s = sched.scheduler(time.time, time.sleep)
if __name__=='__main__':
play()
# midi.quit_midi()