You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 

146 lines
4.8 KiB

#!/usr/bin/env python3
"""
Test hardware MIDI output with the output manager
"""
import sys
import os
import time
# Add project to path
sys.path.insert(0, os.path.dirname(os.path.abspath(__file__)))
def test_output_manager_hardware():
"""Test the output manager in hardware mode"""
print("=== Testing Output Manager Hardware Mode ===")
try:
from simulator.simulator_engine import SimulatorEngine
from core.output_manager import OutputManager
# Create output manager
simulator = SimulatorEngine()
output_manager = OutputManager(simulator)
print(f"Available MIDI outputs: {output_manager.get_available_outputs()}")
# Switch to hardware mode
success = output_manager.set_mode("hardware")
print(f"Switched to hardware mode: {success}")
print(f"Current mode: {output_manager.current_mode}")
# Try to connect to first available device
outputs = output_manager.get_available_outputs()
if outputs and "No MIDI" not in outputs[0]:
device_name = outputs[0]
print(f"Connecting to: {device_name}")
success = output_manager.set_midi_output(device_name)
print(f"Connected: {success}")
if success:
print("Sending test notes...")
# Send a sequence of notes
for note in [60, 64, 67, 72]: # C major chord + octave
print(f"Sending note {note}")
output_manager.send_note_on(1, note, 80)
time.sleep(0.3)
output_manager.send_note_off(1, note)
time.sleep(0.1)
print("Hardware MIDI test completed")
return True
else:
print("No suitable MIDI outputs found")
return False
except Exception as e:
print(f"Hardware MIDI test failed: {e}")
import traceback
traceback.print_exc()
return False
def test_full_arpeggiator_hardware():
"""Test full arpeggiator in hardware mode"""
print("\n=== Testing Full Arpeggiator in Hardware Mode ===")
try:
from core.midi_channel_manager import MIDIChannelManager
from core.volume_pattern_engine import VolumePatternEngine
from core.synth_router import SynthRouter
from simulator.simulator_engine import SimulatorEngine
from core.output_manager import OutputManager
from core.arpeggiator_engine import ArpeggiatorEngine
# Create system
channel_manager = MIDIChannelManager()
volume_engine = VolumePatternEngine()
synth_router = SynthRouter(channel_manager)
simulator = SimulatorEngine()
output_manager = OutputManager(simulator)
arpeggiator = ArpeggiatorEngine(channel_manager, synth_router, volume_engine, output_manager)
# Switch to hardware mode
output_manager.set_mode("hardware")
# Connect to MIDI device
outputs = output_manager.get_available_outputs()
if outputs and "No MIDI" not in outputs[0]:
output_manager.set_midi_output(outputs[0])
print(f"Connected to: {outputs[0]}")
else:
print("No MIDI device available")
return False
# Configure arpeggiator
arpeggiator.set_root_note(60)
arpeggiator.set_scale("major")
arpeggiator.set_pattern_type("up")
arpeggiator.set_tempo(120)
# Add notes and start
print("Adding notes and starting arpeggiator...")
arpeggiator.note_on(60) # C
arpeggiator.note_on(64) # E
started = arpeggiator.start()
print(f"Arpeggiator started: {started}")
if started:
print("Running arpeggiator for 5 seconds...")
time.sleep(5)
arpeggiator.stop()
print("Stopped")
return True
else:
return False
except Exception as e:
print(f"Full hardware test failed: {e}")
import traceback
traceback.print_exc()
return False
def main():
print("Hardware MIDI Test")
print("=" * 30)
# Test output manager
om_ok = test_output_manager_hardware()
# Test full arpeggiator
full_ok = test_full_arpeggiator_hardware()
print("\n" + "=" * 30)
print("RESULTS:")
print(f"Output Manager: {'PASS' if om_ok else 'FAIL'}")
print(f"Full System: {'PASS' if full_ok else 'FAIL'}")
if not om_ok:
print("\nOutput Manager issues - check MIDI device selection")
if not full_ok:
print("\nFull system issues - check arpeggiator integration")
if __name__ == "__main__":
main()