-
Notifications
You must be signed in to change notification settings - Fork 71
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
Player volume fix #303
Player volume fix #303
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -185,11 +185,29 @@ void MidiPlayer::run() | |
if (!(event->isNoteOnOff() && | ||
event->getChannel() == METRONOME_CHANNEL && | ||
!myMetronomeEnabled) && | ||
!event->isTempoChange() && !event->isTrackEnd()) | ||
!event->isTempoChange() && | ||
!event->isTrackEnd() && | ||
!event->isVolumeChange()) | ||
{ | ||
device.sendMessage(event->getData()); | ||
} | ||
|
||
// get the channel and the correspondin player | ||
int channel = event->getChannel(); | ||
int player = getPlayerFromChannel(channel); | ||
// if the channel corresponds to a valid player, set its maximum volume | ||
if(player != -1) | ||
{ | ||
device.setChannelMaxVolume(channel, myScore.getPlayers()[player].getMaxVolume()); | ||
} | ||
// handle volume change events | ||
// using device.setVolume() ensures that the maximum volume threshold | ||
// is taken into consideration | ||
if(event -> isVolumeChange()) | ||
{ | ||
device.setVolume(channel, event->getData()[2]); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Could you wrap the |
||
} | ||
|
||
// Notify listeners of the current playback position. | ||
if (event->getLocation() != current_location) | ||
{ | ||
|
@@ -279,3 +297,26 @@ bool MidiPlayer::isPlaying() const | |
{ | ||
return myIsPlaying; | ||
} | ||
|
||
int MidiPlayer::getPlayerFromChannel(const int channel) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. An alternative to this function would be to record the player number on the What are your thoughts on that? If we stick with the current approach, those unused members should be removed, and there's also a compiler warning (below) where the compiler incorrectly thinks the result could be uninitialized:
|
||
{ | ||
int player; | ||
|
||
//check for invalid channel | ||
if (METRONOME_CHANNEL == channel || 15 == channel) | ||
{ | ||
player = -1; | ||
} | ||
else if (channel < METRONOME_CHANNEL) | ||
{ | ||
player = channel; | ||
} | ||
else if (channel > METRONOME_CHANNEL) | ||
{ | ||
player = channel - 1; | ||
} | ||
|
||
return player; | ||
|
||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The formatting is a bit inconsistent here - should be
if (event->isVolumeChange())