def test_swing_on_off(swing): # Default is swing off assert not swing.is_swing_on() # Can override default swing_2 = Swing(swing_on=True, swing_range=SWING_RANGE, swing_direction=Swing.SwingDirection.Forward) assert swing_2.is_swing_on() # Can toggle with methods swing_2.set_swing_off() assert not swing_2.is_swing_on() swing_2.set_swing_on() assert swing_2.is_swing_on()
def test_assign_meter_swing(meter, section): new_meter = Meter(beats_per_measure=BEATS_PER_MEASURE * 2, beat_note_dur=BEAT_DUR) section.meter = new_meter assert section.meter == new_meter new_swing = Swing(swing_range=SWING_RANGE * 2) section._swing = new_swing assert section._swing == new_swing
def test_assign_swing_apply_swing(section): # Expect notes to be adjusted downward instead of upward because we use # a new Swing with SwingDirection.Reverse instead of the default Forward # Note that the first note is expected to be 0.0 and not negative because apply_swing() catches this case # and assigns any negative note.start value to 0.0 expected_swing_note_starts = [ 0.0, section[0][1].start - SWING_RANGE, section[0][2].start - SWING_RANGE, section[0][3].start - SWING_RANGE, 0.0, section[1][1].start - SWING_RANGE, section[1][2].start - SWING_RANGE, section[1][3].start - SWING_RANGE ] # Does adjust notes if swing is on new_swing = Swing(swing_range=SWING_RANGE, swing_direction=Swing.SwingDirection.Reverse, swing_jitter_type=Swing.SwingJitterType.Fixed) section.swing = new_swing section.set_swing_on().apply_swing() actual_swing_note_starts = section.get_attr('start') assert expected_swing_note_starts == pytest.approx( actual_swing_note_starts)
SCORE_HEADER = '''; Function 1 ; GEN10 Parameters: ; - str1, str2, str3 ... where str is a fixed harmonic partial ; - the value of str# is the relative strength of the partial in the final mixed timbre ; - partials to be skipped are given value 0 ; ; Func # Loadtm TblSize GEN Parameters ... ; First partial variations f 1 0 8193 10 1''' SCORE_HEADER_LINES = [SCORE_HEADER] if __name__ == '__main__': meter = Meter(beats_per_measure=BEATS_PER_MEASURE, beat_note_dur=BEAT_DUR, tempo=TEMPO_QPM) swing = Swing(swing_range=SWING_RANGE) measure = Measure(num_notes=NUM_NOTES, meter=meter, swing=swing, mn=DEFAULT_NOTE_CONFIG()) for i in range(NUM_NOTES): measure[i].instrument = INSTRUMENT_1_ID measure[i].start = (i % NUM_NOTES) * DUR measure[i].duration = DUR measure[i].amplitude = BASE_AMP measure[i].pitch = PITCH measure.apply_swing() track = Track(to_add=[measure], name='ostinato', instrument=INSTRUMENT_1_ID) song = Song(to_add=[track], name=SONG_NAME)
def swing(): return Swing(swing_range=SWING_RANGE)
def swing(): return Swing(swing_range=SWING_RANGE, swing_direction=SWING_DIRECTION, swing_jitter_type=SWING_JITTER_TYPE)
from omnisound.src.modifier.swing import Swing # Meter BEATS_PER_MEASURE = 4 BEAT_DUR = NoteDur.QUARTER # noinspection PyTypeChecker BEAT_DUR_VAL: float = BEAT_DUR.value BPM = 240 METER = Meter(beats_per_measure=BEATS_PER_MEASURE, beat_note_dur=BEAT_DUR, tempo=BPM, quantizing=True) # Swing SWING_FACTOR = 0.005 SWING = Swing(swing_on=True, swing_range=SWING_FACTOR, swing_direction=Swing.SwingDirection.Both) # Sequencer SEQUENCER_NAME = 'example_midi_sequencer_song' NUM_MEASURES = 4 MIDI_FILE_PATH = Path( '/Users/markweiss/Documents/projects/omnisound/omnisound/example/example_sequencer_song.mid' ) BASE_VELOCITY = 100 VELOCITY_FACTOR = 2 if __name__ == '__main__': def get_velocity(j, notes_per_measure): return int(BASE_VELOCITY - ((j % notes_per_measure) / VELOCITY_FACTOR))
if __name__ == '__main__': performance_attrs = PerformanceAttrs() # Declare track container ostinato_track = MidiTrack(name='ostinato', instrument=MidiInstrument.Vibraphone.value, channel=1) chords_track = MidiTrack( name='chords', instrument=MidiInstrument.Acoustic_Grand_Piano.value, channel=2) # Ostinato swing_factor = 0.008 swing = Swing(swing_on=True, swing_range=swing_factor, swing_direction=Swing.SwingDirection.Both) dur = NoteDur.THIRTYSECOND # 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) 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)