SlideShare une entreprise Scribd logo
1  sur  31
CoreMIDI and Friends
Chris Adamson, CocoaHeads Ann Arbor
            Sept. 8, 2011
Road Map


• MIDI basics
• MIDI APIs on OSX
• MIDI APIs on iOS
MIDI Basics

• MIDI = Musical Instrument Digital Interface
  • Circa 1982!
• Sends messages between devices, not sounds
  • Notes to play (pitch, impact, vibrato), patch
    selection, timing synchronization, etc.
MIDI Terms

• Device — participant in a MIDI network
• Endpoint — one connection into or out of a
 device

• Source — endpoint that sends data
• Destination — endpoint that receives data
MIDI Messages


STATUS   DATA 1   DATA 2
MIDI Messages

• Channel Voice Messages — Note On, Note
  Off, After-touch, Pitch wheel

  • High nybble of status is command, low
    nybble is channel number

• Channel Mode, System Messages
• Various extensions to the spec over the years
http://www.midi.org/techspecs/midimessages.php
MIDI APIs on OSX
• CoreMIDI — Implementation of MIDI
 messaging

• Instrument Units — Audio Units that generate
 sound in response to MIDI events

• Music Device — Sends commands to
 Instrument Units

• Music Sequence / Music Player — Plays MIDI
 (.mid) files
Core MIDI


• C-based API in Audio Toolbox
  • Largely similar to other Core Audio APIs
  • Uses Core Foundation opaque types,
    memory management, etc.
Core MIDI Types

• MIDIClientRef — Holds state for your MIDI
 session

• MIDIDeviceRef — A device (real or virtual)
 with “entities” (MIDIEntityRef), which are
 logical sub-systems

• MIDIEndPointRef — Source or destination
• MIDIPortRef — An input or output port
Creating client & input port

!MIDIClientRef client = NULL;
!MIDIClientCreate(CFSTR("Core MIDI to System Sounds Demo"),
    MyMIDINotifyProc, self, &client);
!
!MIDIPortRef inPort = NULL;
!MIDIInputPortCreate(client, CFSTR("Input port"),
    MyMIDIReadProc, self, &inPort);
Discovering and connecting
               sources
!unsigned long sourceCount = MIDIGetNumberOfSources();
!for (int i = 0; i < sourceCount; ++i) {
!! MIDIEndpointRef src = MIDIGetSource(i);
!! CFStringRef endpointName = NULL;
!! OSStatus nameErr = MIDIObjectGetStringProperty(src,
                       kMIDIPropertyName, &endpointName);
!! if (noErr == nameErr) {
!! ! NSLog (@" source %d: %@n", i, endpointName);
!! }
!! MIDIPortConnectSource(inPort, src, NULL);
!}
Read Proc

• Callback function indicated by
 MIDIInputPortCreate()

  • Receives MIDIPacketList
    • numPackets and MIDIPacket[]
  • Receives user-info/context pointers that you
    set up in MIDIInputPortCreate() and
    MIDIPortConnectSource()
MIDIPacket

• Contains timeStamp, length, and Byte[]
• Byte[] data is the MIDI message
  • data[0]: status
  • data[1]: MIDI Data 1
  • data[2] (if present): MIDI Data 2
Parsing a NOTE ON message

!MIDIPacket *packet = (MIDIPacket *)pktlist->packet;!
!Byte midiCommand = packet->data[0] >> 4;
!// is it a note-on?
!if (midiCommand == 0x09) {
!! Byte note = packet->data[1] & 0x7F;
!! Byte velocity = packet->data[2] & 0x7F;
Now What?
Instrument Units


• Audio Units that generate sound in response to
 MIDI events

  • kAudioUnitType_MusicDevice
• Do not currently exist on iOS
Instrument                         to audio H/W
                        I/O Unit
    Unit


             AU Graph
Instrument                                  to audio H/W
                   Effect Unit   I/O Unit
    Unit


             AU Graph
Instrument                         to audio H/W
                        I/O Unit
    Unit


             AU Graph
Mu
     si
          cD
               ev
                    ic
                         eM
                              ID
                                   IE
                                        ve
                                             nt
                                                  ()


                                                       Instrument                         to audio H/W
                                                                               I/O Unit
                                                           Unit


                                                                    AU Graph
MusicDevice.h
• Small API to deliver MIDI events to
 instrument units

• Not in Xcode documentation. Check out the
 header file

  • Only 4 functions
  • MusicDeviceMIDIEvent() sends status,
    data1, data2 to a MusicDeviceComponent
    (i.e., an instrument Audio Unit)
Demo
MIDI on iOS


• Core MIDI added in iOS 4.2
• Device connectivity is via dock port
  • Custom hardware
  • iPad Camera Connection Kit
MIDI via the CCK
• MIDI-to-USB adapters semi-officially blessed
 by Apple

  • Adapter must be USB MIDI Class-
    compliant (i.e., doesn’t need drivers)

  • Bus-powered devices may not work, due to
    low power supplied by iPad. Powered USB
    devices generally work.

• http://iosmidi.com/devices/
Playing sounds on iOS


• No instrument units on iOS. Options:
  • Synthesize your own with a render callback
  • Play sampled sounds with Audio Queue, AV
    Player, System Sounds, etc.
Demo
Demo
AUSampler


• New instrument audio unit in Lion… and… …
  • Takes a sampled waveform and pitch-shifts it
   to make it into an instrument

  • Call with MusicDeviceMIDIEvent(), just
   like other instrument units
AUSampler
• Configuration is a huge hassle
  • Huge and tota!y undocumented hassle
  • Build an .aupreset with AU Lab utility, or
    load DLS bank or SoundFont 2 files, or
    provide your own files

  • See WWDC Session 411 (“Music in iOS
    and MacOSX”), then file documentation
    bugs against absence of sample code
In Summary
• Musicians love MIDI. Devices are cheap and
 plentiful

• OSX and iOS love media, MIDI included
  • By comparison, Android has crap MIDI
    support (no javax.sound.midi, just .mid file
    support in android.media.JetPlayer)

• If you’re doing Mac or iOS media apps, you
 should consider supporting MIDI device I/O
Also, you should buy my book




http://www.mypearsonstore.com/bookstore/product.asp?isbn=9780321636843
             http://my.safaribooksonline.com/9780321636973
        http://www.informit.com/promotions/promotion.aspx?promo=137039

Contenu connexe

Tendances

Lua and adaptive audio - Don Veca (Activision)
Lua and adaptive audio - Don Veca (Activision)Lua and adaptive audio - Don Veca (Activision)
Lua and adaptive audio - Don Veca (Activision)
Kore VM
 
Audio in linux embedded
Audio in linux embeddedAudio in linux embedded
Audio in linux embedded
trx2001
 
XNA L06–Input, Audio and Video Playback
XNA L06–Input, Audio and Video PlaybackXNA L06–Input, Audio and Video Playback
XNA L06–Input, Audio and Video Playback
Mohammad Shaker
 
Hardware synth
Hardware synthHardware synth
Hardware synth
Howard Mao
 

Tendances (13)

The Next-Gen Dynamic Sound System of Killzone Shadow Fall
The Next-Gen Dynamic Sound System of Killzone Shadow FallThe Next-Gen Dynamic Sound System of Killzone Shadow Fall
The Next-Gen Dynamic Sound System of Killzone Shadow Fall
 
Dynamic Sound for iOS Apps and Games
Dynamic Sound for iOS Apps and GamesDynamic Sound for iOS Apps and Games
Dynamic Sound for iOS Apps and Games
 
Why is EFL used on Tizen?
Why is EFL used on Tizen?Why is EFL used on Tizen?
Why is EFL used on Tizen?
 
Android Audio & OpenSL
Android Audio & OpenSLAndroid Audio & OpenSL
Android Audio & OpenSL
 
PiST/// Workshop
PiST/// WorkshopPiST/// Workshop
PiST/// Workshop
 
EFL (Tizen Native Display Layer – Architecture & Usage) - Carsten Haitzler
EFL (Tizen Native Display Layer – Architecture & Usage)  - Carsten HaitzlerEFL (Tizen Native Display Layer – Architecture & Usage)  - Carsten Haitzler
EFL (Tizen Native Display Layer – Architecture & Usage) - Carsten Haitzler
 
Lua and adaptive audio - Don Veca (Activision)
Lua and adaptive audio - Don Veca (Activision)Lua and adaptive audio - Don Veca (Activision)
Lua and adaptive audio - Don Veca (Activision)
 
Nerd sniping myself into a rabbit hole... Streaming online audio to a Sonos s...
Nerd sniping myself into a rabbit hole... Streaming online audio to a Sonos s...Nerd sniping myself into a rabbit hole... Streaming online audio to a Sonos s...
Nerd sniping myself into a rabbit hole... Streaming online audio to a Sonos s...
 
Audio in linux embedded
Audio in linux embeddedAudio in linux embedded
Audio in linux embedded
 
XNA L06–Input, Audio and Video Playback
XNA L06–Input, Audio and Video PlaybackXNA L06–Input, Audio and Video Playback
XNA L06–Input, Audio and Video Playback
 
Philip polstra
Philip polstraPhilip polstra
Philip polstra
 
Hardware synth
Hardware synthHardware synth
Hardware synth
 
Connecting hardware up to ColdFusion
Connecting hardware up to ColdFusionConnecting hardware up to ColdFusion
Connecting hardware up to ColdFusion
 

En vedette

8 3 giraldo anderson y jhon trejos
8 3 giraldo anderson y jhon trejos8 3 giraldo anderson y jhon trejos
8 3 giraldo anderson y jhon trejos
jhonatanrulo
 

En vedette (20)

Continuous Delivery in Ruby
Continuous Delivery in RubyContinuous Delivery in Ruby
Continuous Delivery in Ruby
 
From One to Many: Evolving VPC Design (ARC401) | AWS re:Invent 2013
From One to Many:  Evolving VPC Design (ARC401) | AWS re:Invent 2013From One to Many:  Evolving VPC Design (ARC401) | AWS re:Invent 2013
From One to Many: Evolving VPC Design (ARC401) | AWS re:Invent 2013
 
CIS13: Bootcamp: Ping Identity OAuth and OpenID Connect In Action with PingFe...
CIS13: Bootcamp: Ping Identity OAuth and OpenID Connect In Action with PingFe...CIS13: Bootcamp: Ping Identity OAuth and OpenID Connect In Action with PingFe...
CIS13: Bootcamp: Ping Identity OAuth and OpenID Connect In Action with PingFe...
 
OpenID Connect - An Emperor or Just New Cloths?
OpenID Connect - An Emperor or Just New Cloths?OpenID Connect - An Emperor or Just New Cloths?
OpenID Connect - An Emperor or Just New Cloths?
 
Hadoop Summit 2012 | Optimizing MapReduce Job Performance
Hadoop Summit 2012 | Optimizing MapReduce Job PerformanceHadoop Summit 2012 | Optimizing MapReduce Job Performance
Hadoop Summit 2012 | Optimizing MapReduce Job Performance
 
(APP304) AWS CloudFormation Best Practices | AWS re:Invent 2014
(APP304) AWS CloudFormation Best Practices | AWS re:Invent 2014(APP304) AWS CloudFormation Best Practices | AWS re:Invent 2014
(APP304) AWS CloudFormation Best Practices | AWS re:Invent 2014
 
(WEB302) Best Practices for Running WordPress on AWS | AWS re:Invent 2014
(WEB302) Best Practices for Running WordPress on AWS | AWS re:Invent 2014(WEB302) Best Practices for Running WordPress on AWS | AWS re:Invent 2014
(WEB302) Best Practices for Running WordPress on AWS | AWS re:Invent 2014
 
Digital digest //24.06.2016
Digital digest //24.06.2016Digital digest //24.06.2016
Digital digest //24.06.2016
 
Internaliser et industrialiser ses études de satisfaction digitales - Qualtri...
Internaliser et industrialiser ses études de satisfaction digitales - Qualtri...Internaliser et industrialiser ses études de satisfaction digitales - Qualtri...
Internaliser et industrialiser ses études de satisfaction digitales - Qualtri...
 
일본에 불어닥친 클라우드 컴퓨팅 열풍의 현황과 전망
일본에 불어닥친 클라우드 컴퓨팅 열풍의 현황과 전망일본에 불어닥친 클라우드 컴퓨팅 열풍의 현황과 전망
일본에 불어닥친 클라우드 컴퓨팅 열풍의 현황과 전망
 
2nd annual io t summit 2016 - Bangalore India
2nd annual io t summit 2016 - Bangalore India2nd annual io t summit 2016 - Bangalore India
2nd annual io t summit 2016 - Bangalore India
 
Social Media Strategy DRAFT
Social Media Strategy DRAFTSocial Media Strategy DRAFT
Social Media Strategy DRAFT
 
Apc's customised digital signage solutions
Apc's customised digital signage solutionsApc's customised digital signage solutions
Apc's customised digital signage solutions
 
Sesiones cs fuensanta 25 años
Sesiones cs fuensanta 25 añosSesiones cs fuensanta 25 años
Sesiones cs fuensanta 25 años
 
ประชุมชี้แจ้งกรอบวิจัย งบประมาณปี 2558
ประชุมชี้แจ้งกรอบวิจัย งบประมาณปี 2558ประชุมชี้แจ้งกรอบวิจัย งบประมาณปี 2558
ประชุมชี้แจ้งกรอบวิจัย งบประมาณปี 2558
 
[SJSU] Social Media Strategy
[SJSU] Social Media Strategy[SJSU] Social Media Strategy
[SJSU] Social Media Strategy
 
Ipsos MORI Political Monitor - August 2014
Ipsos MORI Political Monitor - August 2014Ipsos MORI Political Monitor - August 2014
Ipsos MORI Political Monitor - August 2014
 
Вестник // Digital Blow Mind // Май 2016
Вестник // Digital Blow Mind // Май 2016Вестник // Digital Blow Mind // Май 2016
Вестник // Digital Blow Mind // Май 2016
 
8 3 giraldo anderson y jhon trejos
8 3 giraldo anderson y jhon trejos8 3 giraldo anderson y jhon trejos
8 3 giraldo anderson y jhon trejos
 
Box Office Best Practices [Webinar]
Box Office Best Practices [Webinar]Box Office Best Practices [Webinar]
Box Office Best Practices [Webinar]
 

Similaire à Core MIDI and Friends

Rloynd ig2 t1 ws
Rloynd ig2 t1 wsRloynd ig2 t1 ws
Rloynd ig2 t1 ws
rosstapher
 
Michaelwilliamsig2task1worksheet
Michaelwilliamsig2task1worksheetMichaelwilliamsig2task1worksheet
Michaelwilliamsig2task1worksheet
Hooaax
 
Michael williamsig2task1worksheet
Michael williamsig2task1worksheetMichael williamsig2task1worksheet
Michael williamsig2task1worksheet
Hooaax
 
Methods and Principles of Sound Design and Production
Methods and Principles of Sound Design and ProductionMethods and Principles of Sound Design and Production
Methods and Principles of Sound Design and Production
Hooaax
 
Ig2 task 1 work sheet connor martin
Ig2 task 1 work sheet connor martinIg2 task 1 work sheet connor martin
Ig2 task 1 work sheet connor martin
Kalen612
 
Ig2 task 1 work sheet - JS
Ig2 task 1 work sheet - JSIg2 task 1 work sheet - JS
Ig2 task 1 work sheet - JS
JamieShepherd
 
Audio devices, formats and codecs
Audio devices, formats and codecsAudio devices, formats and codecs
Audio devices, formats and codecs
cubitos98
 
Ig2 task 1 work sheet 12378
Ig2 task 1 work sheet 12378Ig2 task 1 work sheet 12378
Ig2 task 1 work sheet 12378
CallumDrakeCPFC
 
Ig2 task 1 no2
Ig2 task 1 no2Ig2 task 1 no2
Ig2 task 1 no2
Kenyon101
 

Similaire à Core MIDI and Friends (20)

Core Audio in iOS 6 (CocoaConf Chicago, March 2013)
Core Audio in iOS 6 (CocoaConf Chicago, March 2013)Core Audio in iOS 6 (CocoaConf Chicago, March 2013)
Core Audio in iOS 6 (CocoaConf Chicago, March 2013)
 
Vst Virtual Studio Technology
Vst Virtual Studio TechnologyVst Virtual Studio Technology
Vst Virtual Studio Technology
 
Core Audio in iOS 6 (CocoaConf Portland, Oct. '12)
Core Audio in iOS 6 (CocoaConf Portland, Oct. '12)Core Audio in iOS 6 (CocoaConf Portland, Oct. '12)
Core Audio in iOS 6 (CocoaConf Portland, Oct. '12)
 
Rloynd ig2 t1 ws
Rloynd ig2 t1 wsRloynd ig2 t1 ws
Rloynd ig2 t1 ws
 
Michaelwilliamsig2task1worksheet
Michaelwilliamsig2task1worksheetMichaelwilliamsig2task1worksheet
Michaelwilliamsig2task1worksheet
 
Michael williamsig2task1worksheet
Michael williamsig2task1worksheetMichael williamsig2task1worksheet
Michael williamsig2task1worksheet
 
IG2 Task 1 Work Sheet
IG2 Task 1 Work SheetIG2 Task 1 Work Sheet
IG2 Task 1 Work Sheet
 
Methods and Principles of Sound Design and Production
Methods and Principles of Sound Design and ProductionMethods and Principles of Sound Design and Production
Methods and Principles of Sound Design and Production
 
Ig2 task 1 work sheet connor martin
Ig2 task 1 work sheet connor martinIg2 task 1 work sheet connor martin
Ig2 task 1 work sheet connor martin
 
Ig2 task 1 iian
Ig2 task  1 iianIg2 task  1 iian
Ig2 task 1 iian
 
Ig2 task 1 work sheet
Ig2 task 1 work sheetIg2 task 1 work sheet
Ig2 task 1 work sheet
 
Lecture 2.5 hardware
Lecture 2.5 hardwareLecture 2.5 hardware
Lecture 2.5 hardware
 
Ig2 task 1 work sheet - JS
Ig2 task 1 work sheet - JSIg2 task 1 work sheet - JS
Ig2 task 1 work sheet - JS
 
Audio devices, formats and codecs
Audio devices, formats and codecsAudio devices, formats and codecs
Audio devices, formats and codecs
 
Ig2
Ig2Ig2
Ig2
 
input devices
input devicesinput devices
input devices
 
Ig2 task 1 work sheet 12378
Ig2 task 1 work sheet 12378Ig2 task 1 work sheet 12378
Ig2 task 1 work sheet 12378
 
Ig2 task 1
Ig2 task 1Ig2 task 1
Ig2 task 1
 
Simple User-Friendly MIDI Controller using Arduino.
Simple User-Friendly MIDI Controller using Arduino.Simple User-Friendly MIDI Controller using Arduino.
Simple User-Friendly MIDI Controller using Arduino.
 
Ig2 task 1 no2
Ig2 task 1 no2Ig2 task 1 no2
Ig2 task 1 no2
 

Plus de Chris Adamson

Plus de Chris Adamson (20)

Whatever Happened to Visual Novel Anime? (AWA/Youmacon 2018)
Whatever Happened to Visual Novel Anime? (AWA/Youmacon 2018)Whatever Happened to Visual Novel Anime? (AWA/Youmacon 2018)
Whatever Happened to Visual Novel Anime? (AWA/Youmacon 2018)
 
Whatever Happened to Visual Novel Anime? (JAFAX 2018)
Whatever Happened to Visual Novel Anime? (JAFAX 2018)Whatever Happened to Visual Novel Anime? (JAFAX 2018)
Whatever Happened to Visual Novel Anime? (JAFAX 2018)
 
Media Frameworks Versus Swift (Swift by Northwest, October 2017)
Media Frameworks Versus Swift (Swift by Northwest, October 2017)Media Frameworks Versus Swift (Swift by Northwest, October 2017)
Media Frameworks Versus Swift (Swift by Northwest, October 2017)
 
Fall Premieres: Media Frameworks in iOS 11, macOS 10.13, and tvOS 11 (CocoaCo...
Fall Premieres: Media Frameworks in iOS 11, macOS 10.13, and tvOS 11 (CocoaCo...Fall Premieres: Media Frameworks in iOS 11, macOS 10.13, and tvOS 11 (CocoaCo...
Fall Premieres: Media Frameworks in iOS 11, macOS 10.13, and tvOS 11 (CocoaCo...
 
CocoaConf Chicago 2017: Media Frameworks and Swift: This Is Fine
CocoaConf Chicago 2017: Media Frameworks and Swift: This Is FineCocoaConf Chicago 2017: Media Frameworks and Swift: This Is Fine
CocoaConf Chicago 2017: Media Frameworks and Swift: This Is Fine
 
Forward Swift 2017: Media Frameworks and Swift: This Is Fine
Forward Swift 2017: Media Frameworks and Swift: This Is FineForward Swift 2017: Media Frameworks and Swift: This Is Fine
Forward Swift 2017: Media Frameworks and Swift: This Is Fine
 
Firebase: Totally Not Parse All Over Again (Unless It Is) (CocoaConf San Jose...
Firebase: Totally Not Parse All Over Again (Unless It Is) (CocoaConf San Jose...Firebase: Totally Not Parse All Over Again (Unless It Is) (CocoaConf San Jose...
Firebase: Totally Not Parse All Over Again (Unless It Is) (CocoaConf San Jose...
 
Building A Streaming Apple TV App (CocoaConf San Jose, Nov 2016)
Building A Streaming Apple TV App (CocoaConf San Jose, Nov 2016)Building A Streaming Apple TV App (CocoaConf San Jose, Nov 2016)
Building A Streaming Apple TV App (CocoaConf San Jose, Nov 2016)
 
Firebase: Totally Not Parse All Over Again (Unless It Is)
Firebase: Totally Not Parse All Over Again (Unless It Is)Firebase: Totally Not Parse All Over Again (Unless It Is)
Firebase: Totally Not Parse All Over Again (Unless It Is)
 
Building A Streaming Apple TV App (CocoaConf DC, Sept 2016)
Building A Streaming Apple TV App (CocoaConf DC, Sept 2016)Building A Streaming Apple TV App (CocoaConf DC, Sept 2016)
Building A Streaming Apple TV App (CocoaConf DC, Sept 2016)
 
Video Killed the Rolex Star (CocoaConf San Jose, November, 2015)
Video Killed the Rolex Star (CocoaConf San Jose, November, 2015)Video Killed the Rolex Star (CocoaConf San Jose, November, 2015)
Video Killed the Rolex Star (CocoaConf San Jose, November, 2015)
 
Video Killed the Rolex Star (CocoaConf Columbus, July 2015)
Video Killed the Rolex Star (CocoaConf Columbus, July 2015)Video Killed the Rolex Star (CocoaConf Columbus, July 2015)
Video Killed the Rolex Star (CocoaConf Columbus, July 2015)
 
Revenge of the 80s: Cut/Copy/Paste, Undo/Redo, and More Big Hits (CocoaConf C...
Revenge of the 80s: Cut/Copy/Paste, Undo/Redo, and More Big Hits (CocoaConf C...Revenge of the 80s: Cut/Copy/Paste, Undo/Redo, and More Big Hits (CocoaConf C...
Revenge of the 80s: Cut/Copy/Paste, Undo/Redo, and More Big Hits (CocoaConf C...
 
Core Image: The Most Fun API You're Not Using, CocoaConf Atlanta, December 2014
Core Image: The Most Fun API You're Not Using, CocoaConf Atlanta, December 2014Core Image: The Most Fun API You're Not Using, CocoaConf Atlanta, December 2014
Core Image: The Most Fun API You're Not Using, CocoaConf Atlanta, December 2014
 
Stupid Video Tricks, CocoaConf Seattle 2014
Stupid Video Tricks, CocoaConf Seattle 2014Stupid Video Tricks, CocoaConf Seattle 2014
Stupid Video Tricks, CocoaConf Seattle 2014
 
Stupid Video Tricks, CocoaConf Las Vegas
Stupid Video Tricks, CocoaConf Las VegasStupid Video Tricks, CocoaConf Las Vegas
Stupid Video Tricks, CocoaConf Las Vegas
 
Core Image: The Most Fun API You're Not Using (CocoaConf Columbus 2014)
Core Image: The Most Fun API You're Not Using (CocoaConf Columbus 2014)Core Image: The Most Fun API You're Not Using (CocoaConf Columbus 2014)
Core Image: The Most Fun API You're Not Using (CocoaConf Columbus 2014)
 
Stupid Video Tricks (CocoaConf DC, March 2014)
Stupid Video Tricks (CocoaConf DC, March 2014)Stupid Video Tricks (CocoaConf DC, March 2014)
Stupid Video Tricks (CocoaConf DC, March 2014)
 
Stupid Video Tricks
Stupid Video TricksStupid Video Tricks
Stupid Video Tricks
 
Introduction to the Roku SDK
Introduction to the Roku SDKIntroduction to the Roku SDK
Introduction to the Roku SDK
 

Dernier

Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Victor Rentea
 
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
?#DUbAI#??##{{(☎️+971_581248768%)**%*]'#abortion pills for sale in dubai@
 

Dernier (20)

CNIC Information System with Pakdata Cf In Pakistan
CNIC Information System with Pakdata Cf In PakistanCNIC Information System with Pakdata Cf In Pakistan
CNIC Information System with Pakdata Cf In Pakistan
 
Ransomware_Q4_2023. The report. [EN].pdf
Ransomware_Q4_2023. The report. [EN].pdfRansomware_Q4_2023. The report. [EN].pdf
Ransomware_Q4_2023. The report. [EN].pdf
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024
 
Exploring Multimodal Embeddings with Milvus
Exploring Multimodal Embeddings with MilvusExploring Multimodal Embeddings with Milvus
Exploring Multimodal Embeddings with Milvus
 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century education
 
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdfRising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
 
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
 
AXA XL - Insurer Innovation Award Americas 2024
AXA XL - Insurer Innovation Award Americas 2024AXA XL - Insurer Innovation Award Americas 2024
AXA XL - Insurer Innovation Award Americas 2024
 
Manulife - Insurer Transformation Award 2024
Manulife - Insurer Transformation Award 2024Manulife - Insurer Transformation Award 2024
Manulife - Insurer Transformation Award 2024
 
AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of Terraform
 
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processors
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a Fresher
 
[BuildWithAI] Introduction to Gemini.pdf
[BuildWithAI] Introduction to Gemini.pdf[BuildWithAI] Introduction to Gemini.pdf
[BuildWithAI] Introduction to Gemini.pdf
 
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...
 
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
 
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
 

Core MIDI and Friends

  • 1. CoreMIDI and Friends Chris Adamson, CocoaHeads Ann Arbor Sept. 8, 2011
  • 2. Road Map • MIDI basics • MIDI APIs on OSX • MIDI APIs on iOS
  • 3. MIDI Basics • MIDI = Musical Instrument Digital Interface • Circa 1982! • Sends messages between devices, not sounds • Notes to play (pitch, impact, vibrato), patch selection, timing synchronization, etc.
  • 4. MIDI Terms • Device — participant in a MIDI network • Endpoint — one connection into or out of a device • Source — endpoint that sends data • Destination — endpoint that receives data
  • 5. MIDI Messages STATUS DATA 1 DATA 2
  • 6. MIDI Messages • Channel Voice Messages — Note On, Note Off, After-touch, Pitch wheel • High nybble of status is command, low nybble is channel number • Channel Mode, System Messages • Various extensions to the spec over the years http://www.midi.org/techspecs/midimessages.php
  • 7. MIDI APIs on OSX • CoreMIDI — Implementation of MIDI messaging • Instrument Units — Audio Units that generate sound in response to MIDI events • Music Device — Sends commands to Instrument Units • Music Sequence / Music Player — Plays MIDI (.mid) files
  • 8. Core MIDI • C-based API in Audio Toolbox • Largely similar to other Core Audio APIs • Uses Core Foundation opaque types, memory management, etc.
  • 9. Core MIDI Types • MIDIClientRef — Holds state for your MIDI session • MIDIDeviceRef — A device (real or virtual) with “entities” (MIDIEntityRef), which are logical sub-systems • MIDIEndPointRef — Source or destination • MIDIPortRef — An input or output port
  • 10. Creating client & input port !MIDIClientRef client = NULL; !MIDIClientCreate(CFSTR("Core MIDI to System Sounds Demo"), MyMIDINotifyProc, self, &client); ! !MIDIPortRef inPort = NULL; !MIDIInputPortCreate(client, CFSTR("Input port"), MyMIDIReadProc, self, &inPort);
  • 11. Discovering and connecting sources !unsigned long sourceCount = MIDIGetNumberOfSources(); !for (int i = 0; i < sourceCount; ++i) { !! MIDIEndpointRef src = MIDIGetSource(i); !! CFStringRef endpointName = NULL; !! OSStatus nameErr = MIDIObjectGetStringProperty(src, kMIDIPropertyName, &endpointName); !! if (noErr == nameErr) { !! ! NSLog (@" source %d: %@n", i, endpointName); !! } !! MIDIPortConnectSource(inPort, src, NULL); !}
  • 12. Read Proc • Callback function indicated by MIDIInputPortCreate() • Receives MIDIPacketList • numPackets and MIDIPacket[] • Receives user-info/context pointers that you set up in MIDIInputPortCreate() and MIDIPortConnectSource()
  • 13. MIDIPacket • Contains timeStamp, length, and Byte[] • Byte[] data is the MIDI message • data[0]: status • data[1]: MIDI Data 1 • data[2] (if present): MIDI Data 2
  • 14. Parsing a NOTE ON message !MIDIPacket *packet = (MIDIPacket *)pktlist->packet;! !Byte midiCommand = packet->data[0] >> 4; !// is it a note-on? !if (midiCommand == 0x09) { !! Byte note = packet->data[1] & 0x7F; !! Byte velocity = packet->data[2] & 0x7F;
  • 16. Instrument Units • Audio Units that generate sound in response to MIDI events • kAudioUnitType_MusicDevice • Do not currently exist on iOS
  • 17. Instrument to audio H/W I/O Unit Unit AU Graph
  • 18. Instrument to audio H/W Effect Unit I/O Unit Unit AU Graph
  • 19. Instrument to audio H/W I/O Unit Unit AU Graph
  • 20. Mu si cD ev ic eM ID IE ve nt () Instrument to audio H/W I/O Unit Unit AU Graph
  • 21. MusicDevice.h • Small API to deliver MIDI events to instrument units • Not in Xcode documentation. Check out the header file • Only 4 functions • MusicDeviceMIDIEvent() sends status, data1, data2 to a MusicDeviceComponent (i.e., an instrument Audio Unit)
  • 22. Demo
  • 23. MIDI on iOS • Core MIDI added in iOS 4.2 • Device connectivity is via dock port • Custom hardware • iPad Camera Connection Kit
  • 24. MIDI via the CCK • MIDI-to-USB adapters semi-officially blessed by Apple • Adapter must be USB MIDI Class- compliant (i.e., doesn’t need drivers) • Bus-powered devices may not work, due to low power supplied by iPad. Powered USB devices generally work. • http://iosmidi.com/devices/
  • 25. Playing sounds on iOS • No instrument units on iOS. Options: • Synthesize your own with a render callback • Play sampled sounds with Audio Queue, AV Player, System Sounds, etc.
  • 26. Demo
  • 27. Demo
  • 28. AUSampler • New instrument audio unit in Lion… and… … • Takes a sampled waveform and pitch-shifts it to make it into an instrument • Call with MusicDeviceMIDIEvent(), just like other instrument units
  • 29. AUSampler • Configuration is a huge hassle • Huge and tota!y undocumented hassle • Build an .aupreset with AU Lab utility, or load DLS bank or SoundFont 2 files, or provide your own files • See WWDC Session 411 (“Music in iOS and MacOSX”), then file documentation bugs against absence of sample code
  • 30. In Summary • Musicians love MIDI. Devices are cheap and plentiful • OSX and iOS love media, MIDI included • By comparison, Android has crap MIDI support (no javax.sound.midi, just .mid file support in android.media.JetPlayer) • If you’re doing Mac or iOS media apps, you should consider supporting MIDI device I/O
  • 31. Also, you should buy my book http://www.mypearsonstore.com/bookstore/product.asp?isbn=9780321636843 http://my.safaribooksonline.com/9780321636973 http://www.informit.com/promotions/promotion.aspx?promo=137039