Skip to content

Ed constants cannot be used in list initialization #3

@PSLLSP

Description

@PSLLSP

I cannot use constants from Ed module to initialize a list. I think that Ed.NOTE_C_7 is just a constant, is't it? There is a commented line that generates syntax error and more workaround follows.

list in EdPy is just a fixed size array of integers. Is it allocated during compile time? If it is allocated by compiler, why I can do buffer overflow (opera[5] = Ed.NOTE_C_8). This line is real troublemaker...

#-------------Setup----------------

import Ed

Ed.EdisonVersion = Ed.V2

Ed.DistanceUnits = Ed.CM
Ed.Tempo = Ed.TEMPO_MEDIUM

#--------Your code below-----------

# SYNTAX ERROR: LIST INIT code too complex for EdPy :-(
# opera = Ed.List(5, [Ed.NOTE_C_7, Ed.NOTE_D_7, Ed.NOTE_E_7, Ed.NOTE_G_7, Ed.NOTE_A_7])

opera = Ed.List(5)
opera[0] = Ed.NOTE_C_7
opera[1] = Ed.NOTE_D_7
opera[2] = Ed.NOTE_E_7
opera[3] = Ed.NOTE_G_7
opera[4] = Ed.NOTE_A_7
opera[5] = Ed.NOTE_C_8  # This is a buffer overflow, not found by compiler!

# this part doesn't work well when opera[5] is defined. Bug that is difficult to find... :-(
for note in opera:
    Ed.PlayTone(note, Ed.NOTE_HALF)
    while Ed.ReadMusicEnd() == Ed.MUSIC_NOT_FINISHED: pass
    Ed.TimeWait(100, Ed.TIME_MILLISECONDS)

# this works ok
Ed.PlayBeep()
waitMusicEnd()
Ed.TimeWait(100, Ed.TIME_MILLISECONDS)

playNote(Ed.NOTE_C_7)
playNote(Ed.NOTE_D_7)
playNote(Ed.NOTE_E_7)
playNote(Ed.NOTE_G_7)
playNote(Ed.NOTE_A_7)

def playNote(note):
    Ed.PlayTone(note, Ed.NOTE_HALF)
    #while Ed.ReadMusicEnd() == Ed.MUSIC_NOT_FINISHED: pass
    waitMusicEnd()
    Ed.TimeWait(100, Ed.TIME_MILLISECONDS)

def waitMusicEnd():
    while Ed.ReadMusicEnd() == Ed.MUSIC_NOT_FINISHED: pass

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions