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

Player volume fix #303

Merged
merged 2 commits into from
Nov 22, 2020
Merged

Conversation

mostafa-nabil
Copy link
Contributor

Description of Change(s)

The changes fixes the issue that each individual player volume in the mixer cannot be set/has no effect. The change involves handling volume change midi events separate from other event, as well as a small modification in the midievent class

Fixes Issue(s)

#276

midiplayer.cpp -> volumechanged event is treated separately in order to include the maxVolume threshold
midievent.cpp -> added a check isVolumeChange()
Copy link
Member

@cameronwhite cameronwhite left a comment

Choose a reason for hiding this comment

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

This looks good, thanks for working on this!

Just a couple minor things noted in the comments, and a possible alternative to getPlayerFromChannel() that I'm unsure about.

@@ -279,3 +297,26 @@ bool MidiPlayer::isPlaying() const
{
return myIsPlaying;
}

int MidiPlayer::getPlayerFromChannel(const int channel)
Copy link
Member

Choose a reason for hiding this comment

The 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 MidiEvent, which avoids having to duplicate the logic for how players are assigned to channels. (There's actually an unused myPlayer member variable in MidiEvent that was intended for this.purpose, but the myInstrument member should probably be removed).

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:

../source/audio/midiplayer.cpp:314:14: warning: variable 'player' is used uninitialized whenever 'if' condition is false [-Wsometimes-uninitialized]
    else if (channel > METRONOME_CHANNEL)
             ^~~~~~~~~~~~~~~~~~~~~~~~~~~
../source/audio/midiplayer.cpp:319:12: note: uninitialized use occurs here
    return player;
           ^~~~~~
../source/audio/midiplayer.cpp:314:10: note: remove the 'if' if its condition is always true
    else if (channel > METRONOME_CHANNEL)
         ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
../source/audio/midiplayer.cpp:303:15: note: initialize the variable 'player' to silence this warning
    int player;
              ^
               = 0
1 warning generated.

// handle volume change events
// using device.setVolume() ensures that the maximum volume threshold
// is taken into consideration
if(event -> isVolumeChange())
Copy link
Member

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())

// is taken into consideration
if(event -> isVolumeChange())
{
device.setVolume(channel, event->getData()[2]);
Copy link
Member

Choose a reason for hiding this comment

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

Could you wrap the event->getData()[2] in a function similar to MidiEvent::getTempo()? It's nice to encapsulate the MIDI details in that class.

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

Successfully merging this pull request may close these issues.

2 participants