A part of a sample into a variable

Hi,

just want to know how to memorize a part of a sample into a variable but the sample is the result of the command sample with start, finish options something like that :

chunk = sample :loop_breakbeat, start: 0, finish: 0.4
sample chunk

Possible ?

I dont know if this works, but there’s no error message,…

chunk = load_sample :loop_breakbeat, start: 0, finish: 0.4
sample chunk 

Eli…

Nice try, Eli, no error but start and stop will be ignored. (I was curious and tried it out.)

As far as I see this is not very elegant but works:

chunk = "sample :loop_breakbeat, start: 0, finish: 0.1"
run_code(chunk)

Yes @Martin it is an idea to store the command into a string

Well I’m home now, and I’ve had a little chance to think and
experiment…

use_sample_defaults start: 0, finish: 0.2
chunk = load_sample :loop_breakbeat
sample chunk

Which sort of led me to this:

chunk = load_sample :loop_breakbeat

live_loop :sam do  
  fin=[0.1,0.2,0.3].choose
  use_sample_defaults start: 0, finish: fin
  sample chunk
  sleep fin
end

And eventually to this:

chunk = load_sample :loop_safari

live_loop :sam do
  fin=0.7
  sta = fin-0.2
  if spread(8, 27).tick
    use_sample_defaults start: sta, finish: fin, amp: 2
    sample chunk
    sleep fin
  else
    sleep fin
  end
end

That seems to work… but I value both of your opinions, please
let me know if I’m wrong?

Eli…

Good morning @Eli,

Thanks for your code but i should have been clearer in my question.
I asked if we can store a part of a sample into a variable. This part would be a sample as the result of some options as start and/or finish parameters.
English is not my natural language and sometimes the question meaning can be misunderstood. Apologies.

the @Martin idea seems to do the job.

Hi,

i would normally put the sample and all it’s parameters into a function, and call it whenever needed. It can even have parameters. That way it would be similar to a variable.
Example:

define :my_kick do
  sample :bd_haus, amp: 1, start: 0.1, attack: 0, sustain: 0, release: 0.01
end

my_kick

Hope this helps.
Cu.

3 Likes

Yes, of course! That’s an obvious solution :wink: (which did not come to my mind). Thanks @minced_mind. And you might parameterize one or the other option (EDIT: oh, you’ve mentioned that already) for more flexibility depending on what you need.

define :my_kick do | begin=0.1, end=1 |
  sample :bd_haus, amp: 1, start: begin, finish: end, attack: 0, sustain: 0, release: 0.01
end

But I am not really sure if this is worth the extra code as in the end this is a wrapper for an already existing function…

hi @minced_mind,

yep a good idea ! but difficult to know the duration without maths. but i keep in mind this very good idea.
thanks

Maybe I misunderstood you. For your given example I would write it like that:

define :chunk do
  sample :loop_breakbeat, start: 0, finish: 0.4
end

chunk

If you want to use different start values you could do something like that:

define :chunk do |s|
  sample :loop_breakbeat, start: s, finish: 0.4
end

chunk 0.1

Or use Martin’s solution with named parameters and defaults. That way the function acts like sample … which is a function, too.

Cu.

Hi @minced_mind

No you have well understood.
A little example no revolution here just example of your idea with a little sequencer.


define :drums_bd do
  sample :drum_heavy_kick, sustain: 0.25, amp:3, compress:1
end

define :drums_sn do
  with_fx :echo, mix: [0.1, 1, 0.2, 1].choose do
    sample :loop_breakbeat, start: 0.25, finish: 0.30, amp: 3
  end
end


define :drums_hithat do
  with_fx :hpf, cutoff: 90 do
    sample :loop_amen, sustain: 0.1, release:0.2,
      start: 0.5, end: 0.45,
      amp: [4, 0.5, 3, 0.25].tick('vol')
  end
end

define :drums_voice do
  sample :ambi_choir, sustain: 0.5, release:0.2,
    numslice: 8, slice: 2, amp: 1
  
end


use_bpm 60


bd_pattern = (ring 1, 1, 0, 0,  0, 0,0, 0,  1, 0, 1, 0,  1, 0, 0, 0)
sn_pattern = (ring 0, 0, 0, 0,  1, 0,0, 0,  0, 0, 0, 0,  1, 0, 0, 1)
hithat_pattern = (ring 1, 0, 1, 0)
voice_pattern = (spread 2,7)
##| voice_pattern = (knit false, 1, true,2, false,1, true,2, false,4, true,1, false,3)

live_loop :sequencer do
  tick
  
  bd_on = bd_pattern.look
  sn_on = sn_pattern.look
  hithat_on = hithat_pattern.look
  voice_on = voice_pattern.look
  
  with_fx :lpf, cutoff: 60, mix: 0.8, pre_amp:1 do
    drums_bd if bd_on==1
  end
  drums_sn if sn_on==1
  drums_hithat if hithat_on==1
  drums_voice if voice_on # spread send back us true or false
  
  sleep 0.25
end

Cheers

Hi nlb,

actually a nice example from you :slight_smile: I’m using function encapsulation for creating musical patterns (melody, some specific sound, a virtual instrument) to arrange the stuff in the composition area.

Cu.