mtrack 0.12.0

A multitrack audio and MIDI player for live performances.
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
// Copyright (C) 2026 Michael Wilson <mike@mdwn.dev>
//
// This program is free software: you can redistribute it and/or modify it under
// the terms of the GNU General Public License as published by the Free Software
// Foundation, version 3.
//
// This program is distributed in the hope that it will be useful, but WITHOUT
// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
// FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License along with
// this program. If not, see <https://www.gnu.org/licenses/>.
//

use super::common::*;
#[cfg(test)]
use crate::lighting::effects::*;
use crate::lighting::engine::EffectEngine;
use std::collections::HashMap;
use std::time::Duration;

#[test]
fn test_static_replace_blend_mode() {
    use super::super::effects::*;
    use super::super::engine::EffectEngine;

    // Initialize tracing

    // Create a test fixture (Astera PixelBlock style)
    let mut channels = HashMap::new();
    channels.insert("red".to_string(), 1);
    channels.insert("green".to_string(), 2);
    channels.insert("blue".to_string(), 3);
    channels.insert("strobe".to_string(), 4);

    let fixture = FixtureInfo::new(
        "front_wash".to_string(),
        1,
        1,
        "Astera-PixelBrick".to_string(),
        channels,
        Some(20.0), // Test fixture with strobe
    );

    let mut engine = EffectEngine::new();
    engine.register_fixture(fixture);

    // Also register back_wash fixture
    let mut back_channels = HashMap::new();
    back_channels.insert("red".to_string(), 1);
    back_channels.insert("green".to_string(), 2);
    back_channels.insert("blue".to_string(), 3);
    back_channels.insert("strobe".to_string(), 4);

    let back_fixture = FixtureInfo::new(
        "back_wash".to_string(),
        1,
        5, // Different address
        "Astera-PixelBrick".to_string(),
        back_channels,
        Some(20.0), // Test fixture with strobe
    );
    engine.register_fixture(back_fixture);

    // Test static effect with replace blend mode (like in your DSL)
    let mut static_params = HashMap::new();
    static_params.insert("red".to_string(), 0.0);
    static_params.insert("green".to_string(), 0.0);
    static_params.insert("blue".to_string(), 1.0);
    static_params.insert("dimmer".to_string(), 1.0);

    let static_effect = create_effect_with_layering(
        "static_blue_with_dimmer".to_string(),
        EffectType::Static {
            parameters: static_params,
            duration: Duration::from_secs(5),
        },
        vec!["front_wash".to_string()],
        EffectLayer::Background,
        BlendMode::Replace, // This is what your DSL uses
    );

    engine.start_effect(static_effect).unwrap();

    // Check what the static effect produces
    let commands = engine
        .update(Duration::from_secs(0), None)
        .unwrap()
        .to_vec();
    println!("Static effect with replace blend mode:");
    for cmd in &commands {
        println!("  Channel {}: {}", cmd.channel, cmd.value);
    }

    // Check that it produces blue, not white
    let red_cmd = commands.iter().find(|cmd| cmd.channel == 1);
    let green_cmd = commands.iter().find(|cmd| cmd.channel == 2);
    let blue_cmd = commands.iter().find(|cmd| cmd.channel == 3);

    if let (Some(red), Some(green), Some(blue)) = (red_cmd, green_cmd, blue_cmd) {
        println!("\nAnalysis:");
        println!("  Red: {} (should be 0)", red.value);
        println!("  Green: {} (should be 0)", green.value);
        println!("  Blue: {} (should be 255)", blue.value);

        assert_eq!(red.value, 0, "Red should be 0");
        assert_eq!(green.value, 0, "Green should be 0");
        assert_eq!(blue.value, 255, "Blue should be 255");
    }
}
#[test]
fn test_static_effect_timing() {
    // Test how static effects work with different timing options
    let mut engine = EffectEngine::new();

    // Register test fixture (RGB-only, no dedicated dimmer)
    let mut channels = HashMap::new();
    channels.insert("red".to_string(), 1);
    channels.insert("green".to_string(), 2);
    channels.insert("blue".to_string(), 3);

    let fixture = FixtureInfo::new(
        "test_fixture".to_string(),
        1,
        1,
        "RGB_Par".to_string(),
        channels,
        None,
    );

    engine.register_fixture(fixture);

    // Test 1: Static effect with no duration (indefinite)
    let mut indefinite_static = EffectInstance::new(
        "indefinite_static".to_string(),
        EffectType::Static {
            parameters: {
                let mut params = HashMap::new();
                params.insert("red".to_string(), 1.0);
                params.insert("green".to_string(), 0.0);
                params.insert("blue".to_string(), 0.0);
                params
            },
            duration: Duration::from_secs(5), // Indefinite
        },
        vec!["test_fixture".to_string()],
        None,
        None,
        None,
    );
    indefinite_static.layer = EffectLayer::Foreground;
    indefinite_static.blend_mode = BlendMode::Replace;

    engine.start_effect(indefinite_static).unwrap();

    // Let it run for a bit
    engine.update(Duration::from_secs(1), None).unwrap();

    let commands_1s = engine
        .update(Duration::from_secs(1), None)
        .unwrap()
        .to_vec();
    println!("Indefinite static at 1s:");
    for cmd in commands_1s {
        let channel_name = match cmd.channel {
            1 => "Red",
            2 => "Green",
            3 => "Blue",
            _ => "Unknown",
        };
        println!(
            "  {}: {} ({:.1}%)",
            channel_name,
            cmd.value,
            cmd.value as f64 / 255.0 * 100.0
        );
    }

    // Test 2: Static effect with duration (timed)
    let mut timed_static = EffectInstance::new(
        "timed_static".to_string(),
        EffectType::Static {
            parameters: {
                let mut params = HashMap::new();
                params.insert("red".to_string(), 0.0);
                params.insert("green".to_string(), 1.0);
                params.insert("blue".to_string(), 0.0);
                params
            },
            duration: Duration::from_secs(3), // 3 seconds
        },
        vec!["test_fixture".to_string()],
        None,
        None,
        None,
    );
    timed_static.layer = EffectLayer::Foreground;
    timed_static.blend_mode = BlendMode::Replace;

    engine.start_effect(timed_static.clone()).unwrap();

    // Test at various times
    let commands_1s_timed = engine
        .update(Duration::from_secs(1), None)
        .unwrap()
        .to_vec();
    println!("\nTimed static at 1s (should be green):");
    for cmd in &commands_1s_timed {
        let channel_name = match cmd.channel {
            1 => "Red",
            2 => "Green",
            3 => "Blue",
            _ => "Unknown",
        };
        println!(
            "  {}: {} ({:.1}%)",
            channel_name,
            cmd.value,
            cmd.value as f64 / 255.0 * 100.0
        );
    }

    let commands_4s = engine
        .update(Duration::from_secs(3), None)
        .unwrap()
        .to_vec();
    println!("\nTimed static at 4s (should be no commands - timed static ended, indefinite static was stopped):");
    println!("Active effects count: {}", engine.active_effects_count());
    for cmd in &commands_4s {
        let channel_name = match cmd.channel {
            1 => "Red",
            2 => "Green",
            3 => "Blue",
            _ => "Unknown",
        };
        println!(
            "  {}: {} ({:.1}%)",
            channel_name,
            cmd.value,
            cmd.value as f64 / 255.0 * 100.0
        );
    }

    // Verify behavior
    let red_1s = commands_1s_timed
        .iter()
        .find(|cmd| cmd.channel == 1)
        .map(|cmd| cmd.value)
        .unwrap_or(0);
    let green_1s = commands_1s_timed
        .iter()
        .find(|cmd| cmd.channel == 2)
        .map(|cmd| cmd.value)
        .unwrap_or(0);

    assert_eq!(
        red_1s, 0,
        "Red should be 0 (timed static replaces indefinite)"
    );
    assert_eq!(green_1s, 255, "Green should be 255 (timed static active)");

    // After timed static ends, no effects remain and no state persists
    // (timed static ended and is not permanent, indefinite was removed by conflict)
    assert!(
        commands_4s.is_empty(),
        "No commands after timed static ends (not permanent, no effects active)"
    );

    println!("✅ Static effect timing test passed!");
}
#[test]
fn test_static_effect_with_up_time() {
    // Test that static effects can have up_time (fade-in) from DSL
    let mut engine = EffectEngine::new();

    // Register test fixture
    let mut channels = HashMap::new();
    channels.insert("dimmer".to_string(), 1);
    channels.insert("red".to_string(), 2);
    channels.insert("green".to_string(), 3);
    channels.insert("blue".to_string(), 4);

    let fixture = FixtureInfo::new(
        "test_fixture".to_string(),
        1,
        1,
        "RGB_Par".to_string(),
        channels,
        None,
    );

    engine.register_fixture(fixture);

    // Create a static effect with up_time using the new constructor
    let static_effect = EffectInstance::new(
        "fade_in_static".to_string(),
        EffectType::Static {
            parameters: {
                let mut params = HashMap::new();
                params.insert("red".to_string(), 1.0);
                params.insert("green".to_string(), 0.0);
                params.insert("blue".to_string(), 0.0);
                params.insert("dimmer".to_string(), 1.0);
                params
            },
            duration: Duration::from_secs(5), // Indefinite
        },
        vec!["test_fixture".to_string()],
        None,
        None,
        None,
    );
    // Don't set up_time - keep it as truly indefinite

    engine.start_effect(static_effect).unwrap();

    // Test at various times during fade-in
    let commands_0s = engine
        .update(Duration::from_secs(0), None)
        .unwrap()
        .to_vec();
    println!("Static with up_time at 0s (should be off):");
    for cmd in &commands_0s {
        let channel_name = match cmd.channel {
            1 => "Dimmer",
            2 => "Red",
            3 => "Green",
            4 => "Blue",
            _ => "Unknown",
        };
        println!(
            "  {}: {} ({:.1}%)",
            channel_name,
            cmd.value,
            cmd.value as f64 / 255.0 * 100.0
        );
    }

    let commands_1s = engine
        .update(Duration::from_secs(1), None)
        .unwrap()
        .to_vec();
    println!("\nStatic with up_time at 1s (should be 50%):");
    for cmd in &commands_1s {
        let channel_name = match cmd.channel {
            1 => "Dimmer",
            2 => "Red",
            3 => "Green",
            4 => "Blue",
            _ => "Unknown",
        };
        println!(
            "  {}: {} ({:.1}%)",
            channel_name,
            cmd.value,
            cmd.value as f64 / 255.0 * 100.0
        );
    }

    let commands_2s = engine
        .update(Duration::from_secs(1), None)
        .unwrap()
        .to_vec();
    println!("\nStatic with up_time at 2s (should be 100%):");
    for cmd in &commands_2s {
        let channel_name = match cmd.channel {
            1 => "Dimmer",
            2 => "Red",
            3 => "Green",
            4 => "Blue",
            _ => "Unknown",
        };
        println!(
            "  {}: {} ({:.1}%)",
            channel_name,
            cmd.value,
            cmd.value as f64 / 255.0 * 100.0
        );
    }

    let commands_3s = engine
        .update(Duration::from_secs(1), None)
        .unwrap()
        .to_vec();
    println!("\nStatic with up_time at 3s (should still be 100%):");
    for cmd in &commands_3s {
        let channel_name = match cmd.channel {
            1 => "Dimmer",
            2 => "Red",
            3 => "Green",
            4 => "Blue",
            _ => "Unknown",
        };
        println!(
            "  {}: {} ({:.1}%)",
            channel_name,
            cmd.value,
            cmd.value as f64 / 255.0 * 100.0
        );
    }

    // Verify behavior
    let red_0s = commands_0s
        .iter()
        .find(|cmd| cmd.channel == 2)
        .map(|cmd| cmd.value)
        .unwrap_or(0);
    let red_1s = commands_1s
        .iter()
        .find(|cmd| cmd.channel == 2)
        .map(|cmd| cmd.value)
        .unwrap_or(0);
    let red_2s = commands_2s
        .iter()
        .find(|cmd| cmd.channel == 2)
        .map(|cmd| cmd.value)
        .unwrap_or(0);
    let red_3s = commands_3s
        .iter()
        .find(|cmd| cmd.channel == 2)
        .map(|cmd| cmd.value)
        .unwrap_or(0);

    assert_eq!(
        red_0s, 255,
        "Red should be on at start (instant indefinite effect)"
    );
    assert_eq!(red_1s, 255, "Red should be on at 1s (indefinite effect)");
    assert_eq!(red_2s, 255, "Red should be on at 2s (indefinite effect)");
    assert_eq!(red_3s, 255, "Red should be on at 3s (indefinite effect)");

    println!("✅ Static effect with up_time test passed!");
}
#[test]
fn test_static_effect_with_down_time() {
    // Test that static effects can have down_time (fade-out) from DSL
    let mut engine = EffectEngine::new();

    // Register test fixture
    let mut channels = HashMap::new();
    channels.insert("dimmer".to_string(), 1);
    channels.insert("red".to_string(), 2);
    channels.insert("green".to_string(), 3);
    channels.insert("blue".to_string(), 4);

    let fixture = FixtureInfo::new(
        "test_fixture".to_string(),
        1,
        1,
        "RGB_Par".to_string(),
        channels,
        None,
    );

    engine.register_fixture(fixture);

    // Create a static effect with up_time, hold_time, and down_time
    let static_effect = EffectInstance::new(
        "fade_in_hold_fade_out_static".to_string(),
        EffectType::Static {
            parameters: {
                let mut params = HashMap::new();
                params.insert("red".to_string(), 1.0);
                params.insert("green".to_string(), 0.0);
                params.insert("blue".to_string(), 0.0);
                params.insert("dimmer".to_string(), 1.0);
                params
            },
            duration: Duration::from_secs(5), // 5 second total duration
        },
        vec!["test_fixture".to_string()],
        Some(Duration::from_secs(1)), // 1 second fade in
        Some(Duration::from_secs(2)), // 2 second hold
        Some(Duration::from_secs(2)), // 2 second fade out
    );

    engine.start_effect(static_effect.clone()).unwrap();

    // Test at various times during the effect
    let commands_0s = engine
        .update(Duration::from_secs(0), None)
        .unwrap()
        .to_vec();
    println!("Static with down_time at 0s (should be off):");
    for cmd in &commands_0s {
        let channel_name = match cmd.channel {
            1 => "Dimmer",
            2 => "Red",
            3 => "Green",
            4 => "Blue",
            _ => "Unknown",
        };
        println!(
            "  {}: {} ({:.1}%)",
            channel_name,
            cmd.value,
            cmd.value as f64 / 255.0 * 100.0
        );
    }

    let commands_0_5s = engine
        .update(Duration::from_millis(500), None)
        .unwrap()
        .to_vec();
    println!("\nStatic with down_time at 0.5s (should be 50% fade in):");
    for cmd in &commands_0_5s {
        let channel_name = match cmd.channel {
            1 => "Dimmer",
            2 => "Red",
            3 => "Green",
            4 => "Blue",
            _ => "Unknown",
        };
        println!(
            "  {}: {} ({:.1}%)",
            channel_name,
            cmd.value,
            cmd.value as f64 / 255.0 * 100.0
        );
    }

    let commands_1s = engine
        .update(Duration::from_millis(500), None)
        .unwrap()
        .to_vec();
    println!("\nStatic with down_time at 1s (should be 100% - fade in complete):");
    for cmd in &commands_1s {
        let channel_name = match cmd.channel {
            1 => "Dimmer",
            2 => "Red",
            3 => "Green",
            4 => "Blue",
            _ => "Unknown",
        };
        println!(
            "  {}: {} ({:.1}%)",
            channel_name,
            cmd.value,
            cmd.value as f64 / 255.0 * 100.0
        );
    }

    let commands_2s = engine
        .update(Duration::from_secs(1), None)
        .unwrap()
        .to_vec();
    println!("\nStatic with down_time at 2s (should be 100% - hold phase):");
    for cmd in &commands_2s {
        let channel_name = match cmd.channel {
            1 => "Dimmer",
            2 => "Red",
            3 => "Green",
            4 => "Blue",
            _ => "Unknown",
        };
        println!(
            "  {}: {} ({:.1}%)",
            channel_name,
            cmd.value,
            cmd.value as f64 / 255.0 * 100.0
        );
    }

    let commands_3s = engine
        .update(Duration::from_secs(1), None)
        .unwrap()
        .to_vec();
    println!("\nStatic with down_time at 3s (should be 100% - end of hold phase):");
    for cmd in &commands_3s {
        let channel_name = match cmd.channel {
            1 => "Dimmer",
            2 => "Red",
            3 => "Green",
            4 => "Blue",
            _ => "Unknown",
        };
        println!(
            "  {}: {} ({:.1}%)",
            channel_name,
            cmd.value,
            cmd.value as f64 / 255.0 * 100.0
        );
    }

    // Test at 3.5s (middle of fade-out phase)
    let commands_3_5s = engine
        .update(Duration::from_millis(500), None)
        .unwrap()
        .to_vec();
    println!("\nStatic with down_time at 3.5s (should be 75% - fade out phase):");
    for cmd in &commands_3_5s {
        let channel_name = match cmd.channel {
            1 => "Dimmer",
            2 => "Red",
            3 => "Green",
            4 => "Blue",
            _ => "Unknown",
        };
        println!(
            "  {}: {} ({:.1}%)",
            channel_name,
            cmd.value,
            cmd.value as f64 / 255.0 * 100.0
        );
    }

    let commands_4s = engine
        .update(Duration::from_secs(1), None)
        .unwrap()
        .to_vec();
    println!("\nStatic with down_time at 4s (should be 50% - middle of fade out):");
    for cmd in &commands_4s {
        let channel_name = match cmd.channel {
            1 => "Dimmer",
            2 => "Red",
            3 => "Green",
            4 => "Blue",
            _ => "Unknown",
        };
        println!(
            "  {}: {} ({:.1}%)",
            channel_name,
            cmd.value,
            cmd.value as f64 / 255.0 * 100.0
        );
    }

    let commands_5s = engine
        .update(Duration::from_secs(1), None)
        .unwrap()
        .to_vec();
    println!("\nStatic with down_time at 5s (should be 0% - effect ended):");
    for cmd in &commands_5s {
        let channel_name = match cmd.channel {
            1 => "Dimmer",
            2 => "Red",
            3 => "Green",
            4 => "Blue",
            _ => "Unknown",
        };
        println!(
            "  {}: {} ({:.1}%)",
            channel_name,
            cmd.value,
            cmd.value as f64 / 255.0 * 100.0
        );
    }

    // Verify behavior
    let red_0s = commands_0s
        .iter()
        .find(|cmd| cmd.channel == 2)
        .map(|cmd| cmd.value)
        .unwrap_or(0);
    let red_0_5s = commands_0_5s
        .iter()
        .find(|cmd| cmd.channel == 2)
        .map(|cmd| cmd.value)
        .unwrap_or(0);
    let red_1s = commands_1s
        .iter()
        .find(|cmd| cmd.channel == 2)
        .map(|cmd| cmd.value)
        .unwrap_or(0);
    let red_2s = commands_2s
        .iter()
        .find(|cmd| cmd.channel == 2)
        .map(|cmd| cmd.value)
        .unwrap_or(0);
    let red_3s = commands_3s
        .iter()
        .find(|cmd| cmd.channel == 2)
        .map(|cmd| cmd.value)
        .unwrap_or(0);
    let red_3_5s = commands_3_5s
        .iter()
        .find(|cmd| cmd.channel == 2)
        .map(|cmd| cmd.value)
        .unwrap_or(0);
    let red_4s = commands_4s
        .iter()
        .find(|cmd| cmd.channel == 2)
        .map(|cmd| cmd.value)
        .unwrap_or(0);
    let red_5s = commands_5s
        .iter()
        .find(|cmd| cmd.channel == 2)
        .map(|cmd| cmd.value)
        .unwrap_or(0);

    assert_eq!(red_0s, 0, "Red should be 0 at start (fade in begins)");
    assert!(
        red_0_5s > 0 && red_0_5s < 255,
        "Red should be partially faded in at 0.5s"
    );
    assert_eq!(
        red_1s, 255,
        "Red should be fully on at 1s (fade in complete)"
    );
    assert_eq!(red_2s, 255, "Red should be fully on at 2s (hold phase)");
    assert_eq!(
        red_3s, 255,
        "Red should be fully on at 3s (end of hold phase)"
    );
    assert!(
        red_3_5s > 0 && red_3_5s < 255,
        "Red should be partially faded out at 3.5s"
    );
    assert!(
        red_4s > 0 && red_4s < 255,
        "Red should be partially faded out at 4s (middle of fade out)"
    );
    assert_eq!(red_5s, 0, "Red should be off at 5s (fade out complete)");

    println!("✅ Static effect with down_time test passed!");
}
#[test]
fn test_static_effect_fade_out() {
    // Test that static effects with timing work correctly
    let mut engine = EffectEngine::new();

    // Register test fixture
    let mut channels = HashMap::new();
    channels.insert("dimmer".to_string(), 1);
    channels.insert("red".to_string(), 2);
    channels.insert("green".to_string(), 3);
    channels.insert("blue".to_string(), 4);

    let fixture = FixtureInfo::new(
        "test_fixture".to_string(),
        1,
        1,
        "Dimmer".to_string(),
        channels,
        None,
    );

    engine.register_fixture(fixture);

    // Create a static effect that fades out over 2 seconds
    let mut fade_out_effect = EffectInstance::new(
        "fade_out".to_string(),
        EffectType::Static {
            parameters: {
                let mut params = HashMap::new();
                params.insert("red".to_string(), 1.0);
                params.insert("green".to_string(), 0.5);
                params.insert("blue".to_string(), 0.0);
                params.insert("dimmer".to_string(), 0.8);
                params
            },
            duration: Duration::from_secs(2), // Timed static effect
        },
        vec!["test_fixture".to_string()],
        Some(Duration::from_secs(0)), // up_time
        Some(Duration::from_secs(0)), // hold_time
        Some(Duration::from_secs(2)), // down_time
    );
    fade_out_effect.layer = EffectLayer::Foreground;
    fade_out_effect.blend_mode = BlendMode::Replace;

    engine.start_effect(fade_out_effect).unwrap();

    println!("Testing static effect fade-out");

    // Test at various time points
    for (time_ms, description) in [
        (0, "Start"),
        (500, "25%"),
        (1000, "50%"),
        (1500, "75%"),
        (2000, "End"),
    ] {
        let commands = engine
            .update(Duration::from_millis(time_ms), None)
            .unwrap()
            .to_vec();
        println!("\nAt {} ({}ms):", description, time_ms);

        for cmd in commands {
            let channel_name = match cmd.channel {
                1 => "Dimmer",
                2 => "Red",
                3 => "Green",
                4 => "Blue",
                _ => "Unknown",
            };
            println!(
                "  {}: {} ({:.1}%)",
                channel_name,
                cmd.value,
                cmd.value as f64 / 255.0 * 100.0
            );
        }
    }

    // Verify the behavior
    let final_commands = engine
        .update(Duration::from_millis(2000), None)
        .unwrap()
        .to_vec();
    assert!(final_commands.is_empty(), "Effect should have ended at 2s");

    println!("✅ Static effect fade-out test completed");
}