pub fn intercept(trigger: String, pattern: String) -> Result<(), Box<dyn Error>> {

  let midi_out = MidiOutput::new("midir forwarding output")?;
  let out_port = select_port(&midi_out, "output")?;
  let mut output = midi_out.connect(&out_port, "midir-forward")?;
  let mut midi_in = MidiInput::new("midir forwarding input")?;
  midi_in.ignore(Ignore::None);
  let in_port = select_port(&midi_in, "input")?;

  let _input = midi_in.connect(&in_port, "midir-forward", move |stamp, message, _| {
    
    let mut note = super::perform::Note {output: &mut output};
    let mut buffer = super::time::MIDI_BUFFER.lock().unwrap();

    note.forward(message);
    // println!("{}: {:?} (len = {})", stamp, message, message.len());
    
    buffer.push(super::time::MidiBuffer{timestamp: stamp, message: message.to_vec()});
    // Trigger if buffer over certain length
    if buffer.len() > 6 && super::perform::trigger(stamp, message, &trigger, buffer.len()) {
      pattern::new(&pattern, &mut note, &mut buffer);
    }
  }, ())?;

  let mut std_input = String::new();
  stdin().read_line(&mut std_input)?; // wait for next enter key press

  println!("Closing connections");
  Ok(())
}
// output is not `Send` in Web MIDI, which means it cannot be passed to connect
output is not `Send` in Web MIDI, which means it cannot be passed to connect
output is not ` Send ` in Web MIDI which means it cannot be passed to connect
pub fn intercept(trigger: String, pattern: String) -> Result<(), Box<dyn Error>> {
  let midi_out = MidiOutput::new("midir forwarding output")?;
  let out_port = select_port(&midi_out, "output")?;
  let mut output = midi_out.connect(&out_port, "midir-forward")?;
  let mut midi_in = MidiInput::new("midir forwarding input")?;
  midi_in.ignore(Ignore::None);
  let in_port = select_port(&midi_in, "input")?;
  let _input = midi_in.connect(&in_port, "midir-forward", move |stamp, message, _| {
    let mut note = super::perform::Note {output: &mut output};
    let mut buffer = super::time::MIDI_BUFFER.lock().unwrap();
    note.forward(message);
    // println!("{}: {:?} (len = {})", stamp, message, message.len());
    buffer.push(super::time::MidiBuffer{timestamp: stamp, message: message.to_vec()});
    // Trigger if buffer over certain length
    if buffer.len() > 6 && super::perform::trigger(stamp, message, &trigger, buffer.len()) {
      pattern::new(&pattern, &mut note, &mut buffer);
    }
  }, ())?;
  let mut std_input = String::new();
  stdin().read_line(&mut std_input)?; // wait for next enter key press
  println!("Closing connections");
  Ok(())
}
pub fn intercept ( trigger : String , pattern : String ) -> Result < ( ) , Box < dyn Error > > { let midi_out = MidiOutput :: new ( " " ) ? ; let out_port = select_port ( & midi_out , " " ) ? ; let mut output = midi_out . connect ( & out_port , " " ) ? ; let mut midi_in = MidiInput :: new ( " " ) ? ; midi_in . ignore ( Ignore :: None ) ; let in_port = select_port ( & midi_in , " " ) ? ; let _input = midi_in . connect ( & in_port , " " , move | stamp , message , _ | { let mut note = super :: perform :: Note { output : & mut output } ; let mut buffer = super :: time :: MIDI_BUFFER . lock ( ) . unwrap ( ) ; note . forward ( message ) ; // println!("{}: {:?} (len = {})", stamp, message, message.len()); buffer . push ( super :: time :: MidiBuffer { timestamp : stamp , message : message . to_vec ( ) } ) ; // Trigger if buffer over certain length if buffer . len ( ) > 6 && super :: perform :: trigger ( stamp , message , & trigger , buffer . len ( ) ) { pattern :: new ( & pattern , & mut note , & mut buffer ) ; } } , ( ) ) ? ; let mut std_input = String :: new ( ) ; stdin ( ) . read_line ( & mut std_input ) ? ; // wait for next enter key press println ! ( " " ) ; Ok ( ( ) ) }
output is not `Send` in Web MIDI, which means it cannot be passed to connect
output is not ` Send ` in Web MIDI which means it cannot be passed to connect
trigger
String
pattern
String
trigger
String
pattern
String