0

I want to make a user-interface of my own that sends out MIDI like signals (or OSC or whatever) that will cause thumbband or garageband or other programs I have installed on my ipad, (or Galaxy) to play the music that I am creating. How do I do that? What ways are available. What programming language must I use to create my "controller" app? What API. What's the fastest way to get this going.

It looks like OSC is what I should be doing, at least for the iPad, but it seems to me that it works only between machines on a network. I want it to work between running apps, like I saw with Jordan Rudess' SampleWiz controlled from another program or https://www.youtube.com/watch?v=ZMyRS9y20mw thumbjam controlling sampleTank (I now looked again at that video and saw that its MIDI)

hichris123
  • 10,145
  • 15
  • 56
  • 70
pashute
  • 3,965
  • 3
  • 38
  • 65
  • possible duplicate of [Can anyone show me how to use CoreMIDI on iOS?](http://stackoverflow.com/questions/13952151/can-anyone-show-me-how-to-use-coremidi-on-ios) – CL. Nov 09 '14 at 07:39
  • Nope. That's telling how to connect from your IOS device (i.e. your iPad or iPhone) to an external device (i.e. a digital music keyboard). – pashute Nov 10 '14 at 08:21
  • "you can use the local CoreMIDI session to send or receive messages from/to another CoreMIDI compatible application" – CL. Nov 10 '14 at 08:24
  • Correction: Nope. That's telling mainly how to connect from your IOS device (i.e. your iPad or iPhone) to an external device (i.e. a digital music keyboard). It says that you can emit midi output, but is that enough to connect between apps? a. What else needs to be done for getting midi running between my new app and some existing MIDI synthesizing app? b. I presume you need to develop with objective C for the CoreMIDI example. What else is available for the IOS environment. c. I've seen HTML5 with JS and MIDI - will that work on IOS devices? d. What about Android – pashute Nov 10 '14 at 08:28
  • Here is a [working example](http://stackoverflow.com/q/26681062/1927589) of how to get Android's MediaPlayer to play back a MIDI file that is created on the fly. Is this something you can adapt to activate a different playback application? – James Newton Nov 21 '14 at 21:28
  • Thanks @JamesNewton ! Definitely. Please put that on the answers and I'll mark it. – pashute Jan 20 '15 at 09:58
  • Thanks @CL. When I wrote the 8:28 comment I didn't see your second comment in response to my 8:21 comment. Seems your answer is correct as well. I lost my ipad so cannot check... But if you put up your answer first, I'll mark it as the answer to this. – pashute Jan 20 '15 at 10:02

1 Answers1

0

Here is a barebones Android project which creates a MIDI file that can then be played by an external MIDI synthesizer. For testing purposes, a playNewMIDIFile() is included. This uses Android's own MediaPlayer to play back the new file.

The original question that included this extract can be found here.

package com.example.midi;

import java.io.File;
import java.io.FileDescriptor;
import java.io.FileInputStream;
import java.io.FileOutputStream;

import android.app.Activity;
import android.media.AudioManager;
import android.media.MediaPlayer;
import android.os.Bundle;
import android.view.View;

public class Main extends Activity {

  private String file = "midi.mid";
  private MediaPlayer mediaPlayer;

  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    mediaPlayer = new MediaPlayer();
    mediaPlayer.setAudioStreamType(AudioManager.STREAM_MUSIC);

    createNewMIDIFile();
    playNewMIDIFile();
  }

  public void createNewMIDIFile() {
    Integer[] stream = new Integer[]{
        //
        0x4d, 0x54, 0x68, 0x64, // MThd = MIDI file designator
        0x00, 0x00, 0x00, 0x06, // Standard MIDI File (SMF)
        0x00, 0x01, 0x00, 0x02, // multiple-track format: 2 tracks
        0x00, 0x40, // 64 ticks per beat (quarter note)
        0x4D, 0x54, 0x72, 0x6B, // Header for track 1
        0x00, 0x00, 0x00, 0x0B, // 11  bytes to describe the track
        0x00, 0xFF, 0x51, 0x03, // set tempo:
        0x0F, 0x42, 0x40, //  1,000,000 microseconds / beat: 60 bpm
        0x00, 0xFF, 0x2F, 0x00, // End of track 1
        0x4D, 0x54, 0x72, 0x6B, // Header for track 2
        0x00, 0x00, 0x00, 0x0F, // 15 bytes to describe the track
        0x00, // Immediately
        0xC1, 0x01, // change instrument for track 2 to piano
        0x00, // Immediately
        0x91, 0x3C, 0x7F, // play middle C with a velocity of 127
        0x30, // 48 ticks later (dotted eighth note)
        0x81, 0x3C, 0x00, // stop playing the middle C
        0x00, 0xFF, 0x2F, 0x00 // End of track 2
    };

    int length = stream.length;
    byte[] byteStream = new byte[length];
    for (int ii = 0; ii < length; ii++) {
      byteStream[ii] = (byte) (stream[ii] % 256);
    }

    try {
      FileOutputStream outputStream = openFileOutput(file, MODE_PRIVATE);
      outputStream.write(byteStream);
      outputStream.close();
    } catch (Exception e) {
      e.printStackTrace();
    }
  }

  public void play(View view) {
  /* Triggered by a button defined in activity_main.xml as 
  <Button
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:onClick="play"
    android:text="Play MIDI" />
  */
    playNewMIDIFile();
  }

  public void playNewMIDIFile() {
    try {
      String filename = getFilesDir() + "/" + file;
      File midifile = new File(filename);
      FileInputStream inputStream = new FileInputStream(midifile);
      FileDescriptor fileDescriptor = inputStream.getFD();
      mediaPlayer.reset();
      mediaPlayer.setDataSource(fileDescriptor);
      inputStream.close();
      mediaPlayer.prepare();
      mediaPlayer.start();
    } catch (Exception e) {
      e.printStackTrace();
    }
  }
}
Community
  • 1
  • 1
James Newton
  • 6,623
  • 8
  • 49
  • 113