Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

336
Vistas
How to connect AKSequencer to a AKCallbackInstrument?

I want to read a midi file and display things when note events are triggered. I found this stackoverflow question, where the second answer suggests to use AudioKit : How Do I Get Reliable Timing for my Audio App? More precisely, the suggestion is to use AKSequencer to absorb the midi file in the app, and then to link it to a AKCallbackInstrument to trigger the events and call a function for each midi note event.

I installed AudioKit 4.5.5 using this tutorial https://www.youtube.com/watch?v=iUvWxWvRvo8 Then I managed to run the code of the tutorial, so I know AudioKit is properly included in the project.

Then I wrote my own code :

let sequencer = AKSequencer(filename: "myMidiFile.mid")
let callbackInstr = AKCallbackInstrument()

callbackInstr.callback = myCallBack
sequencer.setGlobalMIDIOutput(callbackInstr.midiIn)

func myCallBack(a:UInt8, b:MIDINoteNumber, c:MIDIVelocity){
    print(b)
}

func test() {
    do {
        try AudioKit.start()
    }
    catch {
        print("Oops! AudioKit didn't start!")
    }

    sequencer.play()
}

When I try to build my project, there is an error on the line sequencer.setGlobalMIDIOutput(callbackInstr.midiIn)

The error is Value of type 'AKCallbackInstrument' has no member 'midiIn'

I tried to clean the project and re-build but the error is still here.

Can you explain me why do I get this error ? What should I do to solve it ? Because on the AudioKit doc, I found that AKCallbackInstrument is a subclass of AKMIDIInstrument, which does have a property called 'midiIn'. https://audiokit.io/docs/Classes/AKCallbackInstrument.html https://audiokit.io/docs/Classes/AKMIDIInstrument.html

over 4 years ago · Santiago Trujillo
2 Respuestas
Responde la pregunta

0

typewriter found the solution to my problem. Here is the code which works now, printing the midi number of the note each time it is played (but I didn't add sound yet) :

// dont write the .mid extension in filename :
let sequencer = AKSequencer(filename:"coucou") 
let callbackInstr = AKMIDICallbackInstrument()
callbackInstr.callback = myCallBack
sequencer.setGlobalMIDIOutput(callbackInstr.midiIn)
sequencer.play()

func myCallBack(a:UInt8, b:MIDINoteNumber, c:MIDIVelocity) -> () {
    if (a == 144) {  // if noteOn
        print(b)
    }
}
over 4 years ago · Santiago Trujillo Denunciar

0

True, the class AKCallbackInstrument does not have a property midiIn, although the documentation does show it being used that way. Instead of using AKCallbackInstrument, use AKMIDICallbackInstrument. That class has midiIn, and seems to work fine.

over 4 years ago · Santiago Trujillo Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda