Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

new reflection feature: loop duration multiplier #1805

Open
jaseknighter opened this issue Dec 26, 2024 · 1 comment
Open

new reflection feature: loop duration multiplier #1805

jaseknighter opened this issue Dec 26, 2024 · 1 comment

Comments

@jaseknighter
Copy link
Contributor

jaseknighter commented Dec 26, 2024

kinda similar to the existing double function in the reflection lib, there could be a function that increases or decreases the duration by a set amount, like:

--- changes the duration of the current loop
function reflection:mult(mul)
  local copy = deep_copy(self.event)
  local event_new = {}
  for i = 1, self.endpoint do
    event_new[math.ceil(i*mul)] = copy[i]
  end
  self.event = event_new
  self.endpoint = math.ceil(self.endpoint * mul)
end

for reference, here's a copy of the existing double function:

--- doubles the current loop
function reflection:double()
  local copy = deep_copy(self.event)
  for i = 1, self.endpoint do
    self.event[self.endpoint + i] = copy[i]
  end
  self.endpoint = self.endpoint * 2
end

i'd be happy to submit a pull request if there's agreement this would be useful in the lib.

edit: one issue with the suggested approach would be if the length were decreased, data from the original reflection could get munged and lost, so maybe more thought would need to go into the enhancement. a better approach could be to keep a copy of the original event table and always perform the mult on this table and not simply replace it with a new table. (note: a similar approach is used for overdubbing with the event_prev table.)

@sonocircuit
Copy link
Contributor

I like the idea but your proposed function would additionally change the distance between events. untested but something like this should work:

function reflection:mult(mul)
  if mul > 0 then
    local new_endpoint = math.ceil(self.endpoint * mul)
    if new_endpoint > self.endpoint then
      local num_steps = new_endpoint - self.endpoint
      local copy = deep_copy(self.event)
      for i = 1, num_steps do
        self.event[self.endpoint + i] = copy[i]
      end
    end
    self.endpoint = new_endpoint
  end
end

please note that my example above would be non-destructive for mul values < 1. If clearing the entries when shortening a loop is required something like this would work (not claiming elegance here. just a proof of concept):

function reflection:mult(mul)
  if mul > 0 then
    local new_endpoint = math.ceil(self.endpoint * mul)
    if new_endpoint > self.endpoint then
      local num_steps = new_endpoint - self.endpoint
      local copy = deep_copy(self.event)
      for i = 1, num_steps do
        self.event[self.endpoint + i] = copy[i]
      end
    else
      local clear_from = new_endpoint + 1
      local clear_to = self.endpoint
      for i = clear_from, clear_to do
        self.event[i] = nil
      end
    end
    self.endpoint = new_endpoint
  end
end

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants