-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexample.lua
More file actions
218 lines (174 loc) · 8.32 KB
/
Copy pathexample.lua
File metadata and controls
218 lines (174 loc) · 8.32 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
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
-- An example Nebulua composition file.
-- Import modules this needs.
local api = require("script_api")
local mus = require("music_defs")
local def = require("defs_api")
local mid = require("midi_defs")
local mt = require("music_time")
local ut = require("lbot_utils")
local sx = require("stringex")
-- Aliases for imports - less typing.
local inst = mid.instruments
local drum = mid.drums
local kit = mid.drum_kits
local ctrl = mid.controllers
-- Say hello.
api.log_info('Loading example.lua...')
print('================')
------------------------- Configuration -------------------------------
-- Midi channels. Adjust for your configuration.
local midi_device_in = "NebLoopback1"
local hnd_ccin = api.open_input_channel(midi_device_in, 1, "my input")
local midi_device_out = "Microsoft GS Wavetable Synth" -- or "VirtualMIDISynth #1" or "NebLoopback1" for VST host
local hnd_keys = api.open_output_channel(midi_device_out, 1, "keys", inst.AcousticGrandPiano)
local hnd_bass = api.open_output_channel(midi_device_out, 2, "bass", inst.AcousticBass)
local hnd_synth = api.open_output_channel(midi_device_out, 3, "synth", inst.Lead1Square)
local hnd_strings = api.open_output_channel(midi_device_out, 4, "pan flute", inst.StringEnsemble1)
local hnd_drums = api.open_output_channel(midi_device_out, 10, "drums", kit.Jazz)
------------------------- Variables -----------------------------------
-- Get some stock chords and scales.
local my_scale = def.get_notes_from_string("C4.o7")
-- Create custom note collection.
def.create_definition("MY_CHORD", "1 +3 4 -b7")
local my_chord = def.get_notes_from_string("B4.MY_CHORD")
-- Aliases for instruments.
local snare = drum.AcousticSnare
local bdrum = drum.AcousticBassDrum
local hhcl = drum.ClosedHiHat
local ride = drum.RideCymbal1
local crash = drum.CrashCymbal2
local mtom = drum.HiMidTom
-- Forward refs.
local _algo_func
---------------------------------------------------------------------------
------------------------- System Functions --------------------------------
---------------------------------------------------------------------------
-----------------------------------------------------------------------------
-- Called once to initialize your script stuff. Required.
function setup()
api.log_info("example initialization")
-- How fast?
api.set_tempo(88)
-- Set master volumes.
api.set_volume(hnd_keys, 0.7)
api.set_volume(hnd_bass, 0.9)
api.set_volume(hnd_synth, 0.6)
api.set_volume(hnd_drums, 0.9)
api.set_volume(hnd_strings, 0.9)
-- This file uses static composition so you must call this!
return api.process_comp()
end
-----------------------------------------------------------------------------
-- Main work loop called every tick. Required.
function step(tick)
-- Overhead.
api.process_step(tick)
-- Other work you may want to do. Like do something every new bar.
local bar, beat, sub = mt.tick_to_mt(tick)
if beat == 2 and sub == 0 then
-- api.send_midi_controller(hnd_synth, ctrl.Pan, 90)
_algo_func(tick)
end
return 0
end
---------------------------------------------------------------------------
-- Handler for input note events. Optional.
function receive_midi_note(chan_hnd, note_num, volume)
if chan_hnd == hnd_ccin then
-- Play the note.
-- api.log_debug(string.format("RCV hnd_ccin note:%d chan_hnd:%d volume:%f", note_num, chan_hnd, volume))
api.send_note(hnd_strings, note_num, volume)--, 0)
end
return 0
end
---------------------------------------------------------------------------
-- Handlers for input controller events. Optional.
function receive_midi_controller(chan_hnd, controller, value)
if chan_hnd == hnd_ccin then
api.log_debug(string.format("RCV controller:%d chan_hnd:%d value:%d", controller, chan_hnd, value))
-- Do something.
end
return 0
end
---------------------------------------------------------------------------
----------------------- Local Functions -----------------------------------
---------------------------------------------------------------------------
-- Function called from sequence.
_algo_func = function(tick)
if my_scale ~= nil then
local note_num = math.random(1, #my_scale)
api.send_note(hnd_synth, my_scale[note_num], 0.8, 3)
end
end
---------------------------------------------------------------------------
------------------------- Composition -------------------------------------
---------------------------------------------------------------------------
-- Sequences -- each sequence is 8 beats = 2 bars, section is 8 bars
local quiet =
{
{ "| | | | | | | | |", 0 }
}
local example_seq =
{
-- | beat 0 | beat 1 | beat 2 | beat 3 | beat 4 | beat 5 | beat 6 | beat 7 |, WHAT_TO_PLAY
-- |........|........|........|........|........|........|........|........|
{ "|6-------|-- | | |7-------|-- | | |", "G4.m7" },
{ "|7-------|-- | | |7-------|-- | | |", 84 },
{ "| | | |5--- | | | |5-8--- |", "D6" },
}
local drums_verse =
{
-- |........|........|........|........|........|........|........|........|
{ "|8 | |8 | |8 | |8 | |", bdrum },
{ "| 8 | | 8 | 8 | 8 | | 8 | 8 |", snare },
{ "| | 8 8| | 8 8| | 8 8| | 8 8|", hhcl }
}
local drums_chorus =
{
-- |........|........|........|........|........|........|........|........|
{ "|6 | |6 | |6 | |6 | |", bdrum },
{ "| |7 7 | |7 7 | |7 7 | | |", ride },
{ "| | 4 | | | | 4 | | |", mtom },
{ "| | | | | | | |8 |", crash },
}
local keys_verse =
{
-- |........|........|........|........|........|........|........|........|
{ "|7-------|-- | | |7-------|-- | | |", "G4.m7" },
{ "| | | |5--- | | | |5- |", "G4.m6" },
{ "| | | |5--- | | | | 8--- |", "B4.MY_CHORD" },
}
local keys_chorus =
{
-- |........|........|........|........|........|........|........|........|
{ "|6- | | | | | | | |", "F4" },
{ "| 5- | | | | | | | |", "D#4" },
{ "| |6- | | | | | | |", "C4" },
{ "| | 6- | | | | | | |", "B4.m7" },
}
local bass_verse =
{
-- |........|........|........|........|........|........|........|........|
{ "|9-------| | | | | | | |", "C2" },
{ "| | | | 7---| | | | |", "E2" },
{ "| | | | | | | | 9---|", "A#2" },
}
local bass_chorus =
{
-- |........|........|........|........|........|........|........|........|
{ "|5 8 | |5 8 | |5 8 | |5 8 | |", "C2" },
}
-- Sections -- each section is 8 bars
-- 0 2 4 6
api.sect_start("beginning")
api.sect_chan(hnd_keys, keys_verse, keys_verse, keys_verse, keys_verse)
api.sect_chan(hnd_drums, drums_verse, drums_verse, drums_verse, drums_verse)
api.sect_chan(hnd_bass, bass_verse, bass_verse, bass_verse, bass_verse)
api.sect_start("middle")
api.sect_chan(hnd_keys, keys_chorus, keys_chorus, keys_chorus, keys_chorus)
api.sect_chan(hnd_drums, drums_chorus, drums_chorus, drums_chorus, drums_chorus)
api.sect_chan(hnd_bass, bass_chorus, bass_chorus, bass_chorus, bass_chorus)
api.sect_start("ending")
api.sect_chan(hnd_keys, keys_verse, keys_verse, keys_verse, keys_verse)
api.sect_chan(hnd_drums, drums_verse, drums_verse, drums_verse, drums_verse)
api.sect_chan(hnd_bass, bass_verse, bass_verse, bass_verse, bass_verse)