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

midifixes #214

Merged
merged 22 commits into from Dec 3, 2017
Merged

midifixes #214

merged 22 commits into from Dec 3, 2017

Conversation

danomatika
Copy link
Contributor

@danomatika danomatika commented Aug 29, 2017

This PR is an offshoot of #211 which only contains the MIDI bug fixes and code cleanups:

  • fix portmidi infinite loop bug when receiving active sense during running status messages on macOS (submitted and accepted upstream)
  • fix port midi string encoding bug on macOS (via upstream)
  • all message types should now be received and sent
  • slight code cleanup favoring MIDI status byte defines for readability and some commenting
  • remove unused [midiclkin] object ala removing [midiclkin] and updating documentation accordingly #187
  • midiout should send float lists

The work so far has been tested with a simple utility program I wrote (miditester) and Logic Pro X on macOS. This will need testing on other platforms.

@danomatika danomatika self-assigned this Aug 29, 2017
@danomatika danomatika added the bug/fix either a bug (for issues) or a bugfix (for pull-requests) label Aug 29, 2017
This was referenced Aug 29, 2017
Copy link
Contributor

@umlaeute umlaeute left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

since i heartily despise MIDI i don't have any real comment. luckily coverity-scan discovered a few implementation details for me (see the note on dead code).

the implementation in s_midi.c seems to not have this problem, by doing something like status = (status>=MIDI_SYSEX)?status:(status&0xf0)

snd_seq_ev_set_noteon(&ev,channel,b,c);
}
else if (a >= 128) // note off
status = a & 0xf0;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

so status <= 0xf0 (240)...

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The status value is the upper nibble and the channel is the lower nibble for those messages which have them. This masks out the channel.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, I see what you're saying. That should be:

status = a & 0xFF;
if (status < MIDI_SYSEX) status = status & 0xF0;

/* b and c are already correct but alsa needs to recalculate them */
snd_seq_ev_set_pitchbend(&ev, channel, (((c<<7)|b)-8192));
break;
case MIDI_TIMECODE:
Copy link
Contributor

@umlaeute umlaeute Aug 30, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

and MIDI_TIMECODE:=0xf1 (241); so how on earth is status == MIDI_TIMECODE ever going to be true?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the same holds for SONGPOS and SONGSELECT

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch. Fixed.

@danomatika
Copy link
Contributor Author

@umlaeute As you detest MIDI, I'm guessing you're not interested in running some tests?

@danomatika
Copy link
Contributor Author

I added the midi test patch I've ben using to docs/7.stuff/tools. It sends & receives all MIDI messages.

@umlaeute
Copy link
Contributor

umlaeute commented Aug 30, 2017 via email

@danomatika
Copy link
Contributor Author

@umlaeute Neither do I right now. That's why I wrote a test utility: https://github.com/danomatika/miditester

It you run it with the -n -d flags, the values are pretty much the same so comparing the output in the doc/7.stuff/tools/miditester.pd patch is relatively easy. The only caveats are that sending from Pd results in controller and program numbers off by 1 due to Pd adding 1.

src/x_midi.c Outdated
@@ -586,11 +586,21 @@ static void midiout_float(t_midiout *x, t_floatarg f)
outmidi_byte(x->x_portno - 1, f);
}

static void midiout_list(t_midiout *x, t_symbol *s, int ac, t_atom *av)
{
for (int i = 0; i < ac; ++i)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is only valid in C99; since adding support for ANSI C is pretty straightforward, i would suggest to use:

int i;
for (i = 0; i < ac; ++i)
{
   // ..
}

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Got it. Is C99 still a hard limit? I suppose so if we want to continue supporting Windows XP builds? :P

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug/fix either a bug (for issues) or a bugfix (for pull-requests)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants