Looking to optimize a routine

I have a program running on an Arduino that pulses a pin about 500 times a second.

Each time the pulse is high, it needs to poll a (normally low) return pin to see if that is high.

If the pin is high, and it's previous state was low, it needs to send out serial MIDI data.

If however the pin is low, and it was previously high, it needs to send out another MIDI message (note off).

The only additional complication is that the pulses are in groups of 10, that is pulse one sends MIDI message note 1, pulse 2 sends MIDI message note 2... and so on all the way up to pulse 10 sending message for note 10. Then it returns the count back to one.

Is there an optimal way of coding this arrangement, using 10 bits from an int to store previous state of each pulse return?

ie.

If (pin_gone_high) { send MIDI 'on' for this pulse update 'previous pin state' as high } else if (pin_gone_low) { send MIDI 'off' for this puls update 'previous pin state' as low }

I can code this in simple C, but I was wondering if there was a slick way using bitwise operations.

(Let me know if this makes any sense...)