Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion AugmentedNet/feature_representation.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,15 @@
"D8": "M7",
}

HARMONICRHYTHM = [0, 1, 2, 3, 4, 5, 6]
NOTEDURATIONS = [
0, # onset
1, # thirtysecond
2, # sixteenth
3, # eighth
4, # quarter
5, # half
6, # whole
]


class FeatureRepresentation(object):
Expand Down
109 changes: 107 additions & 2 deletions AugmentedNet/input_representations.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,11 @@
m21IntervalStr,
)
from .feature_representation import (
PITCHCLASSES,
INTERVALCLASSES,
NOTEDURATIONS,
NOTENAMES,
PITCHCLASSES,
SPELLINGS,
INTERVALCLASSES,
FeatureRepresentation,
FeatureRepresentationTI,
)
Expand All @@ -39,6 +40,109 @@
# diff = pc -


class Duration14(FeatureRepresentationTI):
features = 2 * len(NOTEDURATIONS)
pattern = [
[1, 0, 0, 0, 0, 0, 0],
[0, 1, 0, 0, 0, 0, 0],
[0, 0, 1, 0, 0, 0, 0],
[0, 1, 1, 0, 0, 0, 0],
[0, 0, 0, 1, 0, 0, 0], # eight
[0, 1, 0, 1, 0, 0, 0],
[0, 0, 1, 1, 0, 0, 0],
[0, 1, 1, 1, 0, 0, 0],
[0, 0, 0, 0, 1, 0, 0], # quarter
[0, 1, 0, 0, 1, 0, 0],
[0, 0, 1, 0, 1, 0, 0],
[0, 1, 1, 0, 1, 0, 0],
[0, 0, 0, 1, 1, 0, 0],
[0, 1, 0, 1, 1, 0, 0],
[0, 0, 1, 1, 1, 0, 0],
[0, 1, 1, 1, 1, 0, 0],
[0, 0, 0, 0, 0, 1, 0], # half
[0, 1, 0, 0, 0, 1, 0],
[0, 0, 1, 0, 0, 1, 0],
[0, 1, 1, 0, 0, 1, 0],
[0, 0, 0, 1, 0, 1, 0],
[0, 1, 0, 1, 0, 1, 0],
[0, 0, 1, 1, 0, 1, 0],
[0, 1, 1, 1, 0, 1, 0],
[0, 0, 0, 0, 1, 1, 0],
[0, 1, 0, 0, 1, 1, 0],
[0, 0, 1, 0, 1, 1, 0],
[0, 1, 1, 0, 1, 1, 0],
[0, 0, 0, 1, 1, 1, 0],
[0, 1, 0, 1, 1, 1, 0],
[0, 0, 1, 1, 1, 1, 0],
[0, 1, 1, 1, 1, 1, 0],
[0, 0, 0, 0, 0, 0, 1], # whole
[0, 1, 0, 0, 0, 0, 1],
[0, 0, 1, 0, 0, 0, 1],
[0, 1, 1, 0, 0, 0, 1],
[0, 0, 0, 1, 0, 0, 1],
[0, 1, 0, 1, 0, 0, 1],
[0, 0, 1, 1, 0, 0, 1],
[0, 1, 1, 1, 0, 0, 1],
[0, 0, 0, 0, 1, 0, 1],
[0, 1, 0, 0, 1, 0, 1],
[0, 0, 1, 0, 1, 0, 1],
[0, 1, 1, 0, 1, 0, 1],
[0, 0, 0, 1, 1, 0, 1],
[0, 1, 0, 1, 1, 0, 1],
[0, 0, 1, 1, 1, 0, 1],
[0, 1, 1, 1, 1, 0, 1],
[0, 0, 0, 0, 0, 1, 1],
[0, 1, 0, 0, 0, 1, 1],
[0, 0, 1, 0, 0, 1, 1],
[0, 1, 1, 0, 0, 1, 1],
[0, 0, 0, 1, 0, 1, 1],
[0, 1, 0, 1, 0, 1, 1],
[0, 0, 1, 1, 0, 1, 1],
[0, 1, 1, 1, 0, 1, 1],
[0, 0, 0, 0, 1, 1, 1],
[0, 1, 0, 0, 1, 1, 1],
[0, 0, 1, 0, 1, 1, 1],
[0, 1, 1, 0, 1, 1, 1],
[0, 0, 0, 1, 1, 1, 1],
[0, 1, 0, 1, 1, 1, 1],
[0, 0, 1, 1, 1, 1, 1],
[0, 1, 1, 1, 1, 1, 1],
]

