当前位置: 首页>>代码示例>>C++>>正文


C++ MidiEvent::NoteNumber方法代码示例

本文整理汇总了C++中MidiEvent::NoteNumber方法的典型用法代码示例。如果您正苦于以下问题:C++ MidiEvent::NoteNumber方法的具体用法?C++ MidiEvent::NoteNumber怎么用?C++ MidiEvent::NoteNumber使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在MidiEvent的用法示例。


在下文中一共展示了MidiEvent::NoteNumber方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: Update


//.........这里部分代码省略.........
     m_last_input_note_name = "";

     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)
开发者ID:qdii,项目名称:linthesia,代码行数:67,代码来源:TitleState.cpp

示例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.
//.........这里部分代码省略.........
开发者ID:gitter-badger,项目名称:linthesia,代码行数:101,代码来源:PlayingState.cpp


注:本文中的MidiEvent::NoteNumber方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。