Exemplo n.º 1
0
void StopNoteEvent::performEvent(MidiOutputDevice &device) const
{
#if defined(LOG_MIDI_EVENTS)
    qDebug() << "Stop Note: " << mySystem << ", " << myPosition << " at " <<
                myStartTime;
#endif

    device.stopNote(myChannel, myPitch);
}
Exemplo n.º 2
0
void MidiPlayer::performCountIn(MidiOutputDevice &device,
                                const SystemLocation &location,
                                int beat_duration)
{
    // Load preferences.
    uint8_t velocity;
    uint8_t preset;
    {
        auto settings = mySettingsManager.getReadHandle();

        if (!settings->get(Settings::CountInEnabled))
            return;

        velocity = settings->get(Settings::CountInVolume);
        preset = settings->get(Settings::CountInPreset) +
                 Midi::MIDI_PERCUSSION_PRESET_OFFSET;
    }

    // Figure out the time signature where playback is starting.
    const System &system = myScore.getSystems()[location.getSystem()];
    const Barline *barline = system.getPreviousBarline(location.getPosition());
    if (!barline)
        barline = &system.getBarlines().front();

    const TimeSignature &time_sig = barline->getTimeSignature();

    const int tick_duration = boost::rational_cast<int>(
        boost::rational<int>(4, time_sig.getBeatValue()) *
        boost::rational<int>(time_sig.getBeatsPerMeasure(),
                             time_sig.getNumPulses()) * beat_duration);

    // Play the count-in.
    device.setChannelMaxVolume(METRONOME_CHANNEL,
                               Midi::MAX_MIDI_CHANNEL_VOLUME);

    for (int i = 0; i < time_sig.getNumPulses(); ++i)
    {
        if (!isPlaying())
            break;

        device.playNote(METRONOME_CHANNEL, preset, velocity);
        usleep(tick_duration * (100.0 / myPlaybackSpeed));
        device.stopNote(METRONOME_CHANNEL, preset);
    }
}