Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Note Off command not working #291

Open
pnome opened this issue Jun 19, 2020 · 5 comments
Open

Note Off command not working #291

pnome opened this issue Jun 19, 2020 · 5 comments
Assignees
Labels

Comments

@pnome
Copy link

pnome commented Jun 19, 2020

I’m sure this is just something I’m not understanding, but I used the following code to try and play a note for 2 seconds. The note off command is never implemented.

I can add a third command for a different note on after 3 seconds, and I’ll end up hearing both. They just never turn off.

Can somebody help me understand what I’m doing wrong? Thanks!

`- (IBAction)sendNote:(id)sender//testing
{

MIKMIDIClientDestinationEndpoint *destinationEndpoint = [[MIKMIDIClientDestinationEndpoint alloc] initWithName:@"SimpleVirtualSynth" receivedMessagesHandler:nil];
self.synthesizer = [[MIKMIDIEndpointSynthesizer alloc] initWithClientDestinationEndpoint:destinationEndpoint];

NSDate *date = [NSDate date];
MIKMIDINoteOnCommand *noteOn = [MIKMIDINoteOnCommand noteOnCommandWithNote:60 velocity:127 channel:0 timestamp:date];
MIKMIDINoteOffCommand *noteOff = [MIKMIDINoteOffCommand noteOffCommandWithNote:60 velocity:0 channel:0 timestamp:[date dateByAddingTimeInterval:2.0]];

MIKMIDIDeviceManager *dm = [MIKMIDIDeviceManager sharedDeviceManager];
NSError *error = nil;
if (![dm sendCommands:@[noteOn,noteOff] toEndpoint:destinationEndpoint error:&error]) {
    NSLog(@"Unable to send note to %@: %@", destinationEndpoint, error);
}

}
`

@armadsen armadsen self-assigned this Jun 19, 2020
@armadsen
Copy link
Member

Hi @pnome,

MIKMIDIClientDestinationEndpoint is a virtual endpoint used to receive events from other apps running on the system. You can't send MIDI commands to it that way. In any case, MIKMIDIEndpointSynthesizer is specifically for synthesizing events coming into your app from an external source (either other apps or a hardware device). If you just want to synthesize local MIDI, use plain MIKMIDISynthesizer. Try this:

- (IBAction)sendNote:(id)sender//testing
{
    NSError *error = nil;
    self.synthesizer = [[MIKMIDISynthesizer alloc] initWithError:&error];
    if (!self.synthesizer) {
        NSLog(@"Error creating synthesizer: %@", error);
    }

    NSDate *date = [NSDate date];
    MIKMIDINoteOnCommand *noteOn = [MIKMIDINoteOnCommand noteOnCommandWithNote:60 velocity:127 channel:0 timestamp:date];
    MIKMIDINoteOffCommand *noteOff = [MIKMIDINoteOffCommand noteOffCommandWithNote:60 velocity:0 channel:0 timestamp:[date dateByAddingTimeInterval:2.0]];

    [self.synthesizer handleMIDIMessages:@[noteOn, noteOff]];
}

@pnome
Copy link
Author

pnome commented Jun 19, 2020

Hi @armadsen ,

I tried that, and I'm experiencing the same problem. I tested by adding a second note to play at [date dateByAddingTimeInterval:4.0] with noteOff at [date dateByAddingTimeInterval:4.0]

When I run the code, both notes play immediately, and never turn off. As if all supplied midi notes are being handled immediately, rather than paying attention to the supplied timestamps.

You can see it in action here: https://www.youtube.com/watch?v=Zzpm2neuBRA

Any suggestions?
Thanks again,
Joe

@armadsen
Copy link
Member

Hi Joe,

Interesting. I wrote the code I sent in a little test app that works fine. I didn't realize you were on iOS (I tested on macOS). It should work exactly the same, but perhaps there's an iOS-specific bug there. I'll dig a little more later this afternoon and will have more for you.

@pnome
Copy link
Author

pnome commented Jun 23, 2020

Hi Andrew,
Just wondering if you made any progress with this. I'd love to use MIDI in my app, and this seems like the way to go, but I can't get past this issue at the moment.
Thanks,
Joe

@pnome
Copy link
Author

pnome commented Jul 10, 2020

Hi @armadsen,
I hope all's well. Did you ever figure out if you could get it working on iOS?

Best,
Joe

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants