Thread: Midi Programming

  1. #1
    Registered User
    Join Date
    May 2010
    Posts
    7

    Question Midi Programming

    I am working on a program in which the user will play a short piece of music to the program via a MIDI keyboard/controller and I am struggling to create something (function, string, whatever) that will allow the user to input data vis the MIDI keyboard. Can anybody help as I only have a couple of weeks to finish this source code?

    Regards.

  2. #2
    Making mistakes
    Join Date
    Dec 2008
    Posts
    476
    What have you done so far?

  3. #3
    Registered User
    Join Date
    May 2010
    Posts
    7
    /*
    * CanonGenerator.c
    *
    *
    * Created by James Daly on 22/04/2010.
    * Copyright 2010 __MyCompanyName__. All rights reserved.
    *
    */


    #include <CanonGenerator.h>
    #include <stdio.h>
    #include <stdlib.h>
    #include "simplemidi.h"

    int main()
    {
    printf ("Welcome! I am Canon Generator!\n");
    printf ("But you may call me Steve.\n");
    printf ("\n");
    printf ("Please play me a short measure of eight notes or less.\n");
    return 0;
    }

  4. #4
    Registered User
    Join Date
    May 2010
    Posts
    7
    The above is all i have. I really am a complete rookie in this subject.

  5. #5
    Registered User
    Join Date
    Oct 2008
    Posts
    1,262
    I LOL'ed

  6. #6
    Novice
    Join Date
    Jul 2009
    Posts
    568
    Quote Originally Posted by jamescpdaly View Post
    The above is all i have. I really am a complete rookie in this subject.
    Start with something simple, why don't you.

    We all started with printf("Hello, world!\n"); and so should you.

  7. #7
    Making mistakes
    Join Date
    Dec 2008
    Posts
    476
    I LOL'ed
    Me too.

    Maybe you should present us what you know about MIDI. Then we can help a lot better.

  8. #8
    Registered User
    Join Date
    May 2010
    Posts
    7
    Quote Originally Posted by msh View Post
    Start with something simple, why don't you.

    We all started with printf("Hello, world!\n"); and so should you.
    I already did that exercise, hence how I was able to input a message so coherently. As for MIDI, I am a qualified musician and sound technician so I am more than capable of aligning instrumentation and processors. I was simply wondering if anyone had a similar program I could use as a basis for my own. I did not expect to be the subject of a joke for those who "LOL'ed".

  9. #9
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    Being able to play music doesn't automatically mean you know how to program something to play it. That's why it's LOL-worthy. You basically just have a "hello world" program, and you want to turn it into a midi player. It's way more complex than that.


    Quzah.
    Hope is the first step on the road to disappointment.

  10. #10
    Registered User
    Join Date
    Oct 2008
    Posts
    1,262
    Quote Originally Posted by quzah View Post
    Being able to play music doesn't automatically mean you know how to program something to play it. That's why it's LOL-worthy. You basically just have a "hello world" program, and you want to turn it into a midi player. It's way more complex than that.


    Quzah.
    Exactly the point.

    Imagine this:
    Me: "Could you help me build a house?"
    Other: "Well, what do you have so far?"
    Me: "A brick."

    You understand how that is kind of ridiculous? Even if the other person was someone who builds houses for money he'd laugh it off and start from scratch. If it's someone who helps online on a forum they'd probably do nothing else than laugh, as it's obviously a lot more job than just getting a brick. It needs designing, loads of materials, planning, and what not. The conversation would show utter cluelessness about what it involves. As your message does.

    Actually, your first message wasn't even that bad. The first one basically asks how to input data through the midi port. That's a fair question, and Brafil's reply was quite useless in my opinion, as you didn't ask for a full program. It's your reply after that that was so funny.

    Truth be told, I've never input midi data, so I can't tell you how it's done. But a google search would easily reveal the answer, I bet.

  11. #11
    Making mistakes
    Join Date
    Dec 2008
    Posts
    476
    I did not expect to be the subject of a joke for those who "LOL'ed".
    I didn't mean to insult you.

    What do you have in simplemidi.h? I think that is the most important question here. Looking at your initial post, I think you don't have anything big yet. As far as I know the windows MFC has a header called mmsystem.h that can help you. Try to look at the documentation, it will definitely help you.

    If you can also use C++, take a look at libjdkmidi.

  12. #12
    Registered User
    Join Date
    Jan 2009
    Posts
    1,485
    What os are you using? That boiler plate comment looks like Xcode? Is it? If that's the case then you have core midi that you can include in you project. If your on linux I think your midi device will show up in your /dev folder, so you could make a thread or separate process that will poll it for incoming data and signal you main thread/process. But it might be easier to use a library specific to what you want to do.

  13. #13
    Registered User
    Join Date
    May 2010
    Posts
    7
    I am using C programming and Xcode

  14. #14
    Registered User
    Join Date
    May 2010
    Posts
    7
    Here is what I currently have. The programme receives MIDI input from a MIDI keyboard now. The next step is to add a piece of code which transposes the piece as I have the scrapped the Canon idea.

    /*
    * CanonGenerator.c
    *
    *
    * Created by James Daly on 22/04/2010.
    * Copyright 2010 __MyCompanyName__. All rights reserved.
    *
    */


    #include <CanonGenerator.h>
    #include <stdio.h>
    #include <stdlib.h>
    #include "simplemidi.h"

    int main(int argc, char *argv[])
    {
    printf ("Welcome! I am Canon Generator!\n");
    printf ("But you may call me Steve.\n");
    printf ("\n");
    printf ("Please play me a measure of eight notes.\n");
    printf ("\n");


    int status[16];
    int data1[16];
    int data2[16];

    long time[16];
    int i = 0;
    chooseMidiInput();
    chooseMidiOutput();
    resetMidiTime();
    while (i < 16) {
    if (isMessageReceived()) {
    time[i] = receiveMessage();
    status[i] = getMessageStatus();
    // only record note-on and note-off messages
    if (((status[i] >= 144) && (status[i] < 144 + 16)) // note-on message
    || ((status[i] >= 128) && (status[i] < 128 + 16))) { // note-off message
    data1[i] = getMessageData1();
    data2[i] = getMessageData2();
    i = i + 1;
    }
    }
    }
    i = 0;
    resetMidiTime(); // puts clock back to 0
    while (i < 16) {
    sendMessageAt(status[i], data1[i], data2[i], time[i]);
    i = i + 1;
    }
    waitMidi(time[15] + 1000); // wait until one second after the last message

    printf ("\n");
    printf ("How many semitones would you like to move the melody up or down?.\n");



    closeMidiOutput();
    closeMidiInput();
    return 0;}


    Does anyone have any pointers or examples on manipulating this much data based on a variable?

  15. #15
    Registered User
    Join Date
    May 2010
    Posts
    7
    I have amended the end so there are only two options for the user. I just need input something to read the number and act upon it.


    #include <CanonGenerator.h>
    #include <stdio.h>
    #include <stdlib.h>
    #include "simplemidi.h"

    int main(int argc, char *argv[])
    {
    printf ("Welcome! I am Transposer!\n");
    printf ("But you may call me Steve.\n");
    printf ("I can transpose a piece up or down by one tone.\n");
    printf ("\n");
    printf ("Please play me a measure of eight notes.\n");
    printf ("\n");


    int status[16];
    int data1[16];
    int data2[16];

    long time[16];
    int i = 0;
    chooseMidiInput();
    chooseMidiOutput();
    resetMidiTime();
    while (i < 16) {
    if (isMessageReceived()) {
    time[i] = receiveMessage();
    status[i] = getMessageStatus();
    // only record note-on and note-off messages
    if (((status[i] >= 144) && (status[i] < 144 + 16)) // note-on message
    || ((status[i] >= 128) && (status[i] < 128 + 16))) { // note-off message
    data1[i] = getMessageData1();
    data2[i] = getMessageData2();
    i = i + 1;
    }
    }
    }
    i = 0;
    resetMidiTime(); // puts clock back to 0
    while (i < 16) {
    sendMessageAt(status[i], data1[i], data2[i], time[i]);
    i = i + 1;
    }
    waitMidi(time[15] + 1000); // wait until one second after the last message

    printf ("\n");
    printf ("Would you like to transpose the melody up or down?.\n");
    printf ("Press '1' to transpose upwards.\n");
    printf ("press '2' to transpose downwards.\n");

    int answer;
    scanf("%d", &answer);



    closeMidiOutput();
    closeMidiInput();
    return 0;}

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 1
    Last Post: 02-22-2010, 11:52 PM
  2. How to play midi music from resource without directX
    By alaphate in forum Windows Programming
    Replies: 0
    Last Post: 03-12-2009, 08:49 AM
  3. Guitar Hero ALSA MIDI output
    By redxine in forum Linux Programming
    Replies: 0
    Last Post: 01-24-2009, 11:03 PM
  4. Intercept the MIDI Out
    By MattMik in forum C++ Programming
    Replies: 2
    Last Post: 10-18-2007, 02:05 AM
  5. Playing a Midi. (win32 console) (MSVC++)
    By knave in forum Windows Programming
    Replies: 3
    Last Post: 05-17-2003, 10:40 AM

Tags for this Thread