Xcode/SimpleSynth - How to get simultaneous MIDI playback?

This is a discussion on Xcode/SimpleSynth - How to get simultaneous MIDI playback? within the C++ Programming forums, part of the General Programming Boards category; Hi there, Iím a University student who took Music Technology as an extra subject for my first year. For one ...

  1. #1
    Registered User Tomaz Bazmati's Avatar
    Join Date
    May 2010
    Posts
    3

    Unhappy Xcode/SimpleSynth - How to get simultaneous MIDI playback?

    Hi there,

    Iím a University student who took Music Technology as an extra subject for my first year. For one task due in on Monday I have to create a c programming project that performs some sort of task. I decided to create a program that harmonizes a scale with chords (or a triad, ie three notes). But I actually have no idea how to play MIDI notes simultaneously. Here is my code so far, if anyone knows how to help, Iíd be extremely grateful. It has been created on a mac, using Xcode and simple synth for midi audio output.

    Code:
    #include <stdio.h>
    
    #include "simplemidi.h"
    
    
    void playNote(int n, int l);
    
    
    
    int main() {
    
        char input[100];
    
        int i;
    
        chooseMidiOutput();
    
        printf("Type letter names of pitches to play (with no spaces).\n");
    
        scanf("%s", input); // scanf("%99s", input); would be safer
    
        for (i = 0; input[i] != '\0'; i++) {
    
            if (input[i] == 'C' || input[i] == 'c') {
    
                playNote(60, 250);
    
            } else if (input[i] == 'D' || input[i] == 'd') {
    
                playNote(62, 250);
    
            } else if (input[i] == 'E' || input[i] == 'e') {
    
                playNote(64, 250);
    
            } else if (input[i] == 'F' || input[i] == 'f') {
    
                playNote(65, 250);
    
            } else if (input[i] == 'G' || input[i] == 'g') {
    
                playNote(67, 250);
    
            } else if (input[i] == 'A' || input[i] == 'a') {
    
                playNote(69, 250);
    
            } else if (input[i] == 'B' || input[i] == 'b') {
    
                playNote(71, 250);
    
            } else {
    
                printf("%c is not a pitch.\n", input[i]);
    
            }
    
        }
    
        waitMidi(500);
    
        closeMidiOutput();
    
        return 0;
    
    }
    
    
    
    void playNote(int n, int l) {
    
        sendMessageNow(144, n, 64);
    
        waitMidi(l);
    
        sendMessageNow(128, n, 0);
    
    }
    Many Thanks,
    Tom

  2. #2
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,185
    Presumably you'll need to send three "on" messages at the same time, and then three "off" messages.

  3. #3
    Super Moderator VirtualAce's Avatar
    Join Date
    Aug 2001
    Posts
    9,598
    Without knowing the details of the API we probably cannot offer much assistance.

  4. #4
    Registered User Tomaz Bazmati's Avatar
    Join Date
    May 2010
    Posts
    3
    I'm not so sure what API means but I'll try to provide more info.

    In Xcode (for MAC) the projected was created under Command Line Utility, Standard Tool. The program used for the virtual MIDI is simple synth. Er, other than that I don't have much information.

    Does that help/make any sense?

  5. #5
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,185
    So do you know which message is "on" and which message is "off"?

  6. #6
    Registered User Tomaz Bazmati's Avatar
    Join Date
    May 2010
    Posts
    3
    Quote Originally Posted by tabstop View Post
    So do you know which message is "on" and which message is "off"?
    I think that's in the highlighted area. Unfortuently I have an incredibly sub-standard knowlege in this coding, it was introduced to the course at a very late stage and I wouldn't have chosen it had I known. I'm not great with this stuff. I understand if it's too difficult to help me.

    Code:
    #include <stdio.h>
    
    #include "simplemidi.h"
    
    
    void playNote(int n, int l);
    
    
    
    int main() {
    
        char input[100];
    
        int i;
    
        chooseMidiOutput();
    
        printf("Type letter names of pitches to play (with no spaces).\n");
    
        scanf("%s", input); // scanf("%99s", input); would be safer
    
        for (i = 0; input[i] != '\0'; i++) {
    
            if (input[i] == 'C' || input[i] == 'c') {
    
                playNote(60, 250);
    
            } else if (input[i] == 'D' || input[i] == 'd') {
    
                playNote(62, 250);
    
            } else if (input[i] == 'E' || input[i] == 'e') {
    
                playNote(64, 250);
    
            } else if (input[i] == 'F' || input[i] == 'f') {
    
                playNote(65, 250);
    
            } else if (input[i] == 'G' || input[i] == 'g') {
    
                playNote(67, 250);
    
            } else if (input[i] == 'A' || input[i] == 'a') {
    
                playNote(69, 250);
    
            } else if (input[i] == 'B' || input[i] == 'b') {
    
                playNote(71, 250);
    
            } else {
    
                printf("%c is not a pitch.\n", input[i]);
    
            }
    
        }
    
        waitMidi(500);
    
        closeMidiOutput();
    
        return 0;
    
    }
    
    
    
    void playNote(int n, int l) {
    
        sendMessageNow(144, n, 64);
    
        waitMidi(l);
    
        sendMessageNow(128, n, 0);
    
    }

  7. #7
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,185
    So since you know which is on, and which is off, then do three on messages, hang around for a while, then turn them off.

  8. #8
    Super Moderator VirtualAce's Avatar
    Join Date
    Aug 2001
    Posts
    9,598
    According to what you have shown I would say the API does not support playing two midi sounds at once. The whole message on, message off system seems to imply that only one midi 'note' can play at a time.

  9. #9
    Registered User
    Join Date
    Aug 2005
    Posts
    266
    I am not sure how music works but is there a way of mixing the notes you need to get a new number code?

  10. #10
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,185
    Quote Originally Posted by Bubba View Post
    According to what you have shown I would say the API does not support playing two midi sounds at once. The whole message on, message off system seems to imply that only one midi 'note' can play at a time.
    That would surprise anybody who's ever used a synthesizer. Who knew you couldn't hold two keys down at the same time?

  11. #11
    Super Moderator VirtualAce's Avatar
    Join Date
    Aug 2001
    Posts
    9,598
    That would surprise anybody who's ever used a synthesizer. Who knew you couldn't hold two keys down at the same time?
    Agreed and I'm sure it's not the case. However given the linear nature of what we have seen I'm sure there is another API call that handles the exact case we are talking about. No one in their right mind would write a MIDI API for a synthesizer that did not allow one to play chords.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Working with MIDI in C++
    By adamdavis in forum C++ Programming
    Replies: 2
    Last Post: 04-11-2010, 09:33 PM
  2. Replies: 1
    Last Post: 02-22-2010, 11:52 PM
  3. wave and MIDI sound
    By carlorfeo in forum C++ Programming
    Replies: 1
    Last Post: 08-04-2009, 07:17 PM
  4. Guitar Hero ALSA MIDI output
    By redxine in forum Linux Programming
    Replies: 0
    Last Post: 01-24-2009, 11:03 PM
  5. Intercept the MIDI Out
    By MattMik in forum C++ Programming
    Replies: 2
    Last Post: 10-18-2007, 03:05 AM

Tags for this Thread


1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21