Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
//
// Use this file to import your target's public headers that you would like to expose to Swift. (Needed for Swift only)
//

#import "MIKMIDIToAudioExporter.h"
#import "MIKOfflineMIDISynthesizer.h"

Large diffs are not rendered by default.

38 changes: 38 additions & 0 deletions Examples/iOS/MIDI to Audio iOS/MIDI to Audio iOS/AppDelegate.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import UIKit

@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate {

var window: UIWindow?


func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
// Override point for customization after application launch.
return true
}

func applicationWillResignActive(_ application: UIApplication) {
// Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state.
// Use this method to pause ongoing tasks, disable timers, and invalidate graphics rendering callbacks. Games should use this method to pause the game.
}

func applicationDidEnterBackground(_ application: UIApplication) {
// Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later.
// If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits.
}

func applicationWillEnterForeground(_ application: UIApplication) {
// Called as part of the transition from the background to the active state; here you can undo many of the changes made on entering the background.
}

func applicationDidBecomeActive(_ application: UIApplication) {
// Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface.
}

func applicationWillTerminate(_ application: UIApplication) {
// Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:.
}


}

Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
{
"images" : [
{
"idiom" : "iphone",
"size" : "20x20",
"scale" : "2x"
},
{
"idiom" : "iphone",
"size" : "20x20",
"scale" : "3x"
},
{
"idiom" : "iphone",
"size" : "29x29",
"scale" : "2x"
},
{
"idiom" : "iphone",
"size" : "29x29",
"scale" : "3x"
},
{
"idiom" : "iphone",
"size" : "40x40",
"scale" : "2x"
},
{
"idiom" : "iphone",
"size" : "40x40",
"scale" : "3x"
},
{
"idiom" : "iphone",
"size" : "60x60",
"scale" : "2x"
},
{
"idiom" : "iphone",
"size" : "60x60",
"scale" : "3x"
}
],
"info" : {
"version" : 1,
"author" : "xcode"
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="11134" systemVersion="15F34" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" launchScreen="YES" useTraitCollections="YES" colorMatched="YES" initialViewController="01J-lp-oVM">
<dependencies>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="11106"/>
<capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
</dependencies>
<scenes>
<!--View Controller-->
<scene sceneID="EHf-IW-A2E">
<objects>
<viewController id="01J-lp-oVM" sceneMemberID="viewController">
<layoutGuides>
<viewControllerLayoutGuide type="top" id="Llm-lL-Icb"/>
<viewControllerLayoutGuide type="bottom" id="xb3-aO-Qok"/>
</layoutGuides>
<view key="view" contentMode="scaleToFill" id="Ze5-6b-2t3">
<rect key="frame" x="0.0" y="0.0" width="375" height="667"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
<color key="backgroundColor" red="1" green="1" blue="1" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
</view>
</viewController>
<placeholder placeholderIdentifier="IBFirstResponder" id="iYj-Kq-Ea1" userLabel="First Responder" sceneMemberID="firstResponder"/>
</objects>
<point key="canvasLocation" x="53" y="375"/>
</scene>
</scenes>
</document>
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
<?xml version="1.0" encoding="UTF-8"?>
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="11762" systemVersion="16C67" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" colorMatched="YES" initialViewController="BYZ-38-t0r">
<device id="retina4_7" orientation="portrait">
<adaptation id="fullscreen"/>
</device>
<dependencies>
<deployment identifier="iOS"/>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="11757"/>
<capability name="Constraints to layout margins" minToolsVersion="6.0"/>
<capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
</dependencies>
<scenes>
<!--View Controller-->
<scene sceneID="tne-QT-ifu">
<objects>
<viewController id="BYZ-38-t0r" customClass="ViewController" customModule="MIDI_to_Audio_iOS" customModuleProvider="target" sceneMemberID="viewController">
<layoutGuides>
<viewControllerLayoutGuide type="top" id="y3c-jy-aDJ"/>
<viewControllerLayoutGuide type="bottom" id="wfy-db-euE"/>
</layoutGuides>
<view key="view" contentMode="scaleToFill" id="8bC-Xf-vdC">
<rect key="frame" x="0.0" y="0.0" width="375" height="667"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
<subviews>
<button opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="roundedRect" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="UQ3-EZ-nTP">
<rect key="frame" x="16" y="150" width="343" height="165"/>
<fontDescription key="fontDescription" type="system" weight="medium" pointSize="15"/>
<state key="normal" title="Play Original MIDI File"/>
<connections>
<action selector="playOriginalButtonPressed:" destination="BYZ-38-t0r" eventType="touchUpInside" id="Y5n-Sw-9UZ"/>
</connections>
</button>
<button opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="roundedRect" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="vdn-Nq-oaR">
<rect key="frame" x="16" y="485" width="343" height="162"/>
<fontDescription key="fontDescription" type="system" weight="medium" pointSize="15"/>
<state key="normal" title="Play to Converted Audio File"/>
<connections>
<action selector="playConvertedButtonPressed:" destination="BYZ-38-t0r" eventType="touchUpInside" id="6qJ-Tc-2is"/>
</connections>
</button>
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="MIDI To Audio File" textAlignment="center" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" minimumScaleFactor="0.25" translatesAutoresizingMaskIntoConstraints="NO" id="V8h-kC-8LS">
<rect key="frame" x="16" y="20" width="343" height="122"/>
<constraints>
<constraint firstAttribute="height" constant="122" id="ohq-me-Nke"/>
</constraints>
<fontDescription key="fontDescription" type="system" weight="thin" pointSize="36"/>
<nil key="textColor"/>
<nil key="highlightedColor"/>
</label>
<button opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="roundedRect" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="eUE-Fb-YfL">
<rect key="frame" x="16" y="323" width="343" height="154"/>
<constraints>
<constraint firstAttribute="height" constant="154" id="7Me-B4-mUw"/>
</constraints>
<fontDescription key="fontDescription" type="system" weight="medium" pointSize="15"/>
<state key="normal" title="Convert MIDI to Audio File"/>
<connections>
<action selector="convertToAudioFileButtonPressed:" destination="BYZ-38-t0r" eventType="touchUpInside" id="zvr-jc-0WI"/>
</connections>
</button>
</subviews>
<color key="backgroundColor" red="1" green="1" blue="1" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
<constraints>
<constraint firstItem="eUE-Fb-YfL" firstAttribute="leading" secondItem="vdn-Nq-oaR" secondAttribute="leading" id="04I-KH-KMY"/>
<constraint firstItem="V8h-kC-8LS" firstAttribute="leading" secondItem="8bC-Xf-vdC" secondAttribute="leadingMargin" id="1ND-BR-jdf"/>
<constraint firstItem="V8h-kC-8LS" firstAttribute="trailing" secondItem="UQ3-EZ-nTP" secondAttribute="trailing" id="9wk-P0-8HT"/>
<constraint firstItem="eUE-Fb-YfL" firstAttribute="top" secondItem="UQ3-EZ-nTP" secondAttribute="bottom" constant="8" symbolic="YES" id="A4M-pe-g6k"/>
<constraint firstItem="V8h-kC-8LS" firstAttribute="trailing" secondItem="8bC-Xf-vdC" secondAttribute="trailingMargin" id="KML-n8-sNG"/>
<constraint firstItem="eUE-Fb-YfL" firstAttribute="centerY" secondItem="8bC-Xf-vdC" secondAttribute="centerY" constant="66.5" id="NY1-vU-C3U"/>
<constraint firstItem="UQ3-EZ-nTP" firstAttribute="trailing" secondItem="eUE-Fb-YfL" secondAttribute="trailing" id="OUq-Vx-EZr"/>
<constraint firstItem="V8h-kC-8LS" firstAttribute="top" secondItem="y3c-jy-aDJ" secondAttribute="bottom" id="Uy4-Qq-qEQ"/>
<constraint firstItem="vdn-Nq-oaR" firstAttribute="top" secondItem="eUE-Fb-YfL" secondAttribute="bottom" constant="8" symbolic="YES" id="XET-f0-XMc"/>
<constraint firstItem="eUE-Fb-YfL" firstAttribute="trailing" secondItem="vdn-Nq-oaR" secondAttribute="trailing" id="Xdh-Yz-IZm"/>
<constraint firstItem="V8h-kC-8LS" firstAttribute="leading" secondItem="UQ3-EZ-nTP" secondAttribute="leading" id="aXH-7L-Yv2"/>
<constraint firstItem="UQ3-EZ-nTP" firstAttribute="leading" secondItem="eUE-Fb-YfL" secondAttribute="leading" id="dwv-2k-k4l"/>
<constraint firstItem="UQ3-EZ-nTP" firstAttribute="top" secondItem="V8h-kC-8LS" secondAttribute="bottom" constant="8" symbolic="YES" id="jTC-Sd-6qx"/>
<constraint firstAttribute="bottom" secondItem="vdn-Nq-oaR" secondAttribute="bottom" constant="20" symbolic="YES" id="vXf-uq-tCE"/>
</constraints>
</view>
<connections>
<outlet property="convertToAudioFileButton" destination="eUE-Fb-YfL" id="Qbt-jB-sps"/>
<outlet property="playConvertedAudioFileButton" destination="vdn-Nq-oaR" id="Qgm-Fi-aoE"/>
<outlet property="playOriginalButton" destination="UQ3-EZ-nTP" id="Yne-4Q-fCL"/>
</connections>
</viewController>
<placeholder placeholderIdentifier="IBFirstResponder" id="dkx-z0-nzr" sceneMemberID="firstResponder"/>
</objects>
<point key="canvasLocation" x="136.80000000000001" y="137.18140929535232"/>
</scene>
</scenes>
</document>
38 changes: 38 additions & 0 deletions Examples/iOS/MIDI to Audio iOS/MIDI to Audio iOS/Info.plist
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>CFBundleDevelopmentRegion</key>
<string>en</string>
<key>CFBundleExecutable</key>
<string>$(EXECUTABLE_NAME)</string>
<key>CFBundleIdentifier</key>
<string>$(PRODUCT_BUNDLE_IDENTIFIER)</string>
<key>CFBundleInfoDictionaryVersion</key>
<string>6.0</string>
<key>CFBundleName</key>
<string>$(PRODUCT_NAME)</string>
<key>CFBundlePackageType</key>
<string>APPL</string>
<key>CFBundleShortVersionString</key>
<string>1.0</string>
<key>CFBundleVersion</key>
<string>1</string>
<key>LSRequiresIPhoneOS</key>
<true/>
<key>UILaunchStoryboardName</key>
<string>LaunchScreen</string>
<key>UIMainStoryboardFile</key>
<string>Main</string>
<key>UIRequiredDeviceCapabilities</key>
<array>
<string>armv7</string>
</array>
<key>UISupportedInterfaceOrientations</key>
<array>
<string>UIInterfaceOrientationPortrait</string>
<string>UIInterfaceOrientationLandscapeLeft</string>
<string>UIInterfaceOrientationLandscapeRight</string>
</array>
</dict>
</plist>
Binary file not shown.
Binary file not shown.
130 changes: 130 additions & 0 deletions Examples/iOS/MIDI to Audio iOS/MIDI to Audio iOS/ViewController.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,130 @@
//
// ViewController.swift
// MIDI to Audio iOS
//
// Created by Sasha Ivanov on 2016-12-24.
// Copyright © 2016 madebysasha. All rights reserved.

// Permission is hereby granted, free of charge, to any person obtaining a
// copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
//
// The above copyright notice and this permission notice shall be included
// in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
// IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
// CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
// TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
// SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.


import UIKit
import AVFoundation
import MIKMIDI

class ViewController: UIViewController {



var midiUrl:URL?
var soundfontUrl:URL?
var sequencer:MIKMIDISequencer?

var audioUrl:URL?
var audioPlayer:AVPlayer?

@IBOutlet weak var playOriginalButton: UIButton!
@IBOutlet weak var convertToAudioFileButton: UIButton!
@IBOutlet weak var playConvertedAudioFileButton: UIButton!

@IBAction func playOriginalButtonPressed(_ sender: Any) {

// Play the sequencer
sequencer?.startPlayback()

}

@IBAction func convertToAudioFileButtonPressed(_ sender: Any) {

// Create the MIKMIDI Audio Exporter
let audioExporter = MIKMIDIToAudioExporter(midiFileAt: midiUrl)

// Add the soundfont to the Audio Exporter (NEW from macOS Example)
audioExporter?.addSoundfont(soundfontUrl)

// Render the MIDI file as a CAF file with the added soundfont
audioExporter?.exportWithSoundfontToAudioFile(completionHandler: { (audioOutputUrl, error) in

// Check if there was an error durring the export
if (audioOutputUrl == nil){
if((error) != nil){
NSLog(error as! String)
print("Audio Conversion Failed")
}
}

// Otherwise save the output url and enable the Play Converted Audio button
else{
self.audioUrl = audioOutputUrl
self.playConvertedAudioFileButton.isEnabled = true
}
})
}

@IBAction func playConvertedButtonPressed(_ sender: Any) {

// Create an AV Audio Player to playback the converted file
audioPlayer = AVPlayer(url: audioUrl!)

// Play the converted file
audioPlayer?.play()
}


override func viewDidLoad() {
super.viewDidLoad()

// 1. Disable the Play Converted Audio button. (Will enable when the convert button is pressed)
playConvertedAudioFileButton.isEnabled = false

// 2. Set the URLs of the files we want to use for playback (midi file and soundfont file)
midiUrl = Bundle.main.url(forResource: "TheOriginal", withExtension: "mid")
soundfontUrl = Bundle.main.url(forResource: "Stereo Piano", withExtension: ".sf2")

// 3. Setup the MIKMIDI Sequencer for Playing Back Original Midi File
do{
// Create a MIKMIDI Sequence from the midi file
let sequence = try MIKMIDISequence(fileAt: midiUrl!)

// Create a MIKMIDI Sequencer from the sequence
sequencer = MIKMIDISequencer(sequence: sequence)

// Use the Soundfont File to set the Synth for each Track in the Sequence.
for track in sequence.tracks{
let synth = sequencer?.builtinSynthesizer(for: track)
try synth!.loadSoundfontFromFile(at: soundfontUrl!)
}
}
catch{
print("Unable to Create Sequencer")
}
}

override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}





}

Loading