def test_strech_is_reversable(self): """ Ensure that stretch and contract is an identity operation """ from sebastian.core.transforms import stretch s1 = self.make_sequence() stretched = s1 | stretch(2) | stretch(0.5) self.assertEqual(s1._elements, stretched._elements)
def chord_scaled(arr, scale, period=12): ''' Scales an note's array ''' remainder = arr.size % period if remainder: fill = period - remainder arr = np.append(arr, np.zeros(fill) * np.nan) arr_scaled = np.int32([np.nansum(row) / len(row) for row in arr.reshape((-1, period))]) root_scaled = [note_on_classes(note, arr, scale) for note in arr_scaled] root = [] third = [] fifth = [] for note in root_scaled: root.append(note_name(note, scale)) third.append(note_name(note, scale)) fifth.append(note_name(note, scale)) seq1 = parse(" ".join(root)) seq2 = parse(" ".join(third)) seq3 = parse(" ".join(fifth)) # chords = (seq1 * period) // (seq2 * period) // (seq3 * period) chords = seq1 // seq2 // seq3 # return (chords | add({DURATION_64: chords[0][DURATION_64] * period})) return (chords | stretch(period))
def test_stretch(self): """ Ensure that strech modifies a simple sequence """ from sebastian.core.transforms import stretch s1 = self.make_sequence() streched = s1 | stretch(2) from sebastian.core import OFFSET_64, DURATION_64, MIDI_PITCH self.assertEqual(streched._elements, [ {MIDI_PITCH: 50, OFFSET_64: 32, DURATION_64: 34}, {MIDI_PITCH: 53, OFFSET_64: 38, DURATION_64: 40} ])
def test_stretch(self): """ Ensure that strech modifies a simple sequence """ from sebastian.core.transforms import stretch s1 = self.make_sequence() streched = s1 | stretch(2) from sebastian.core import OFFSET_64, DURATION_64 self.assertEqual(streched._elements, [{ "pitch": 50, OFFSET_64: 32, DURATION_64: 34 }, { "pitch": 53, OFFSET_64: 38, DURATION_64: 40 }])
assert s1 | transpose(5) | transpose(-5) == s1 # reverse assert (s1 | reverse())._elements == [ {MIDI_PITCH: 52, OFFSET_64: 0, DURATION_64: 16}, {MIDI_PITCH: 50, OFFSET_64: 16, DURATION_64: 16}, {OFFSET_64: 48} ] assert s1 | reverse() | reverse() == s1 # stretch assert (s1 | stretch(2))._elements == [ {MIDI_PITCH: 50, OFFSET_64: 32, DURATION_64: 32}, {MIDI_PITCH: 52, OFFSET_64: 64, DURATION_64: 32} ] assert s1 | stretch(2) | stretch(0.5) == s1 # invert assert (s1 | invert(50))._elements == [ {DURATION_64: 16, OFFSET_64: 16, MIDI_PITCH: 50}, {DURATION_64: 16, OFFSET_64: 32, MIDI_PITCH: 48} ] assert s1 | invert(100) | invert(100) == s1