def test_key_on_full_config(self): channel = 1 operator = 1 enabled_operator = Operators.CAR1 # Add noise freq (Basic Config) self.state.apply(create(0x0F, 0x1)) # Add Connection (Channel Config) self.state.apply(create(0x20 | channel, 1)) # Add Phase Multiply (Operator Config) self.state.apply(create(0x40 | operator << 3 | channel, 1)) self.assertEqual(len(self.state.configs), 0) # Play note self.state.apply(create(0x08, enabled_operator << 3 | channel)) self.assertEqual(len(self.state.configs), 1) # Play note again self.state.apply(create(0x08, enabled_operator << 3 | channel)) self.assertEqual(len(self.state.configs), 1) # Check Noise Freq (Basic Config) self.assertEqual(self.state.configs[0].noise_freq, 1) # Check Connection (Channel Config) self.assertEqual(self.state.configs[0].connection, 1) # Check Phase Multiply (Operator Config) self.assertEqual(self.state.configs[0].operators[operator].multiply, 1) # Check Active Operators (Note Config) self.assertEqual(self.state.configs[0].enabled_operators, enabled_operator)
def test_key_on_different_notes(self): channel = 1 operator = 1 enabled_operator = Operators.CAR1 # Play note self.state.apply(create(0x08, enabled_operator << 3 | channel)) self.assertEqual(len(self.state.configs), 1) self.assertEqual(len(self.state.key_presses(channel)), 1) self.assertEqual(self.state.key_presses(channel)[0].octave, 0) self.assertEqual(self.state.key_presses(channel)[0].note, 0) self.assertEqual(self.state.key_presses(channel)[0].key_fraction, 0) # Set different note self.state.apply(create(0x28 | channel, 0x1)) # Play note with new config self.state.apply(create(0x08, enabled_operator << 3 | channel)) self.assertEqual(len(self.state.configs), 1) self.assertEqual(len(self.state.key_presses(channel)), 2) self.assertEqual(self.state.key_presses(channel)[0].octave, 0) self.assertEqual(self.state.key_presses(channel)[0].note, 0) self.assertEqual(self.state.key_presses(channel)[0].key_fraction, 0) self.assertEqual(self.state.key_presses(channel)[1].octave, 0) self.assertEqual(self.state.key_presses(channel)[1].note, 1) self.assertEqual(self.state.key_presses(channel)[1].key_fraction, 0)
def test_apply_key_on_reuse_sample_many_notes(self): self.state.apply(create(0x08, (1 << 3) | 5)) self.assertEqual(len(self.state.configs), 1) self.assertEqual(len(self.state.key_presses(5)), 1) self.assertEqual(self.state.key_presses(5)[0].config_id, 0) self.assertEqual(self.state.configs[0].lfo, 0) self.state.apply(create(0x18, 0x55)) self.state.apply(create(0x08, (1 << 3) | 5)) self.assertEqual(len(self.state.configs), 2) self.assertEqual(len(self.state.key_presses(5)), 2) self.assertEqual(self.state.key_presses(5)[1].config_id, 1) self.assertEqual(self.state.configs[0].lfo, 0) self.assertEqual(self.state.configs[1].lfo, 0x55) self.state.apply(create(0x18, 0x0)) self.state.apply(create(0x08, (1 << 3) | 5)) self.assertEqual(len(self.state.configs), 2) self.assertEqual(len(self.state.key_presses(5)), 3) self.assertEqual(self.state.key_presses(5)[2].config_id, 0) self.assertEqual(self.state.configs[0].lfo, 0) self.assertEqual(self.state.configs[1].lfo, 0x55)
def test_apply_ctrl_output(self): self.assertFalse(self.state.ct1) self.assertFalse(self.state.ct2) self.assertEqual(self.state.waveform, Waveform.SAW) self.state.apply(create(0x1B, 1 << 7)) self.assertFalse(self.state.ct1) self.assertTrue(self.state.ct2) self.assertEqual(self.state.waveform, Waveform.SAW) self.state.apply(create(0x1B, (1 << 6) | (1 << 7))) self.assertTrue(self.state.ct1) self.assertTrue(self.state.ct2) self.assertEqual(self.state.waveform, Waveform.SAW) self.state.apply(create(0x1B, (1 << 6))) self.assertTrue(self.state.ct1) self.assertFalse(self.state.ct2) self.assertEqual(self.state.waveform, Waveform.SAW) self.state.apply(create(0x1B, (1 << 7) | 2)) self.assertFalse(self.state.ct1) self.assertTrue(self.state.ct2) self.assertEqual(self.state.waveform, Waveform.TRIANGLE)
def test_apply_key_on_simple_multiple_samples(self): self.state.apply(create(0x08, (1 << 3) | 5)) self.assertEqual(len(self.state.configs), 1) self.assertEqual(len(self.state.key_presses(5)), 1) self.assertEqual(self.state.key_presses(5)[0].config_id, 0) self.assertEqual(self.state.configs[0].lfo, 0) self.state.apply(create(0x18, 0x55)) self.state.apply(create(0x08, (1 << 3) | 5)) self.assertEqual(len(self.state.configs), 2) self.assertEqual(len(self.state.key_presses(5)), 2) self.assertEqual(self.state.key_presses(5)[1].config_id, 1) self.assertEqual(self.state.configs[0].lfo, 0) self.assertEqual(self.state.configs[1].lfo, 0x55) self.state.apply(create(0x0F, (1 << 7))) self.state.apply(create(0x08, (1 << 3) | 3)) self.assertEqual(len(self.state.configs), 3) self.assertEqual(len(self.state.key_presses(3)), 1) self.assertEqual(self.state.key_presses(3)[0].config_id, 2) self.assertEqual(self.state.configs[0].lfo, 0) self.assertEqual(self.state.configs[0].noise, False) self.assertEqual(self.state.configs[1].lfo, 0x55) self.assertEqual(self.state.configs[1].noise, False) self.assertEqual(self.state.configs[2].lfo, 0x55) self.assertEqual(self.state.configs[2].noise, True)
def test_apply_channel_control_left_right_multiple_channels(self): ch = 1 self.assertFalse(self.state.channel_config(ch).right) self.assertFalse(self.state.channel_config(ch).left) self.state.apply(create(0x20 | ch, (1 << 7))) self.assertTrue(self.state.channel_config(ch).right) self.assertFalse(self.state.channel_config(ch).left) ch = 2 self.state.apply(create(0x20 | ch, (1 << 6))) self.assertFalse(self.state.channel_config(ch).right) self.assertTrue(self.state.channel_config(ch).left) self.assertTrue(self.state.channel_config(1).right) self.assertFalse(self.state.channel_config(1).left)
def test_key_on_old_sample(self): channel = 1 operator = 1 enabled_operator = Operators.CAR1 # Play note self.state.apply(create(0x08, enabled_operator << 3 | channel)) self.assertEqual(len(self.state.configs), 1) # Add noise freq (Basic Config) self.state.apply(create(0x0F, 0x1)) # Add Connection (Channel Config) self.state.apply(create(0x20 | channel, 1)) # Add Phase Multiply (Operator Config) self.state.apply(create(0x40 | operator << 3 | channel, 1)) # Play note with new config self.state.apply(create(0x08, enabled_operator << 3 | channel)) self.assertEqual(len(self.state.configs), 2) # Add noise freq (Basic Config) self.state.apply(create(0x0F, 0x0)) # Add Connection (Channel Config) self.state.apply(create(0x20 | channel, 0)) # Add Phase Multiply (Operator Config) self.state.apply(create(0x40 | operator << 3 | channel, 0)) # Play note again with old config self.state.apply(create(0x08, enabled_operator << 3 | channel)) # Check no new configs stored self.assertEqual(len(self.state.configs), 2) # Config 0 # Check Noise Freq (Basic Config) self.assertEqual(self.state.configs[0].noise_freq, 0) # Check Connection (Channel Config) self.assertEqual(self.state.configs[0].connection, 0) # Check Phase Multiply (Operator Config) self.assertEqual(self.state.configs[0].operators[operator].multiply, 0) # Check Active Operators (Note Config) self.assertEqual(self.state.configs[0].noise_freq, 0) # Config 1 # Check Noise Freq (Basic Config) self.assertEqual(self.state.configs[1].noise_freq, 1) # Check Connection (Channel Config) self.assertEqual(self.state.configs[1].connection, 1) # Check Phase Multiply (Operator Config) self.assertEqual(self.state.configs[1].operators[operator].multiply, 1) # Check Active Operators (Note Config) self.assertEqual(self.state.configs[1].noise_freq, 1)
def test_apply_key_on_simple(self): self.assertEqual(len(self.state.configs), 0) self.state.apply(create(0x08, (1 << 3) | 5)) self.assertEqual(len(self.state.key_presses(5)), 1) self.assertListEqual(self.state.key_presses(0), []) self.assertEqual(self.state.key_presses(5)[0].config_id, 0) self.assertEqual(len(self.state.configs), 1)
def test_apply_amp_md(self): depth = 0x55 cmd = create(0x19, depth) self.assertEqual(self.state.phs_md, 0) self.assertEqual(self.state.amp_md, 0) self.state.apply(cmd) self.assertEqual(self.state.phs_md, 0) self.assertEqual(self.state.amp_md, depth)
def test_apply_noise_freq(self): freq = 0x1F cmd = create(0x0F, freq) self.assertFalse(self.state.noise) self.assertEqual(self.state.noise_freq, 0) self.state.apply(cmd) self.assertFalse(self.state.noise) self.assertEqual(self.state.noise_freq, freq)
def test_apply_key_off(self): self.assertEqual(len(self.state.configs), 0) self.assertListEqual(self.state.key_presses(0), []) self.assertEqual(self.state.key_presses(1), []) self.state.apply(create(0x08, 0x00)) self.assertEqual(len(self.state.key_presses(0)), 1) self.assertListEqual(self.state.key_presses(1), []) self.assertEqual(len(self.state.configs), 1)
def test_apply_phase_amp_mod_sens(self): ch = 2 pms = 6 ams = 3 self.assertEqual(self.state.channel_config(ch).pms, 0) self.assertEqual(self.state.channel_config(ch).ams, 0) self.state.apply(create(0x38 | ch, (pms << 4) | ams)) self.assertEqual(self.state.channel_config(ch).pms, pms) self.assertEqual(self.state.channel_config(ch).ams, ams)
def test_apply_key_code(self): ch = 2 octave = 3 note = 4 self.assertEqual(self.state.channel_config(ch).octave, 0) self.assertEqual(self.state.channel_config(ch).note, 0) self.state.apply(create(0x28 | ch, octave << 4 | note)) self.assertEqual(self.state.channel_config(ch).octave, octave) self.assertEqual(self.state.channel_config(ch).note, note)
def test_apply_channel_control_left_right_single_channel(self): ch = 0 fb = 5 cxn = 7 self.assertFalse(self.state.channel_config(ch).right) self.assertFalse(self.state.channel_config(ch).left) self.assertEqual(self.state.channel_config(ch).fb, 0) self.assertEqual(self.state.channel_config(ch).connection, 0) self.state.apply(create(0x20 | ch, (1 << 7) | (fb << 3) | cxn)) self.assertTrue(self.state.channel_config(ch).right) self.assertFalse(self.state.channel_config(ch).left) self.assertEqual(self.state.channel_config(ch).fb, fb) self.assertEqual(self.state.channel_config(ch).connection, cxn) self.state.apply(create(0x20 | ch, (1 << 6))) self.assertFalse(self.state.channel_config(ch).right) self.assertTrue(self.state.channel_config(ch).left) self.assertEqual(self.state.channel_config(ch).fb, 0) self.assertEqual(self.state.channel_config(ch).connection, 0)
def test_apply_mix(self): self.state.apply(create(0x0F, 0xFF)) self.assertTrue(self.state.noise) self.assertEqual(self.state.noise_freq, 0x1F) self.assertEqual(self.state.lfo, 0) self.assertEqual(self.state.phs_md, 0) self.assertEqual(self.state.amp_md, 0) self.assertFalse(self.state.ct1) self.assertFalse(self.state.ct2) self.assertEqual(self.state.waveform, Waveform.SAW) self.state.apply(create(0x1B, (1 << 7))) self.assertTrue(self.state.noise) self.assertEqual(self.state.noise_freq, 0x1F) self.assertEqual(self.state.lfo, 0) self.assertEqual(self.state.phs_md, 0) self.assertEqual(self.state.amp_md, 0) self.assertFalse(self.state.ct1) self.assertTrue(self.state.ct2) self.assertEqual(self.state.waveform, Waveform.SAW)
def test_apply_key_fraction(self): ch = 2 kf = 63 self.assertEqual(self.state.channel_config(ch).key_fraction, 0) self.state.apply(create(0x30 | ch, kf << 2)) self.assertEqual(self.state.channel_config(ch).key_fraction, kf)
def assert_single_field(self, reg_address: int, reg_value: int, field_name: str, expected_value: int): all_names = list(vars(vgm.ym2151.config.OperatorConfig()).keys()) self.assertTrue(field_name in all_names) for ch in range(8): for dev in range(4): for pre in range(dev): for field in all_names: actual = getattr( self.state.channel_config(ch).operators[pre], field) expected = 0 if field == field_name: expected = expected_value self.assertEqual(actual, expected) self.state.apply(create(reg_address | dev << 3 | ch, reg_value)) for field in all_names: actual = getattr( self.state.channel_config(ch).operators[dev], field) expected = 0 if field == field_name: expected = expected_value self.assertEqual(actual, expected) for post in range(dev + 1, 4): for field in all_names: actual = getattr( self.state.channel_config(ch).operators[post], field) expected = 0 self.assertEqual(actual, expected) for dev in range(4): for pre in range(dev): for field in all_names: actual = getattr( self.state.channel_config(ch).operators[pre], field) expected = 0 self.assertEqual(actual, expected) self.state.apply(create(reg_address | dev << 3 | ch, 0)) for field in all_names: actual = getattr( self.state.channel_config(ch).operators[dev], field) expected = 0 self.assertEqual(actual, expected) for post in range(dev + 1, 4): for field in all_names: actual = getattr( self.state.channel_config(ch).operators[post], field) expected = 0 if field == field_name: expected = expected_value self.assertEqual(actual, expected)
def test_apply_noise_enable(self): cmd = create(0x0F, 0b10000000) self.assertFalse(self.state.noise) self.state.apply(cmd) self.assertTrue(self.state.noise)
def test_apply_lfo(self): freq = 0xAA cmd = create(0x18, freq) self.assertEqual(self.state.lfo, 0) self.state.apply(cmd) self.assertEqual(self.state.lfo, freq)