Help looking for Sonic Pi coder to help create some tunes

The code below will work, but I find it very messy and difficult to adjust or see exactly what will happen. It seems to just have several different ideas randomly added on top of each other, although they will work together in a somewhat haphazard manner.

I assume the sample you want is the piece you posted to soundcloud. I managed to download it with the aid of a helper program, and the first thing I did was to convert it from mp3 to flac format as this is one that Sonic Pi can handle. (I used audacity to do this). I then placed it in a folder music in my downloads folder and hence it is accessed by index 0 in that folder (your setting was 2, but maybe you have other samples there as well).
I altered your loop that was inside an in_thread block to a live loop named live_loop :test By adding a sync command inside the loop it can be synced to live_loop :three. I placed it before the other live loops, so that it was running and waiting for this sync BEFORE live_loop three starts for the first time. That way it starts the first time live_loop :three starts. Live_loop :three has a duration of several seconds (a+s+r) on each pass, but this is quite a bit shorter that the downloaded sample duration, even though it is played at a higher rate and only with a finish 0.75 or three quarters of the way through. You will therefore get the sample overlaying several times. I have set the loop to print each time it runs a new iteration so you can visually see when this happens.
With the present synth (:tri) you won’t hear played midi notes very well, but I don’t know what your aim is here. You can here the various percussion loops playing though.
I have added a line use_debug false so that the log window is not so cluttered up.

I think that I have taken this as far as it can go at present. I suggest that you need to do some planning as to what you are eventually aiming at. Just adding further bits seemingly rather at random is unlikely to achieve a good result.

#7
use_debug false
set_volume! 1
##| Link to the samples folder:
samples_dir = '~/Downloads/music' #i've changed this to suit my setup
with_fx :reverb, room: 1 do
  with_fx :rbpf, res: 0, mix: 0.7 do
    with_fx :gverb, mix: 0.2, room: 10 do
      live_loop :test do #your loop changed to a live loop. Synced bynext line
        sync :three#syncved by live loop three.
        puts "loop test run ",tick #printed each time toe live loop starts
        #sample lenght is quite long so will not finish before next overlay starts
        sample samples_dir,0 , amp: 1.35, rate: 1.4, compress: 1, finish: 0.75, release: 2
      end
    end
  end
end

n,v = sync "/midi*:1/note_on"#first midi note starts things going

use_synth :tri #synth for midi input notes
set :flag, false
define :check_sample do |ns,bs|
  in_thread do
    sample ns,beat_stretch: bs,amp: 0.7
    set :flag,true
    sleep bs
    set :flag,false
  end
end

live_loop :midi_in do
  use_real_time
  #n,v = sync "/midi*/note_on"
  n,v = sync "/midi*:1/note_on"
  if v > 0
    play n,amp: v/127.0,release: 0.2
    if get(:flag)==false
      #tick chooses sample in sequence from a ring, 8 is the beat_stretch number
      check_sample (ring :loop_garzul,:loop_mika,:loop_safari).tick,8
    end
  end
end

mn=[]; for j in 1..1023
  mn[j]=hz_to_midi(11*j)
end;
use_synth :hoover

m=[3,6,9]
nl=[24,30,36,48]
# Ryhtm


live_loop :one do
  a=choose(m); s=choose(m); r=choose(m)
  nv=choose(nl)
  play mn[nv], attack: a,
    sustain: s, release: r, amp: 0.6
  print  mn[nv], attack: a,
    sustain: s, release: r
sleep a+s+r; end

with_fx :reverb, room: 1 do
  with_fx :echo do
    live_loop :two do
      #use_synth :dark_ambience
      use_synth (ring :blade, :hollow,  :hoover).tick
      a=choose(m); s=choose(m); r=choose(m)
      nv=choose(nl)
      play mn[nv], attack: a,
        sustain: s, release: r, amp: 0.75
    sleep a+s+r; end
  end
end

live_loop :three do
  a=choose(m); s=choose(m); r=choose(m)
  #use_synth :prophet
  use_synth (ring :hoover, :hollow, :blade).tick
  nv=choose(nl)
  play mn[nv], attack: a,
    sustain: s, release: r, amp: 0.8
sleep a+s+r; end

I truly appreciate all your assistance and input :pray:- Ive learned a lot from this so far. :+1:
I may phrase the question incorrectly and this causes these back and forth. Apologies.
From the start what Im trying to do is play some music clips - saved in my samples directory at various stages to approximate the sprindrift soundcloud sample I posted.
while those clips are playing to then be able to play new midi sounds to sync as far as possible with the clips playing in the background from my samples directory.
For example in my samples directory there are 12 (flac) of various lengths songs I want to play these sequentially or randomly in the background (so assume amp will be < 6) and on top of these to play the midi notes I want these midi notes to have different exotic sounds say like a vangelis :smiley:synth overlayed and synced on top of the sample being played.

I dont want to have to play the sonic pi synths that we currently do for the midi input ie:use_synth :tri #synth for midi input notes - can i instead play a sample clip in its place for the midi? ie:

use_synth samples_dir ,1 # where 1 is for example the ambi_choir.flac and the midi input v will adjust the parameters of this as we do with use_synth :tri. I cant seem to get this right ?.
What I want to do is not be forced to play the synth sounds ie tri prophet etc and want to rather play something more exotic in their place when playing midi keys. Vangelis type effect :grinning_face_with_smiling_eyes:

Also Im sure its covered somewhere but how do I ensure that a song plays when sonic pi is opened without me having to hit the play button on the program? So in my case when i play a midi note the song will play?

thanks again!

ps - the loops dont stop playing now when no midi input is played - it used to stop after no midi input please can you advise what to do to fix this

Hey wro,

The key here is that samples are not synths. As the name suggests, use_synth is for choosing a synth to use :slightly_smiling_face:
To choose a sample, you just use the sample function, and give it a path and/or some filters.

The init.rb file, which lives in ~/.sonic-pi/config. See an example file (basically empty) at:

You would place whatever you want to auto-start in here. (Which by the sound of it is a loop that then immediately syncs on an external MIDI event, so that it waits for you to start playing?).

When you say ‘the loops’ - is this in reference to Robin’s exact code just above your reply? or are you talking about code you’ve personally modified? (in which case sharing it would be valuable). It helps to be very clear :slightly_smiling_face:

Robins code above - thanks

The live_loop :test is synced to start with live_loop :three. Since this runs continuously after the initial midi note input which starts everything running. so will that loop. I’m not sure what you are aiming at. Also with regards to the unwanted notes with the :tri synth, you can miss out the play n,amp: v/127.0,release: 0.2 line altogether. In that case a midi note will sync the start of one of the :loop samples (or any sample you substitute for them) without playing anything.

What might help would be if you could perhaps draw a clear diagram showing what you want to happen and when, and which bits are to depend on an incoming midi signal to start them playing. (you could take a photo (jpg) of it and post that into in-thread).

[quote=“ethancrawford, post:84, topic:5679”]
You would place whatever you want to auto-start in here. (Which by the sound of it is a loop that then immediately syncs on an external MIDI event, so that it waits for you to start playing?).
[/quote] :+1: :+1:…

thanks

1 Like

Yes I know - is there a way to use the midi input to modify the way a sample is played the way we do for a use_synth with n,v

How do I start live_loop after previous live_loop has ended?
is there a way to fade one out and fade the next loop in?

That much is basically the same as how you would do it with synths :slightly_smiling_face:
(The sample function has many opts that you can use - so you can just give those opts values that are set in some way by the MIDI data. (Like setting the amp: based on the v that is passed through from the MIDI event, as we have done with the synths previously)).

  1. Im playing with a sample and want to manipulate it with midi inputs to distort it and pan its sound using n and v I also have access to midi pitch_bend. please show me how to do this.
  2. how do i stop the loops (1,2,3) from above code playing on and on as they start overlapping on the other loops and it compounds on and on? would be nice to have number of times that each loop plays then stops. And these loops can restart when the last loop has played its number of times than the 1st can start again.
  3. Still waiting on the answer that the code was supposed to stop after no midi input - the loops currently keep playing when midi input is stopped and they should also stop.

Hey Wro,

If you’re happy to, let’s continue this conversation elsewhere for a little while - I’ll try to help you outside of an in_thread topic :slightly_smiling_face:

Hi Ethan ok how do I do that?