本文整理汇总了C++中MidiEvent::NoteVelocity方法的典型用法代码示例。如果您正苦于以下问题:C++ MidiEvent::NoteVelocity方法的具体用法?C++ MidiEvent::NoteVelocity怎么用?C++ MidiEvent::NoteVelocity使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类MidiEvent
的用法示例。
在下文中一共展示了MidiEvent::NoteVelocity方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: Update
//.........这里部分代码省略.........
delete m_state.midi_in;
m_state.midi_in = 0;
if (input_id >= 0) {
try {
m_state.midi_in = new MidiCommIn(input_id);
UserSetting::Set(InputDeviceKey, m_state.midi_in->GetDeviceDescription().name);
}
catch (MidiErrorCode) {
m_state.midi_in = 0;
}
}
else
UserSetting::Set(InputDeviceKey, InputKeySpecialDisabled);
}
if (m_state.midi_in && m_input_tile->IsPreviewOn()) {
// Read note events to display on screen
while (m_state.midi_in->KeepReading()) {
MidiEvent ev = m_state.midi_in->Read();
// send to output (for a possible audio preview)
if (m_state.midi_out)
m_state.midi_out->Write(ev);
if (ev.Type() == MidiEventType_NoteOff || ev.Type() == MidiEventType_NoteOn) {
string note = MidiEvent::NoteName(ev.NoteNumber());
if (ev.Type() == MidiEventType_NoteOn && ev.NoteVelocity() > 0)
m_last_input_note_name = note;
else
if (note == m_last_input_note_name)
m_last_input_note_name = "";
}
}
}
else
m_last_input_note_name = "";
if (IsKeyPressed(KeyEscape) || m_back_button.hit) {
delete m_state.midi_out;
m_state.midi_out = 0;
delete m_state.midi_in;
m_state.midi_in = 0;
delete m_state.midi;
m_state.midi = 0;
Compatible::GracefulShutdown();
return;
}
if (IsKeyPressed(KeyEnter) || m_continue_button.hit) {
if (m_state.midi_out)
m_state.midi_out->Reset();
示例2: Listen
void PlayingState::Listen() {
if (!m_state.midi_in)
return;
while (m_state.midi_in->KeepReading()) {
microseconds_t cur_time = m_state.midi->GetSongPositionInMicroseconds();
MidiEvent ev = m_state.midi_in->Read();
if (m_state.midi_in->ShouldReconnect())
{
m_state.midi_in->Reconnect();
m_state.midi_out->Reconnect();
continue;
}
// Just eat input if we're paused
if (m_paused)
continue;
// We're only interested in NoteOn and NoteOff
if (ev.Type() != MidiEventType_NoteOn && ev.Type() != MidiEventType_NoteOff)
continue;
// Octave Sliding
ev.ShiftNote(m_note_offset);
int note_number = ev.NoteNumber();
string note_name = MidiEvent::NoteName(note_number);
// On key release we have to look for existing "active" notes and turn them off.
if (ev.Type() == MidiEventType_NoteOff || ev.NoteVelocity() == 0) {
// NOTE: This assumes mono-channel input. If they're piping an entire MIDI file
// (or even the *same* MIDI file) through another source, we could get the
// same NoteId on different channels -- and this code would start behaving
// incorrectly.
for (ActiveNoteSet::iterator i = m_active_notes.begin(); i != m_active_notes.end(); ++i) {
if (ev.NoteNumber() != i->note_id)
continue;
// Play it on the correct channel to turn the note we started
// previously, off.
ev.SetChannel(i->channel);
if (m_state.midi_out)
m_state.midi_out->Write(ev);
m_active_notes.erase(i);
break;
}
// User releases the key
// If we delete this line, than all pressed keys will be gray until
// it is unpressed automatically
m_keyboard->SetKeyActive(note_name, false, Track::FlatGray);
userPressedKey(note_number, false);
continue;
}
TranslatedNoteSet::iterator closest_match = m_notes.end();
for (TranslatedNoteSet::iterator i = m_notes.begin(); i != m_notes.end(); ++i) {
const microseconds_t window_start = i->start - (KeyboardDisplay::NoteWindowLength / 2);
const microseconds_t window_end = i->start + (KeyboardDisplay::NoteWindowLength / 2);
// As soon as we start processing notes that couldn't possibly
// have been played yet, we're done.
if (window_start > cur_time)
break;
if (i->state != UserPlayable)
continue;
if (window_end > cur_time && i->note_id == ev.NoteNumber()) {
if (closest_match == m_notes.end()) {
closest_match = i;
continue;
}
microseconds_t this_distance = cur_time - i->start;
if (i->start > cur_time)
this_distance = i->start - cur_time;
microseconds_t known_best = cur_time - closest_match->start;
if (closest_match->start > cur_time)
known_best = closest_match->start - cur_time;
if (this_distance < known_best)
closest_match = i;
}
}
Track::TrackColor note_color = Track::FlatGray;
if (closest_match != m_notes.end()) {
note_color = m_state.track_properties[closest_match->track_id].color;
// "Open" this note so we can catch the close later and turn off
// the note.
//.........这里部分代码省略.........