# Glissando between notes (David Collett, Jan 20, 2023)

# This example uses 2 instruments: the flute glissandos up while the space_voice goes down; both notes play together.
# You can input the low and high notes (these can be MIDI note numbers or any decimal values between for microtonal)
# You can also set the increment (inc) size you want. 0.2 seems to work well, but experiment for the sound you want.
# In line 20, you can set the total time the glissando will take between the low and high notes (0.5 = 8th note, for example).
# You can uncomment the 3 print() lines if you want to see the values.
# Finally, the two lines at the bottom may be necessary if your notes hold over.

# The first one you hear is an ascending glissando for the flute.
# The next one is descending.
# The last one is the flute ascending at the same time the space_voice is descending (both played together).

from scamp import *

s = Session()
pan_flute = s.new_part("Pan Flute")
space_voice = s.new_part("Space Voice")

low_note = 60
high_note = 67
cur_low_note = low_note
cur_high_note = high_note

num_semitones = high_note - low_note

inc = 0.2                           # number of semitones to skip at every step
tot_steps = num_semitones / inc     # total number of steps required between notes

desired_time_between_hi_low = 0.5   # number of secs to slide from low to high notes (Ex: 0.5 is 8th note; 0.25 is 16th note; can be any decimal value

inc_speed = desired_time_between_hi_low * (inc / num_semitones) # number of seconds between each small step

# print("num_semitones =", num_semitones)
# print("tot_steps =", tot_steps)
# print("inc_speed =", inc_speed)


while cur_low_note < high_note:
    pan_flute.play_note(cur_low_note, 1.0, inc_speed) # so both notes play together
    cur_low_note += inc
wait(1.0)


while cur_high_note > low_note:
    pan_flute.play_note(cur_high_note, 1.0, inc_speed) # so both notes play together
    cur_high_note -= inc
wait(1.0)



low_note = 60
high_note = 67
cur_low_note = low_note
cur_high_note = high_note

while cur_low_note < high_note:
    pan_flute.play_note(cur_low_note, 1.0, inc_speed, blocking=False) # so both notes play together
    space_voice.play_note(cur_high_note, 0.5, inc_speed)
    cur_low_note += inc
    cur_high_note -= inc
   
#pan_flute.end_all_notes()          # may be necessary if using Thonny to prevent sound continuing
#space_voice.end_all_notes()