-
Notifications
You must be signed in to change notification settings - Fork 0
/
polyphony.rb
124 lines (110 loc) · 2.72 KB
/
polyphony.rb
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
# load all files
[
"composition",
"ensembles",
"ideation",
"logging",
"performance-helpers",
"performance-midi",
"performance-spi",
"performance",
"rhythm",
"space",
"state",
"tests",
"timekeeping",
"utils",
# load settings last
"settings"
].each do |filename|
load(File.expand_path("#{filename}.rb", -File.dirname(__FILE__)))
end
#
# *Ideate. Compose. Perform.*
#
module Polyphony
#
# Main methods.
#
module Core
extend self
include Polyphony::Composition
include Polyphony::Ensembles
include Polyphony::Ideation
include Polyphony::Logging
include Polyphony::Performance::Helpers
include Polyphony::Performance::Midi
include Polyphony::Performance::SPi
include Polyphony::Performance
include Polyphony::Rhythm
include Polyphony::Settings
include Polyphony::Space
include Polyphony::State
include Polyphony::Timekeeping
include Polyphony::Tests
include Polyphony::Utils
include SonicPi::Lang::Core
include SonicPi::Lang::Midi
include SonicPi::Lang::Sound
#
# Prepares Sonic Pi.
#
def init
initEnv()
initMIDI()
initTimeState()
initState()
initVoices()
end
#
# Prepares Sonic Pi environment.
#
def initEnv
use_bpm(Settings::TIMEKEEPING[:unitsPerMinute])
use_random_seed(Settings::RANDOM[:seed])
use_cue_logging(Settings::LOGGING[:shouldLogCues])
use_debug(Settings::LOGGING[:shouldLogDebug])
use_midi_logging(Settings::LOGGING[:shouldLogMIDI])
end
#
# Prepares Sonic Pi time-state.
#
def initTimeState
set("space/chordRoot", 0)
set("space/key", Settings::SPACE[:initialKey])
set("time/unitsElapsed", 0)
end
#
# Starts all live loops.
#
def run
init()
live_loop :maintainLog, sync_bpm: -"time/measure" do
activateLogging()
sync_bpm(-"time/measure")
end
live_loop :maintainSpace, sync_bpm: -"time/measure" do
waitNumUnitsQuantised(Settings::TIMEKEEPING[:numUnitsPerMeasure] / 2)
activateSpace()
sync_bpm(-"time/measure")
end
live_loop :maintainState, sync_bpm: -"time/measure" do
waitNumUnitsQuantised(Settings::TIMEKEEPING[:numUnitsPerMeasure] / 2)
activateState()
sync_bpm(-"time/measure")
end
live_loop :maintainTimekeeper do
activateTimekeeping()
end
live_loop :maintainVoices, sync_bpm: -"time/measure" do
Settings::VOICES[:selection].each do |voiceType|
in_thread name: "#{voiceType}".to_sym do
activateVoices(voiceType)
end
end
sync_bpm(-"time/measure")
end
end
end
end
include Polyphony::Core