Skip to content

Commit

Permalink
Added insert notes at cursor position option.
Browse files Browse the repository at this point in the history
  • Loading branch information
nilcaream committed Oct 25, 2022
1 parent cc07620 commit 905d037
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 17 deletions.
8 changes: 6 additions & 2 deletions com.nilcaream.rsmfs.xrnx/README.md
Expand Up @@ -11,15 +11,15 @@ This plugin will reuse existing instrument and will only update currently select
#### Version 0.1

- reads midi files with `.xrmid` extension,
- prints notes and file information in Scripting Terminal.
- print notes and file information in Scripting Terminal.
- adds midi note events (note, volume, delay) to selected pattern track.
- adjusts number of pattern lines and visible note columns to match the midi file (optional).

#### Version 0.2

- added an option to skip note volume information (`Tools - Renoise Simple Midi File Support - Include velocity` = `false`).
- fixed an issue with old notes cleanup when pattern was too short but had hidden notes in it (outside of pattern lines range).
- fixed an issue with tool crashing on trying to add notes outside of the Renoise max 512 pattern lines length.
- fixed an issue with tool crashing on trying to add notes outside the Renoise max 512 pattern lines length.
- skipped setting note volume for midi notes with maximum velocity (127).
- added note-off commands for first line of the track.

Expand Down Expand Up @@ -47,6 +47,10 @@ This plugin will reuse existing instrument and will only update currently select
- added tooltips for options.
- reviewed, corrected and updated this readme.

#### Version 0.6

- added an option to insert notes at cursor position (`Options - Insert at cursor position` = `true`; thanks, Neuro... No Neuro).

## Capabilities and limitations

This is my first Renoise tool and first code in Lua. I am also new to the midi file format and midi events. The use case implemented here is very simple and might be limited a single, specific scenario. It is not meant to be a replacement for the built-in midi files import nor a general purpose midi file to Renoise song converter.
Expand Down
2 changes: 1 addition & 1 deletion com.nilcaream.rsmfs.xrnx/manifest.xml
Expand Up @@ -2,7 +2,7 @@
<RenoiseScriptingTool doc_version="0">
<ApiVersion>6.1</ApiVersion>
<Id>com.nilcaream.rsmfs</Id>
<Version>0.5</Version>
<Version>0.6</Version>
<Author>Nil Caream [nil.caream@gmail.com]</Author>
<Name>Renoise Simple Midi File Support</Name>
<Category>File Formats, MIDI</Category>
Expand Down
18 changes: 10 additions & 8 deletions com.nilcaream.rsmfs.xrnx/options.lua
Expand Up @@ -12,7 +12,8 @@ rsmfs.options = {
include_velocity = true,
include_delay = true,
include_note_off = true,
correct_positions = false
correct_positions = false,
insert_at_cursor = false
}

