```rust
use std::{
    path::Path,
    sync::{Arc, Mutex},
    thread,
    time::{Duration, Instant},
};

use clap::Parser;
use kdmapi::KDMAPI;
use midi_toolkit::{
    events::Event,
    io::{DiskReader, MIDIFile},
    pipe,
    sequence::{
        event::{cancel_tempo_events, merge_events_array, scale_event_time, Delta},
        to_vec, unwrap_items, TimeCaster,
    },
};

#[derive(Parser, Debug)]
#[command(author, version, about, long_about = None)]
struct Args {
    /// Path of the midi file
    #[arg(short, long)]
    midi_file: String,
}

struct MIDIPlayer {
    midi: MIDIFile<DiskReader>,
    midi_data: Mutex<Box<dyn Iterator<Item = Delta<f64, Event>>>>,
    paused: NAME_1,
    current_time: f64,
}

impl MIDIPlayer {
    fn new(midi_file_path: impl AsRef<Path>) -> MIDIPlayer {
        let midi = MIDIFile::open(midi_file_path, None).unwrap();
        let ppq = midi.ppq();
        let merged = pipe!(
            midi.iter_all_tracks()
            |> to_vec()
            |> merge_events_array()
            |> TimeCaster::<f64>::cast_event_delta()
            |> cancel_tempo_events(250_000)
            |> scale_event_time(1.0 / ppq as f64)
            |> unwrap_items()
        );

        MIDIPlayer {
            midi,
            midi_data: Mutex::new(Box::new(merged)),
            paused: false,
            current_time: 0.0,
        }
    }

    // Function to play the MIDI events
    fn play(&mut self) {
        let now = Instant::now();
        let mut time = 0.0;
        let mut midi_data_guard = self.midi_data.lock().unwrap();
        while let Some(e) = midi_data_guard.next() {
            if self.paused {
                continue;
            }

            if e.delta != 0.0 {
                time += e.delta;
                let diff = time - now.elapsed().as_secs_f64();
                if diff > 0.0 {
                    thread::sleep(Duration::from_secs_f64(diff));
                }
            }
            match e.event {
                Event::NoteOn(evt) => {
                    println!("{:?}", evt)
                }
                Event::NoteOff(evt) => {
                    println!("{:?}", evt)
                }
                _ => {}
            }
        }
    }
}

fn main() {
    let kdmapi = KDMAPI.open_stream();
    let args = Args::parse();

    let midi_player = Arc::new(Mutex::new(MIDIPlayer::new(args.midi_file))); // Wrap MIDIPlayer in a Mutex
    let midi_events: Vec<Delta<f64, Event>> = {
        let player = midi_player.lock().unwrap();
        player.midi_data.lock().unwrap().colle