def run(self):
array = np.zeros(self.shape, dtype=self.dtype)
prev_measure = -1
idx = 0
for frame, measure in enumerate(self.df.s_measure):
if measure != prev_measure:
idx = 0
prev_measure = measure
pattern = self.pattern[idx]
array[frame, 0:7] = pattern
idx += 1
idx = 0
for frame, onset in enumerate(self.df.s_isOnset):
if sum(onset) > 0:
idx = 0
pattern = self.pattern[idx]
array[frame, 7:] = pattern
idx += 1
return array

@classmethod
def decode(cls, array):
if len(array.shape) != 2 or array.shape[1] != cls.features:
raise IndexError("Strange array shape.")
ret = []
for manyhot in array:
measureOnset = [
NOTEDURATIONS[x] for x in np.nonzero(manyhot[:7])[0]
]
noteOnset = [NOTEDURATIONS[x] for x in np.nonzero(manyhot[7:])[0]]
ret.append((tuple(measureOnset), tuple(noteOnset)))
return ret


class Bass19(FeatureRepresentation):
features = len(NOTENAMES) + len(PITCHCLASSES)

Expand Down Expand Up @@ -267,6 +371,7 @@ def decode(cls, array):
"Bass35": Bass35,
"Chromagram19": Chromagram19,
"Chromagram35": Chromagram35,
"Duration14": Duration14,
"Intervals39": Intervals39,
"Intervals19": Intervals19,
"BassChromagram38": BassChromagram38,
Expand Down
5 changes: 2 additions & 3 deletions AugmentedNet/output_representations.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,12 @@
TransposePitch,
)
from .feature_representation import (
HARMONICRHYTHM,
FeatureRepresentation,
FeatureRepresentationTI,
CHORD_QUALITIES,
COMMON_ROMAN_NUMERALS,
DEGREES,
HARMONICRHYTHM,
NOTEDURATIONS,
KEYS,
PCSETS,
SPELLINGS,
Expand Down Expand Up @@ -124,7 +123,7 @@ def run(self):


class HarmonicRhythm7(OutputRepresentationTI):
classList = HARMONICRHYTHM
classList = NOTEDURATIONS
dfFeature = "a_harmonicRhythm"


Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
[
[[0], [0]],
[[1], [1]],
[[2], [2]],
[[1, 2], [1, 2]],
[[3], [0]],
[[1, 3], [1]],
[[2, 3], [2]],
[[1, 2, 3], [1, 2]],
[[4], [0]],
[[1, 4], [1]],
[[2, 4], [2]],
[[1, 2, 4], [1, 2]],
[[0], [0]],
[[1], [1]],
[[2], [2]],
[[1, 2], [1, 2]],
[[3], [3]],
[[1, 3], [1, 3]],
[[2, 3], [2, 3]],
[[1, 2, 3], [1, 2, 3]],
[[4], [4]],
[[1, 4], [1, 4]],
[[2, 4], [2, 4]],
[[1, 2, 4], [1, 2, 4]],
[[0], [0]],
[[1], [1]],
[[2], [2]],
[[1, 2], [1, 2]],
[[3], [0]],
[[1, 3], [1]],
[[2, 3], [2]],
[[1, 2, 3], [1, 2]],
[[4], [0]],
[[1, 4], [1]],
[[2, 4], [2]],
[[1, 2, 4], [1, 2]],
[[0], [0]],
[[1], [1]],
[[2], [2]],
[[1, 2], [1, 2]],
[[3], [0]],
[[1, 3], [1]],
[[2, 3], [2]],
[[1, 2, 3], [1, 2]],
[[4], [0]],
[[1, 4], [1]],
[[2, 4], [2]],
[[1, 2, 4], [1, 2]],
[[0], [0]],
[[1], [1]],
[[2], [2]],
[[1, 2], [1, 2]],
[[3], [0]],
[[1, 3], [1]],
[[2, 3], [2]],
[[1, 2, 3], [1, 2]],
[[4], [0]],
[[1, 4], [1]],
[[2, 4], [2]],
[[1, 2, 4], [1, 2]],
[[0], [0]],
[[1], [1]],
[[2], [2]],
[[1, 2], [1, 2]]
]
64 changes: 64 additions & 0 deletions test/auxiliary_files/input_representations/haydnDuration14GT.out
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
1 0 0 0 0 0 0 1 0 0 0 0 0 0
0 1 0 0 0 0 0 0 1 0 0 0 0 0
0 0 1 0 0 0 0 0 0 1 0 0 0 0
0 1 1 0 0 0 0 0 1 1 0 0 0 0
0 0 0 1 0 0 0 1 0 0 0 0 0 0
0 1 0 1 0 0 0 0 1 0 0 0 0 0
0 0 1 1 0 0 0 0 0 1 0 0 0 0
0 1 1 1 0 0 0 0 1 1 0 0 0 0
0 0 0 0 1 0 0 1 0 0 0 0 0 0
0 1 0 0 1 0 0 0 1 0 0 0 0 0
0 0 1 0 1 0 0 0 0 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0 1 0 0 0 1 1 0 0 0 0
1 0 0 0 0 0 0 1 0 0 0 0 0 0
0 1 0 0 0 0 0 0 1 0 0 0 0 0
0 0 1 0 0 0 0 0 0 1 0 0 0 0
0 1 1 0 0 0 0 0 1 1 0 0 0 0
0 0 0 1 0 0 0 1 0 0 0 0 0 0
0 1 0 1 0 0 0 0 1 0 0 0 0 0
0 0 1 1 0 0 0 0 0 1 0 0 0 0
0 1 1 1 0 0 0 0 1 1 0 0 0 0
0 0 0 0 1 0 0 1 0 0 0 0 0 0
0 1 0 0 1 0 0 0 1 0 0 0 0 0
0 0 1 0 1 0 0 0 0 1 0 0 0 0
0 1 1 0 1 0 0 0 1 1 0 0 0 0
1 0 0 0 0 0 0 1 0 0 0 0 0 0
0 1 0 0 0 0 0 0 1 0 0 0 0 0
0 0 1 0 0 0 0 0 0 1 0 0 0 0
0 1 1 0 0 0 0 0 1 1 0 0 0 0
Binary file modified test/haydn.png
100644 → 100755
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
27 changes: 27 additions & 0 deletions test/test_input_representations.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
BassChromagram38,
BassChromagram70,
BassIntervals58,
Duration14,
Intervals19,
)
from AugmentedNet.joint_parser import J_LISTTYPE_COLUMNS
Expand Down Expand Up @@ -38,6 +39,32 @@ def _save(arr):
np.savetxt("tmp.txt", arr, fmt="%i", delimiter=" ")


class TestDuration14(unittest.TestCase):
def setUp(self):
self.maxDiff = None
self.df = _load_dfgt(aux.haydn)
self.timesteps = len(self.df.index)
self.transpositions = ["m2", "M6", "P5", "d7"]

def test_encoding(self):
encoding = Duration14(self.df).array
encodingGT = np.loadtxt(aux.haydnDuration14GT, dtype="i1")
for timestep in range(self.timesteps):
with self.subTest(timestep=timestep):
ar = np.nonzero(encoding[timestep])
arGT = np.nonzero(encodingGT[timestep])
self.assertEqual(tuple(ar[0]), tuple(arGT[0]))

def test_decoding(self):
encoding = Duration14(self.df).array
decoded = Duration14.decode(encoding)
decodedGT = aux.haydnDuration14DecodedGT
decodedGT = [(tuple(t[0]), tuple(t[1])) for t in decodedGT]
for timestep in range(self.timesteps):
with self.subTest(timestep=timestep):
self.assertEqual(decoded[timestep], decodedGT[timestep])


class TestBassChromagram38(unittest.TestCase):
def setUp(self):
self.maxDiff = None
Expand Down