rsmfs.options.init = function()
Expand Down Expand Up @@ -93,20 +94,21 @@ rsmfs.options.show = function()
vb:column {
spacing = CONTENT_SPACING,

add_checkbox("Add note columns", "add_note_columns", "Add note columns to track if needed"),
add_checkbox("Remove note columns", "remove_note_columns", "Remove note columns to track if needed"),
add_checkbox("Increase number of lines", "increase_number_of_lines", "Increase pattern number of lines if needed"),
add_checkbox("Decrease number of lines", "decrease_number_of_lines", "Decrease pattern number of lines if needed"),
add_checkbox("Add note columns", "add_note_columns", "Adds note columns to track if needed"),
add_checkbox("Remove note columns", "remove_note_columns", "Removes note columns to track if needed"),
add_checkbox("Increase number of lines", "increase_number_of_lines", "Increases pattern number of lines if needed"),
add_checkbox("Decrease number of lines", "decrease_number_of_lines", "Decreases pattern number of lines if needed"),

vb:space { height = DEFAULT_CONTROL_HEIGHT },

add_checkbox("Include velocity", "include_velocity", "Include note velocity (volume)"),
add_checkbox("Include delay", "include_delay", "Include note delay"),
add_checkbox("Include note off", "include_note_off", "Include note-off (OFF)"),
add_checkbox("Include velocity", "include_velocity", "Includes note velocity (volume)"),
add_checkbox("Include delay", "include_delay", "Includes note delay"),
add_checkbox("Include note off", "include_note_off", "Includes note-off (OFF)"),

vb:space { height = DEFAULT_CONTROL_HEIGHT },

add_checkbox("Correct positions", "correct_positions", "Increase by 1 note's start or end positions if delay is higher than FD"),
add_checkbox("Insert at cursor position", "insert_at_cursor", "Inserts notes at cursor position. Clears only notes after the cursor"),

vb:space { height = DEFAULT_CONTROL_HEIGHT },

Expand Down
30 changes: 24 additions & 6 deletions com.nilcaream.rsmfs.xrnx/workplace.lua
Expand Up @@ -9,18 +9,30 @@ function rsmfs.workplace:new()
track_index = renoise.song().selected_track_index,
track = renoise.song().selected_track,
pattern = renoise.song().selected_pattern,
instrument = renoise.song().selected_instrument_index - 1
instrument = renoise.song().selected_instrument_index,
line_index = renoise.song().selected_line_index,
note_column_index = math.max(1, renoise.song().selected_note_column_index) -- 0 when effect column is selected
}
setmetatable(instance, rsmfs.workplace)
return instance
end

function rsmfs.workplace:prepare(track_lines_number)
local number_of_lines = self.pattern.number_of_lines
local offset_position = 0
local offset_track_lines_number = 0

if rsmfs.options.insert_at_cursor then
offset_position = self.line_index - 1
offset_track_lines_number = self.note_column_index - 1
track_lines_number = track_lines_number + offset_track_lines_number
end

self.pattern.number_of_lines = 512
for index, line in ipairs(self.pattern_track.lines) do
line:clear()
if index >= offset_position then
line:clear()
end
end
self.pattern.number_of_lines = number_of_lines

Expand All @@ -38,7 +50,7 @@ function rsmfs.workplace:prepare(track_lines_number)

if rsmfs.options.include_note_off then
for i = 1, self.track.visible_note_columns do
self.pattern_track:line(1):note_column(i).note_string = "OFF"
self.pattern_track:line(1 + offset_position):note_column(i + offset_track_lines_number).note_string = "OFF"
end
end

Expand All @@ -48,15 +60,21 @@ end

function rsmfs.workplace:update(note_column_index, renoise_note_column)
local max_end_position = 1
local offset_position = 0

if rsmfs.options.insert_at_cursor then
offset_position = self.line_index - 1
note_column_index = note_column_index + self.note_column_index - 1
end

if note_column_index > 12 then
rsmfs.log("Skipping note column " .. note_column_index)
return
end

for index, renoise_note_column_line in ipairs(renoise_note_column) do
local start_position = math.floor(renoise_note_column_line.start_position)
local end_position = math.floor(renoise_note_column_line.end_position)
local start_position = offset_position + math.floor(renoise_note_column_line.start_position)
local end_position = offset_position + math.floor(renoise_note_column_line.end_position)

max_end_position = math.max(max_end_position, end_position)

Expand All @@ -67,7 +85,7 @@ function rsmfs.workplace:update(note_column_index, renoise_note_column)

-- rsmfs.log("Update - line: %d, note: %s, start: %d, end: %d", line_index, pre_track_entry.note, start_position, end_position)

self.pattern_track:line(start_position + 1):note_column(note_column_index).instrument_value = self.instrument
self.pattern_track:line(start_position + 1):note_column(note_column_index).instrument_value = self.instrument - 1

if rsmfs.options.include_velocity and renoise_note_column_line.velocity < 127 then
self.pattern_track:line(start_position + 1):note_column(note_column_index).volume_value = renoise_note_column_line.velocity
Expand Down

0 comments on commit 905d037

Please sign in to comment.