def vanDerWeijFeatures(melodyscore, segments):
    # This is radically different, we only look at features at constituent level
    melody = tools.parseScore(melodyscore)

    features = []
    index = 0
    for i in range(len(segments)):
        #if i > 0:
        #  segments[i] = [segments[i-1][len(segments[i-1])-1]] + segments[i]
        length = len(segments[i])
        # Calculate features:

        pitch_int = structure.bare_deltalist(structure.pitch, segments[i])
        abs_pitch_int = structure.absolute_deltalist(structure.pitch, segments[i])
        pitches = [structure.pitch(segments[i], j) for j in range(len(segments[i]))]
        durations = [structure.duration(segments[i], j) for j in range(len(segments[i]))]

        avg_pitch = 1/float(length) * sum(pitches)
        dPitch = 1/float(length) * sum(pitch_int)
        abs_dPitch = 1/float(length) * sum(abs_pitch_int)
        ddPitch = 1/float(length) * sum(structure.second_order_deltalist(pitch_int))
        abs_ddPitch = 1/float(length) * sum(structure.second_order_deltalist(abs_pitch_int))

        avg_duration_ratio = 0
        avg_duration = 1/float(length) * sum(durations)
        dDuration = 1/float(length) * sum(structure.bare_deltalist(structure.duration, segments[i]))
        abs_dDuration = 1/float(length) * sum(structure.absolute_deltalist(structure.duration, segments[i]))
        ddDuration = 1/float(length) * sum(structure.second_order_deltalist(structure.bare_deltalist(structure.duration, segments[i])))
        abs_ddDuration = 1/float(length) * sum(structure.second_order_deltalist(structure.absolute_deltalist(structure.duration, segments[i])))

        silence = 1/float(length) * sum([structure.silence(segments[i], j+1) for j in range(len(segments[i])-1)])

        onsets = structure.normalize([n.on for n in segments[i]])
        pitches = structure.normalize([n.pitch for n in segments[i]])
        if len(onsets) == 1:
            pitch_direction = 0
        else:
            pitch_direction = pf.linear_fit(onsets, pitches)[1]

        # Polyfony?
        # Score markings?
        features.append((avg_pitch, dPitch, abs_dPitch, ddPitch, abs_ddPitch,\
            avg_duration, dDuration, abs_dDuration, ddDuration, abs_ddDuration,\
            silence, pitch_direction, length))

#featureset = ['avg_pitch', 'dPitch', 'abs_dPitch', 'ddPitch', 'abs_ddPitch',\
#    'avg_duration', 'dDuration', 'abs_dDuration', 'ddDuration',\
#    'abs_ddDuration', 'silence', 'pitch_direction']
    return features
for feature in [structure.onset, structure.duration, structure.pitch]:
    print(">>>> {0} absolute:".format(feature))
    print(structure.absolute_deltalist(feature, notes))
    print(">>>> {0} relative:".format(feature))
    print(structure.relative_deltalist(feature, notes))


#deltas.append(normalize(square(structure.absolute_deltalist(structure.onset, notes))))
#deltas.append(normalize(structure.relative_deltalist(structure.pitch, notes)))

deltas = []
deltas.append(structure.absolute_deltalist(structure.onset, notes))
deltas.append(square(structure.absolute_deltalist(structure.pitch, notes)))

sodeltas = []
sodeltas.append(normalize(structure.second_order_deltalist(deltas[0])))
sodeltas.append(normalize(structure.second_order_deltalist(deltas[1])))


#fig = plt.figure()
#dplot = fig.add_subplot(111)
#sodplot = fig.add_subplot(111)
#dplot.plot([i for i in range(len(deltas[0]))], deltas[0])
#sodplot.plot([i for i in range(len(sodeltas[0]))], sodeltas[0])
#plt.show()

avg = normalize(avg_list(sodeltas, [1, 1]))

s = []
s.append(structure.second_order_deltarule(notes, sodeltas[0], 0.1))
s.append(structure.second_order_deltarule(notes, sodeltas[1], 0.1))
#while True:
#  print db.select()
print(">>>> Loading materials.....")

schumann = ('Schumann', 'kdz007', 'ashke', 'GPO-Concert-Steinway-ver2.sf2')
mozart1 = ('Mozart', 'snt331-3', 'nakam', 'GPO-Concert-Steinway-ver2.sf2')
chopin1 = ('Chopin', 'wlz010', 'ashke', 'Bosendorfer PIANO / GIGA')
mozart2 = ('Mozart', 'snt331-1', 'mo', None)
lastig = ('Bach', 'wtc219-f', 'richt', 'GPO-Concert-Steinway-ver2.sf2')

score = Score(db.getScore1(chopin1).stripTies())
melody = score.melody()
chopinnotes = tools.parseScore(melody)
delta = structure.absolute_deltalist(structure.onset, chopinnotes)
sodelta1 = structure.normalize(structure.second_order_deltalist(delta))

score = Score(db.getScore1(mozart2).stripTies())
melody = score.melody()
mozartnotes = tools.parseScore(melody)
delta2 = structure.square(structure.absolute_deltalist(structure.pitch, mozartnotes))
sodelta2 = structure.normalize(structure.second_order_deltalist(delta2))

s1 = structure.second_order_deltarule(chopinnotes, sodelta1, 0.1)
s2 = structure.second_order_deltarule(mozartnotes, sodelta2, 0.1)

while True:
    choice = util.menu("Select", ['Schumann exp', 'Schumann score', 'Schumann noexp', 'chopin struct', 'lastig struct bach', 'struct moz'])
    if choice == 0:
        path = db.getPerformancePath1(schumann)
        os.system("audacious {0}".format(path))