-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
PakettiPatternMatrix.lua
176 lines (139 loc) · 8.84 KB
/
PakettiPatternMatrix.lua
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
-- Show or hide Pattern Matrix
function showhidepatternmatrix()
if renoise.app().window.active_middle_frame ~= renoise.ApplicationWindow.MIDDLE_FRAME_PATTERN_EDITOR
then renoise.app().window.active_middle_frame=renoise.ApplicationWindow.MIDDLE_FRAME_PATTERN_EDITOR
renoise.app().window.pattern_matrix_is_visible = true
return
end
if renoise.app().window.pattern_matrix_is_visible == true
then renoise.app().window.pattern_matrix_is_visible = false
else renoise.app().window.pattern_matrix_is_visible = true
end
end
renoise.tool():add_keybinding{name="Global:Paketti:Show/Hide Pattern Matrix",invoke=function() showhidepatternmatrix() end}
renoise.tool():add_menu_entry{name="--Pattern Matrix:Paketti..:Switch to Automation",invoke=function() showAutomation() end}
renoise.tool():add_menu_entry{name="--Pattern Matrix:Paketti..:Bypass EFX (Write to Pattern)", invoke=function() effectbypasspattern() end}
renoise.tool():add_menu_entry{name="Pattern Matrix:Paketti..:Enable EFX (Write to Pattern)", invoke=function() effectenablepattern() end}
renoise.tool():add_menu_entry{name="--Pattern Matrix:Paketti..:Bypass All Devices on Channel", invoke=function() effectbypass() end}
renoise.tool():add_menu_entry{name="Pattern Matrix:Paketti..:Enable All Devices on Channel", invoke=function() effectenable() end}
renoise.tool():add_menu_entry{name="--Pattern Matrix:Paketti..:Play at 75% Speed (Song BPM)", invoke=function() playat75() end}
renoise.tool():add_menu_entry{name="Pattern Matrix:Paketti..:Play at 100% Speed (Song BPM)", invoke=function() returnbackto100() end}
-------
local function duplicate_pattern_and_clear_muted_above()
local song=renoise.song()
local current_pattern_index=song.selected_pattern_index
local current_sequence_index=song.selected_sequence_index
-- Insert a new, unreferenced pattern above the current sequence index
local new_sequence_index = current_sequence_index
local new_pattern_index = song.sequencer:insert_new_pattern_at(new_sequence_index)
-- Copy the current pattern into the newly created pattern
song.patterns[new_pattern_index]:copy_from(song.patterns[current_pattern_index])
-- Set the name of the new pattern based on the original name or default to "Pattern <number> (mutes cleared)"
local original_name = song.patterns[current_pattern_index].name
if original_name == "" then
original_name = "Pattern " .. tostring(current_pattern_index)
end
song.patterns[new_pattern_index].name = original_name .. " (mutes cleared)"
-- Select the new sequence index
song.selected_sequence_index = new_sequence_index
-- Apply mute states from the original pattern to the new pattern in the sequencer
for track_index = 1, #song.tracks do
local is_muted = song.sequencer:track_sequence_slot_is_muted(track_index, current_sequence_index)
song.sequencer:set_track_sequence_slot_is_muted(track_index, new_sequence_index, is_muted)
if is_muted then
print("Track " .. track_index .. " was muted in the original sequence; muting in new sequence.")
end
end
-- Copy all automation data from the original pattern to the new pattern
for track_index = 1, #song.tracks do
local original_track = song.patterns[current_pattern_index].tracks[track_index]
local new_track = song.patterns[new_pattern_index].tracks[track_index]
for _, automation in ipairs(original_track.automation) do
local parameter = automation.dest_parameter
-- Find or create the corresponding automation in the new track
local new_automation = new_track:find_automation(parameter)
if not new_automation then
new_automation = new_track:create_automation(parameter)
end
-- Copy the entire automation data using copy_from
new_automation:copy_from(automation)
print("Copied complete automation for parameter in track " .. track_index)
end
end
-- Identify tracks that are muted or off, then clear them in the new pattern
local muted_tracks = {}
for i, track in ipairs(song.tracks) do
if track.mute_state == renoise.Track.MUTE_STATE_MUTED or track.mute_state == renoise.Track.MUTE_STATE_OFF then
table.insert(muted_tracks, i)
print("Track " .. i .. " is muted or off. Preparing to clear it.")
end
end
for _, track_index in ipairs(muted_tracks) do
song.patterns[new_pattern_index].tracks[track_index]:clear()
print("Cleared track " .. track_index .. " in duplicated pattern.")
end
renoise.app():show_status("Duplicated pattern above current sequence with mute states, complete automation, and cleared muted tracks.")
end
renoise.tool():add_keybinding{name="Global:Paketti:Duplicate Pattern Above & Clear Muted Tracks", invoke=duplicate_pattern_and_clear_muted_above}
renoise.tool():add_midi_mapping{name="Paketti:Duplicate Pattern Above & Clear Muted", invoke=duplicate_pattern_and_clear_muted_above}
renoise.tool():add_menu_entry{name="Main Menu:Tools:Paketti..:Pattern Editor..:Duplicate Pattern Above & Clear Muted", invoke=duplicate_pattern_and_clear_muted_above}
renoise.tool():add_menu_entry{name="Pattern Editor:Paketti..:Duplicate Pattern Above & Clear Muted", invoke=duplicate_pattern_and_clear_muted_above}
renoise.tool():add_menu_entry{name="Pattern Matrix:Paketti..:Duplicate Pattern Above & Clear Muted", invoke=duplicate_pattern_and_clear_muted_above}
renoise.tool():add_menu_entry{name="Mixer:Paketti..:Duplicate Pattern Above & Clear Muted", invoke=duplicate_pattern_and_clear_muted_above}
local function duplicate_pattern_and_clear_muted()
local song=renoise.song()
local current_pattern_index=song.selected_pattern_index
local current_sequence_index=song.selected_sequence_index
-- Insert a new, unreferenced pattern below the current sequence index
local new_sequence_index = current_sequence_index + 1
local new_pattern_index = song.sequencer:insert_new_pattern_at(new_sequence_index)
-- Copy the current pattern into the newly created pattern
song.patterns[new_pattern_index]:copy_from(song.patterns[current_pattern_index])
-- Set the name of the new pattern based on the original name or default to "Pattern <number> (mutes cleared)"
local original_name = song.patterns[current_pattern_index].name
if original_name == "" then
original_name = "Pattern " .. tostring(current_pattern_index)
end
song.patterns[new_pattern_index].name = original_name .. " (mutes cleared)"
-- Select the new sequence index
song.selected_sequence_index = new_sequence_index
-- Apply mute states from the original pattern to the new pattern in the sequencer
for track_index = 1, #song.tracks do
local is_muted = song.sequencer:track_sequence_slot_is_muted(track_index, current_sequence_index)
song.sequencer:set_track_sequence_slot_is_muted(track_index, new_sequence_index, is_muted)
if is_muted then
end
end
-- Copy all automation data from the original pattern to the new pattern
for track_index = 1, #song.tracks do
local original_track = song.patterns[current_pattern_index].tracks[track_index]
local new_track = song.patterns[new_pattern_index].tracks[track_index]
for _, automation in ipairs(original_track.automation) do
local parameter = automation.dest_parameter
-- Find or create the corresponding automation in the new track
local new_automation = new_track:find_automation(parameter)
if not new_automation then
new_automation = new_track:create_automation(parameter)
end
-- Copy the entire automation data using copy_from
new_automation:copy_from(automation)
end
end
-- Identify tracks that are muted or off, then clear them in the new pattern
local muted_tracks = {}
for i, track in ipairs(song.tracks) do
if track.mute_state == renoise.Track.MUTE_STATE_MUTED or track.mute_state == renoise.Track.MUTE_STATE_OFF then
table.insert(muted_tracks, i)
end
end
for _, track_index in ipairs(muted_tracks) do
song.patterns[new_pattern_index].tracks[track_index]:clear()
end
renoise.app():show_status("Duplicated pattern below current sequence with mute states, complete automation, and cleared muted tracks.")
end
renoise.tool():add_keybinding{name="Global:Paketti:Duplicate Pattern Below & Clear Muted Tracks", invoke=duplicate_pattern_and_clear_muted}
renoise.tool():add_midi_mapping{name="Paketti:Duplicate Pattern Below & Clear Muted", invoke=duplicate_pattern_and_clear_muted}
renoise.tool():add_menu_entry{name="Main Menu:Tools:Paketti..:Pattern Editor..:Duplicate Pattern Below & Clear Muted", invoke=duplicate_pattern_and_clear_muted}
renoise.tool():add_menu_entry{name="Pattern Editor:Paketti..:Duplicate Pattern Below & Clear Muted", invoke=duplicate_pattern_and_clear_muted}
renoise.tool():add_menu_entry{name="Pattern Matrix:Paketti..:Duplicate Pattern Below & Clear Muted", invoke=duplicate_pattern_and_clear_muted}
renoise.tool():add_menu_entry{name="Mixer:Paketti..:Duplicate Pattern Below & Clear Muted", invoke=duplicate_pattern_and_clear_muted}