Playing with ChatGPT and Sonic Pi

Had a play with ChatGPT and Sonic Pi recently. Some asnwers quite impressive others less so. Here is one sequence. (It even coped with my miss-types!

Question: Gnerate a melody part using minor_pentatonic scale and add a percussion rhythm part in Sonic Pi

Response: Sure! Here’s an example code that generates a melody part using the minor pentatonic scale and adds a percussion rhythm part in Sonic Pi:

Code Generated:

use_bpm 120

# Define the minor pentatonic scale
minor_pentatonic = scale(:A3, :minor_pentatonic)

# Define the percussion rhythm
rhythm = (ring 1, 0.5, 0.5, 1, 0.5, 0.5)

# Define the live loop for percussion
live_loop :percussion do
  rhythm.each do |duration|
    sample :bd_haus if duration == 1
    sample :sn_dub if duration == 0.5
    sleep duration
  end
end

# Define the live loop for melody
live_loop :melody do
  # Choose a random note from the minor pentatonic scale
  note = minor_pentatonic.choose
  
  # Play the note with a random duration
  duration = [0.25, 0.5].choose
  with_fx :reverb, mix: 0.5 do
    synth :pluck, note: note, sustain: duration, release: duration
  end
  
  # Sleep for a random amount of time
  sleep [0.25, 0.5].choose
end

Explanation:
This code defines the minor_pentatonic scale and the rhythm array for the percussion part. In the live_loop for percussion, the rhythm is played using the sample command with different drum samples, creating a simple but groovy rhythm.

In the live_loop for melody, a random note is chosen from the minor_pentatonic scale and played using the synth command with a plucked sound. The with_fx command is used to add some reverb to the sound, and the sleep command is used to create a rhythmic pattern for the melody.

You can customize the minor_pentatonic scale and the rhythm array to create your own unique melody and percussion rhythm. Additionally, you can experiment with different synth sounds and effects to create a more varied and interesting sound.

I thought this was not bad at all.

2 Likes

Looks like ChatGPT did a good job with your request. I have been using it to write pieces of code in Sonic Pi and Processing, with varying degrees of success. Since I only need it to help with the more complicated code, the hardest problem is phrasing the specifications so that the AI will give a correct solution. It never says it doesn’t understand what I want. It happily (bravely? blindly? mindlessly?) spits out code, and it’s up to me to run it and see if it is what I want. Or if it runs at all. It always has complete confidence that it’s doing the right thing. It sometimes takes many iterations to work through a task.

I once asked it how it knows if it’s writing correct code. Here’s what it said:

As an AI language model, I use a combination of techniques to ensure that the code I provide is correct and meets the requirements of the task. These techniques include:

  1. Syntax checking: I perform basic syntax checking to ensure that the code is valid and free of syntax errors.

  2. Logic checking: I check that the logic of the code makes sense and is consistent with the requirements of the task.

  3. Testing: I use various test cases to verify that the code produces the correct output for different input values and scenarios. I can also verify the output provided by users to check for correctness.

  4. Experience and knowledge: I draw on my experience and knowledge of programming languages and best practices to ensure that the code is written in an appropriate and efficient manner.

While I cannot actually run the code, I can provide guidance and feedback on whether the code is likely to work correctly based on the above techniques.
<

1 Like

Hi Ken
I agree entirely with your comments. chatGPT is good to ive you some ideas, but it can produce some questionable code too. IT’s often a matter of trying to refine your qeustion to get a reasonable result. But it is fun to play with!

1 Like

I don’t think those steps describe how it actually works, just how people think a bot would write code, so that’s how ChatGPT describes the process. Reason I’m fairly confident is that it doesn’t process its output recursively. It just goes for it.