Length note property

I can’t get this to work:

def basson01a():
    basson_pitch_01a  = [48,  43,  46,  48, 50,  51,  50, 48, 43]
    basson_durs_01a   = [1,   .5,  .5,  1,  1,   1.5, .5, 1,  1]
    basson_vol_01a    = [.8,  .6,  .75, .9, .6,  .8,  .7, .7, .9]
    basson_length_01a = [.5,  .5,  .5,  .5, .9,  .9,  .2, .2, 1]
    for pitch, volume, duration, length in zip(basson_pitch_01a, basson_vol_01a, basson_durs_01a, basson_length_01a):
        basson.play_note(pitch, volume, duration, length)

Everything works, except the note property “length”, which gives me this error:

ValueError: 0.5 not interpretable as NoteProperties.

Probably a misunderstanding on my part, but I’ve been looking for hours and I can’t find it.
A little help would be appreciated :slight_smile:

Hi, What do you want to do with the variable ‘length’ (as basson_durs_01a[] list sets the durations of notes?

I want to slightly modify the duration of the sound rendering for the note, without affecting its transcription in the score… “length” is used for that, I believe?

from random import randrange

create your basson_length_01a = [.5, .5, .5, .5, .9, .9, .2, .2, 1] array
as integers
basson_length_01a = [50, 50, 50, 50, 90, 90, 20, 20, 100]
variation = 5 # 5%

replace length in the play_note with randrange(length-variation,length+variation)/100.00

then your length will randomly change between length +/- 5%
you could put randrange in a function to make the code read nicer

def randlength(length,variation):
    return randrange(length-variation,length+variation)/100.00

Thank you… yes, I understand what you mean. But in my case, I just want to accurately note the duration as I see fit. Nothing random there. just – maybe – a bit of a manic concern.

Ah, I think I finally understand the question. You’re trying to use the note properties argument to adjust the playback length of the note. What you want is something like this:

def basson01a():
    basson_pitch_01a  = [48,  43,  46,  48, 50,  51,  50, 48, 43]
    basson_durs_01a   = [1,   .5,  .5,  1,  1,   1.5, .5, 1,  1]
    basson_vol_01a    = [.8,  .6,  .75, .9, .6,  .8,  .7, .7, .9]
    basson_length_01a = [.5,  .5,  .5,  .5, .9,  .9,  .2, .2, 1]
    for pitch, volume, duration, length in zip(basson_pitch_01a, basson_vol_01a, basson_durs_01a, basson_length_01a):
        basson.play_note(pitch, volume, duration, NotePlaybackAdjustment.set_params(length=length))
        

Or alternatively, you could use this shorthand:

basson.play_note(pitch, volume, duration, f"length={length}")

Thank you for the answer :slight_smile:

In fact, what I want to do precisely is to multiply the value of the duration of the notes by the value “length”.
Example: having a note with a duration of 1 that I only hear for a duration of 0.6.
Value written in score: 1
Value heard during this duration of 1: 0.6

I do not know if it’s clear?

Using your example, I tried this:

def bassoon01a():
     bassoon_pitch_01a = [48, 43, 46, 48, 50, 51, 50, 48, 43]
     bassoon_dur_01a = [1, .5, .5, 1, 1, 1.5, .5, 1, 1]
     bassoon_vol_01a = [.8, .6, .75,.9, .6, .8, .7, .7, .9]
     bassoon_length_01a = [.5, .5, .5, .5, .9, .9, .2, .2, 1]
     for pitch, volume, duration, length in zip(
         bassoon_pitch_01a, bassoon_dur_01a, bassoon_vol_01a, bassoon_length_01a):
         bassoon.play_note(pitch, volume, duration, NotePlaybackAdjustment.set_params(length=duration*length))
bassoon01a()

But it doesn’t do what I’m trying to do…

Ooups ! It was just misordered variables. Now it’s ok with this:

    for pitch, volume, duration, length in zip(
        basson_pitch_01a, basson_vol_01a, basson_dur_01a, basson_length_01a):
        basson.play_note(pitch, volume, duration, NotePlaybackAdjustment.set_params(length=length*duration))

I had :
basson_pitch_01a, basson_dur_01a, basson_vol_01a, basson_length_01a)
and now :
basson_pitch_01a, basson_vol_01a, basson_dur_01a, basson_length_01a)

…and it works!

Thank you all for the help and attention :slight_smile:

1 Like