-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathOSC.lua
More file actions
64 lines (52 loc) · 1.97 KB
/
Copy pathOSC.lua
File metadata and controls
64 lines (52 loc) · 1.97 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
previousChordNotesArray = nil
function connectOSC()
-- Left empty; OSC networking removed in favor of direct Renoise 6.2 API calls
end
function getVelocityValue()
if renoise.song().transport.keyboard_velocity_enabled then
return renoise.song().transport.keyboard_velocity
else
return 127
end
end
function stopPreviousChord(chordNotesArray)
local song = renoise.song()
local instrument_index = song.selected_instrument_index
local track_index = song.selected_track_index
for i = 1, #chordNotesArray do
local note = chordNotesArray[i]
-- Renoise API takes raw note values (0 = C-0, 119 = B-9)
song:trigger_instrument_note_off(instrument_index, track_index, note)
end
end
function stopCurrentChordTimer()
if previousChordNotesArray ~= nil then
stopPreviousChord(previousChordNotesArray)
previousChordNotesArray = nil
end
if renoise.tool():has_timer(stopCurrentChordTimer) then
renoise.tool():remove_timer(stopCurrentChordTimer)
end
end
function playChordWithOsc(chordNotesArray)
-- Stop the previous chord if it is still playing
if previousChordNotesArray ~= nil then
stopPreviousChord(previousChordNotesArray)
end
if renoise.tool():has_timer(stopCurrentChordTimer) then
renoise.tool():remove_timer(stopCurrentChordTimer)
end
local song = renoise.song()
local instrument_index = song.selected_instrument_index
local track_index = song.selected_track_index
-- The Renoise API expects volume normalized between 0.0 and 1.0
local velocityValue = getVelocityValue()
local volume = velocityValue / 127.0
for i = 1, #chordNotesArray do
local note = chordNotesArray[i]
song:trigger_instrument_note_on(instrument_index, track_index, note, volume)
end
previousChordNotesArray = chordNotesArray
-- Add a timer to stop the chord after 1 second (1000 ms)
renoise.tool():add_timer(stopCurrentChordTimer, 1000)
end