def test_nested_child_sequences(make_note_config, note_sequence): note_sequence_len = len(note_sequence) child_sequence = NoteSequence.copy(_note_sequence(mn=make_note_config)) child_sequence_len = len(child_sequence) child_child_sequence = NoteSequence.copy( _note_sequence(mn=make_note_config)) child_child_sequence_len = len(child_child_sequence) child_sequence.append_child_sequence(child_child_sequence) note_sequence.append_child_sequence(child_sequence) assert len(note_sequence.child_sequences) == 1 assert len( note_sequence ) == note_sequence_len + child_sequence_len + child_child_sequence_len
def test_copy(note_sequence): note_sequence[0].amplitude = AMP note_sequence[1].amplitude = AMP + 1 new_note_sequence = NoteSequence.copy(note_sequence) assert id(note_sequence) != id(new_note_sequence) assert new_note_sequence[0].amplitude == note_sequence[0].amplitude assert new_note_sequence[1].amplitude == note_sequence[1].amplitude
def _note(mn, attr_name_idx_map=None, attr_val_default_map=None, num_attributes=None): mn.attr_name_idx_map = attr_name_idx_map or ATTR_NAME_IDX_MAP mn.attr_val_default_map = attr_val_default_map or ATTR_VAL_DEFAULT_MAP mn.num_attributes = num_attributes or NUM_ATTRIBUTES return NoteSequence.new_note(mn)
def __setitem__(self, index: int, note_sequence: NoteSequence) -> None: validate_types(('index', index, int), ('note_sequence', note_sequence, NoteSequence)) if abs(index) >= len(self.note_seq_seq): raise IndexError( f'`index` out of range index: {index} len(note_seq_seq): {len(self.note_seq_seq)}' ) self.note_seq_seq[index] = NoteSequence.copy(note_sequence)
def test_make_notes(make_note_config, note_sequence): assert len(note_sequence) == 2 notes = note_sequence.notes() assert notes assert len(notes) == 2 child_sequence = NoteSequence.copy(_note_sequence(mn=make_note_config)) child_child_sequence = NoteSequence.copy( _note_sequence(mn=make_note_config)) child_sequence.append_child_sequence(child_child_sequence) note_sequence.append_child_sequence(child_sequence) assert len(note_sequence) == 6 notes = note_sequence.notes() assert len(notes) == 6 for note in notes: assert note.amplitude == 0.0
def test_child_sequences(make_note_config, note_sequence): child_sequence = NoteSequence.copy(note_sequence) child_sequence[0].amplitude = AMP init_len = len(note_sequence) note_sequence.append_child_sequence(child_sequence) assert len(note_sequence.child_sequences) == 1 assert len(note_sequence) == init_len + len(child_sequence) child_sequence = note_sequence.child_sequences[0] assert child_sequence[0].amplitude == AMP # Add another note_sequence child_sequence_2 = NoteSequence.copy(_note_sequence(mn=make_note_config)) note_sequence.append_child_sequence(child_sequence_2) assert len(note_sequence.child_sequences) == 2 assert len(note_sequence ) == init_len + len(child_sequence) + len(child_sequence_2) # NOTE: IF WE ADD A SEQUENCE TO ITSELF IT IS A CYCLE AND WE ARE IN INFINITE LOOP # Validate that attempting to create a cycle by appending a note to be its own child raises with pytest.raises(ValueError): note_sequence.append_child_sequence(note_sequence)
def test_note_sequence_insert_remove_getitem(make_note_config): note_sequence = NoteSequence(num_notes=NUM_NOTES, mn=make_note_config) # Get the first note in the sequence, and get its amplitude note_front = note_sequence.note(0) note_front_amp = note_front.amplitude # Insert a new note at the front of the sequence, with a different amplitude new_amp = AMP + 1 new_note = _note(mn=make_note_config) new_note.amplitude = new_amp note_sequence.insert(0, new_note) new_note_front = note_sequence[0] new_note_front_amp = new_note_front.amplitude # Assert that the new note inserted can be retrieved and is the expected new first note assert note_front_amp != new_note_front_amp assert new_note_front_amp == new_amp # After removing a note, the new front note is the one added second to most recently expected_amp = note_sequence[1].amplitude note_sequence.remove((0, 1)) note_front = note_sequence[0] assert expected_amp == note_front.amplitude
def copy(other: 'NoteSequenceSequence'): return NoteSequenceSequence( [NoteSequence.copy(note_seq) for note_seq in other.note_seq_seq])
def note_sequence(make_note_config): return NoteSequence(num_notes=NUM_NOTES, mn=make_note_config)
def test_eq(note_sequence): new_note_sequence = NoteSequence.copy(note_sequence) assert note_sequence == new_note_sequence note_sequence[0].amplitude = AMP assert note_sequence != new_note_sequence
def _note_sequence(mn=None, attr_name_idx_map=None, num_attributes=None): mn.attr_name_idx_map = attr_name_idx_map or ATTR_NAME_IDX_MAP mn.num_attributes = num_attributes or NUM_ATTRIBUTES return NoteSequence(num_notes=NUM_NOTES, mn=mn)
for _ in range(NUM_MEASURES): note_config = MakeNoteConfig.copy(NOTE_CONFIG) ostinato_measure = Measure(num_notes=notes_per_measure, meter=METER, swing=swing, mn=note_config) for i in range(notes_per_measure): note_values = NoteValues(ATTR_NAMES) note_values.time = i * dur_val note_values.duration = dur_val note_values.velocity = int(BASE_VELOCITY - ( (i % notes_per_measure) / VELOCITY_FACTOR)) note_values.pitch = SCALE[i % NUM_NOTES_IN_SCALE].pitch note_config.attr_val_default_map = note_values.as_dict() note = NoteSequence.new_note(note_config) ostinato_measure.append(note) ostinato_measure.apply_swing() ostinato_track.append(ostinato_measure) # Chords octave = OCTAVE - 2 dur = NoteDur.WHOLE # noinspection PyTypeChecker dur_val: float = dur.value notes_per_measure = int((1 / dur_val) * (BEATS_PER_MEASURE * BEAT_DUR_VAL)) for _ in range(NUM_MEASURES): note_config = MakeNoteConfig.copy(NOTE_CONFIG) chords_measure = Measure(meter=METER, swing=swing,
note_config.synth_def = fd_sc_synth note_config.amp = 1.0 note_config.oct = 2 note_config.scale = 'lydian' idur = 1.0 delay = 0.0 for i in range(15): note_config.delay = int(round(delay, 5)) note_config.dur = round(idur - ((i + 1) * 0.05), 5) note_config.degree = i % 5 note = FoxDotSupercolliderNote(**note_config.as_dict(), performance_attrs=performance_attrs) notes.append(note) delay += note_config.dur note_sequence = NoteSequence(notes) player = FoxDotSupercolliderPlayer(note_sequence) player.play_each() sleep(3) notes = [] note_config.name = 'test_note' note_config.synth_def = fd_sc_synth note_config.amp = 1.0 note_config.oct = 5 note_config.scale = 'chromatic' idur = 1.0 delay = 0.0 for i in range(15): note_config.delay = round(delay, 5)