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.
196 lines
5.9 KiB
196 lines
5.9 KiB
#!/usr/bin/env python3
|
|
"""
|
|
Simple audio and MIDI test without Unicode issues
|
|
"""
|
|
|
|
import sys
|
|
import os
|
|
import time
|
|
|
|
# Add project to path
|
|
sys.path.insert(0, os.path.dirname(os.path.abspath(__file__)))
|
|
|
|
def test_basic_audio():
|
|
"""Test basic pygame audio"""
|
|
print("=== Testing Basic Audio ===")
|
|
|
|
try:
|
|
import pygame
|
|
import numpy as np
|
|
|
|
pygame.mixer.pre_init(frequency=22050, size=-16, channels=2, buffer=512)
|
|
pygame.mixer.init()
|
|
print("PASS: Pygame mixer initialized")
|
|
|
|
# Generate test tone
|
|
sample_rate = 22050
|
|
duration = 1.0
|
|
frequency = 440
|
|
|
|
samples = np.sin(2 * np.pi * frequency * np.linspace(0, duration, int(sample_rate * duration)))
|
|
samples = (samples * 0.3 * 32767).astype(np.int16)
|
|
stereo_samples = np.column_stack((samples, samples))
|
|
|
|
sound = pygame.sndarray.make_sound(stereo_samples)
|
|
print("Playing test tone...")
|
|
sound.play()
|
|
time.sleep(1.2)
|
|
print("PASS: Basic audio working")
|
|
return True
|
|
|
|
except Exception as e:
|
|
print(f"FAIL: Basic audio error: {e}")
|
|
return False
|
|
|
|
def test_simulator():
|
|
"""Test simulator engine"""
|
|
print("\n=== Testing Simulator ===")
|
|
|
|
try:
|
|
from simulator.simulator_engine import SimulatorEngine
|
|
|
|
simulator = SimulatorEngine()
|
|
print(f"Simulator audio enabled: {simulator.audio_enabled}")
|
|
print(f"Audio initialized: {simulator.audio_initialized_flag}")
|
|
|
|
print("Testing simulator note...")
|
|
simulator.play_note(1, 60, 80)
|
|
time.sleep(1)
|
|
simulator.stop_note(1, 60)
|
|
print("PASS: Simulator test completed")
|
|
return True
|
|
|
|
except Exception as e:
|
|
print(f"FAIL: Simulator error: {e}")
|
|
return False
|
|
|
|
def test_midi():
|
|
"""Test MIDI devices"""
|
|
print("\n=== Testing MIDI ===")
|
|
|
|
try:
|
|
import mido
|
|
|
|
outputs = mido.get_output_names()
|
|
print(f"Found {len(outputs)} MIDI outputs:")
|
|
for i, output in enumerate(outputs):
|
|
print(f" {i+1}: {output}")
|
|
|
|
if outputs:
|
|
print(f"Testing with: {outputs[0]}")
|
|
midi_out = mido.open_output(outputs[0])
|
|
|
|
# Send test note
|
|
msg_on = mido.Message('note_on', channel=0, note=60, velocity=80)
|
|
msg_off = mido.Message('note_off', channel=0, note=60, velocity=0)
|
|
|
|
midi_out.send(msg_on)
|
|
print("Sent note ON")
|
|
time.sleep(0.5)
|
|
midi_out.send(msg_off)
|
|
print("Sent note OFF")
|
|
|
|
midi_out.close()
|
|
print("PASS: MIDI test completed")
|
|
return True
|
|
else:
|
|
print("FAIL: No MIDI outputs found")
|
|
return False
|
|
|
|
except Exception as e:
|
|
print(f"FAIL: MIDI error: {e}")
|
|
return False
|
|
|
|
def test_arpeggiator_notes():
|
|
"""Test if arpeggiator actually triggers notes"""
|
|
print("\n=== Testing Arpeggiator Note Triggering ===")
|
|
|
|
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)
|
|
|
|
print("Components created")
|
|
|
|
# Set to simulator mode
|
|
output_manager.set_mode("simulator")
|
|
print(f"Output mode: {output_manager.current_mode}")
|
|
|
|
# Configure
|
|
arpeggiator.set_root_note(60)
|
|
arpeggiator.set_scale("major")
|
|
arpeggiator.set_pattern_type("up")
|
|
arpeggiator.set_tempo(240) # Fast tempo for quick test
|
|
|
|
# Add notes
|
|
print("Adding notes C and E...")
|
|
arpeggiator.note_on(60) # C
|
|
arpeggiator.note_on(64) # E
|
|
|
|
print(f"Held notes: {len(arpeggiator.held_notes)}")
|
|
print(f"Pattern length: {arpeggiator.pattern_length}")
|
|
|
|
# Start arpeggiator
|
|
print("Starting arpeggiator...")
|
|
started = arpeggiator.start()
|
|
print(f"Started: {started}")
|
|
|
|
if started:
|
|
print("Running for 3 seconds...")
|
|
time.sleep(3)
|
|
arpeggiator.stop()
|
|
print("Stopped")
|
|
return True
|
|
else:
|
|
print("FAIL: Could not start arpeggiator")
|
|
return False
|
|
|
|
except Exception as e:
|
|
print(f"FAIL: Arpeggiator error: {e}")
|
|
import traceback
|
|
traceback.print_exc()
|
|
return False
|
|
|
|
def main():
|
|
print("Simple Audio/MIDI Diagnostic")
|
|
print("=" * 40)
|
|
|
|
# Test basic audio first
|
|
audio_ok = test_basic_audio()
|
|
|
|
# Test simulator
|
|
sim_ok = test_simulator()
|
|
|
|
# Test MIDI
|
|
midi_ok = test_midi()
|
|
|
|
# Test full arpeggiator
|
|
arp_ok = test_arpeggiator_notes()
|
|
|
|
print("\n" + "=" * 40)
|
|
print("RESULTS:")
|
|
print(f"Basic Audio: {'PASS' if audio_ok else 'FAIL'}")
|
|
print(f"Simulator: {'PASS' if sim_ok else 'FAIL'}")
|
|
print(f"MIDI: {'PASS' if midi_ok else 'FAIL'}")
|
|
print(f"Arpeggiator: {'PASS' if arp_ok else 'FAIL'}")
|
|
|
|
if not audio_ok:
|
|
print("\nAudio issues: Check Windows audio settings")
|
|
if not midi_ok:
|
|
print("\nMIDI issues: Install virtual MIDI cable (loopMIDI)")
|
|
if not arp_ok:
|
|
print("\nArpeggiator issues: Check component integration")
|
|
|
|
if __name__ == "__main__":
|
|
main()
|