Jump to content


Photo

Moving Samples from one instrument to another instrument


  • Please log in to reply
5 replies to this topic

#1 tunabee

tunabee

    Member

  • Normal Members
  • PipPip
  • 68 posts

Posted 05 December 2017 - 05:56

I'm really struggling to understand how all of this works. Here's what I've tried in the terminal:

inst_a = renoise.song().instruments[2].samples
inst_b = renoise.song().instruments[3].samples

table.insert(inst_a, inst_b[1])

Now, I'd assume that this would insert the first sample of instrument B into instrument A, right? So why doesn't it work? When I rprint inst_a, it indeed does have a new sample, but the instrument in Renoise still only has two. What's going on?


Edited by tunabee, 05 December 2017 - 05:57.


#2 Neurogami

Neurogami

    Big Super Masta Member

  • Normal Members
  • PipPipPipPipPipPipPipPipPipPip
  • 637 posts
  • Gender:Male
  • Location:Scottsdale AZ
  • Interests:Art, music, technology

Posted 05 December 2017 - 06:47

I can't tell you the details of just how Renoise is managing sample objects and such, but I figured this out from the API:

-- Get an index 1 past the current number pf samples
local inst2_sample_slot = #(renoise.song().instruments[2].samples) + 1


-- Insert a blank sample object
renoise.song().instruments[2]:insert_sample_at(inst2_sample_slot)


-- get a reference to the first sample in the other instrument
local s = renoise.song().instruments[3]:sample(1) 


-- Copy those details into the blank sample just created
renoise.song().instruments[2].samples[inst2_sample_slot]:copy_from(s)
 

 

My guess is that the management of samples in an instrument in a song goes beyond a basic table reference, and perhaps other structures need updating before an update to a table of samples is recognized and available.

Edited by Neurogami, 05 December 2017 - 06:48.


#3 tunabee

tunabee

    Member

  • Normal Members
  • PipPip
  • 68 posts

Posted 05 December 2017 - 07:32

Brilliant, that's exactly what I was looking to do. 

 

So far Lua is turning out to be really weird (and I've been programming in Python for a few years now). Thanks for your help.



#4 Neurogami

Neurogami

    Big Super Masta Member

  • Normal Members
  • PipPipPipPipPipPipPipPipPipPip
  • 637 posts
  • Gender:Male
  • Location:Scottsdale AZ
  • Interests:Art, music, technology

Posted 05 December 2017 - 18:02

Lua seems pretty transparent.  Very simple core premises (lots of tables).  A few things (other than indexing starts at 1, which is just evil)) struck me as quirky (coming from Ruby mainly), especially the iteration of tables.    It strikes me as a better-planed, more consistent, less-weird JavaScript.

 

I learned a lot by looking at other people's Renoise tools.

 

I think weirdness here has to do with how the Renoise internals work, because what you tried first really looks like something that should Just Work (but doesn't).



#5 joule

joule

    Guruh Motha Fakka is Levitating and Knows Everything About Renoise Member

  • Normal Members
  • PipPipPipPipPipPipPipPipPipPipPipPipPip
  • 1520 posts
  • Gender:Not Telling
  • Location:Sweden
  • Interests:music, philosophy, engineering

Posted 06 December 2017 - 11:28

PS.

 

In LUA, table.insert(table1, table2) would only insert a reference to the table - meaning that any change to the original will also be visible in this reference. This is quite important to understand, in many cases.

 

A simple rule of thumb: if you can display a real value with the 'print' function, any insertion/assignment will be an actual "copy" of the value. Otherwise, an insertion or assignment will just be a reference (to some kind of object or table).



#6 Neurogami

Neurogami

    Big Super Masta Member

  • Normal Members
  • PipPipPipPipPipPipPipPipPipPip
  • 637 posts
  • Gender:Male
  • Location:Scottsdale AZ
  • Interests:Art, music, technology

Posted 06 December 2017 - 21:35

In LUA, table.insert(table1, table2) would only insert a reference to the table - meaning that any change to the original will also be visible in this reference. This is quite important to understand, in many cases.

 

A simple rule of thumb: if you can display a real value with the 'print' function, any insertion/assignment will be an actual "copy" of the value. Otherwise, an insertion or assignment will just be a reference (to some kind of object or table).

 

Right.  But the question is, why doesn't this (copying references from a sample tables over to another instruments table of samples) produce a discernible effect in Renoise?