Skip to content
This repository has been archived by the owner on Aug 4, 2024. It is now read-only.

Commit

Permalink
- xInstrument: add method -
Browse files Browse the repository at this point in the history
 `get_slice_marker_after_pos`
  • Loading branch information
bjorn-nesby committed Jul 12, 2018
1 parent 8170bc7 commit 01ce927
Showing 1 changed file with 31 additions and 2 deletions.
33 changes: 31 additions & 2 deletions classes/xInstrument.lua
Original file line number Diff line number Diff line change
Expand Up @@ -168,13 +168,17 @@ end

---------------------------------------------------------------------------------------------------
-- [Static] Detect if there is a slice marker *approximately* at the sample pos
-- @return boolean, [error message (string)]
-- @return number or nil, [error message (string)]

function xInstrument.get_slice_marker_at_pos(instr,pos,threshold)
TRACE("xInstrument.get_slice_marker_at_pos(instr,pos,threshold)",instr,pos,threshold)

assert(type(instr)=="Instrument")
assert(type(pos)=="number")
assert(type(threshold)=="number")

if not xInstrument.is_sliced(instr) then
return false, "Instrument contains no slices"
return nil, "Instrument contains no slices"
end

local sample = instr.samples[1]
Expand All @@ -190,6 +194,31 @@ function xInstrument.get_slice_marker_at_pos(instr,pos,threshold)

end

---------------------------------------------------------------------------------------------------
-- obtain the first slice marker following the provided position
-- @param instr (renoise.Instrument)
-- @param pos (number)
-- @return number or nil, [error message (string)]

function xInstrument.get_slice_marker_after_pos(instr,pos)
TRACE("xInstrument.get_slice_marker_after_pos(instr,pos)",instr,pos)

assert(type(instr)=="Instrument")
assert(type(pos)=="number")

if not xInstrument.is_sliced(instr) then
return nil, "Instrument contains no slices"
end

local sample = instr.samples[1]
for marker_idx = 1,#sample.slice_markers do
local marker = sample.slice_markers[marker_idx]
if (marker > pos) then
return marker_idx
end
end

end

---------------------------------------------------------------------------------------------------
-- [Static] Return the slice markers associated with a given sample
Expand Down

0 comments on commit 01ce927

Please sign in to comment.