コード例 #1
0
void DeviceTile::ReplaceDeviceList(const MidiCommDescriptionList &device_list)
{
  if (m_device_id != -1)
  {
      // Try to find currently selected device amoung devices in the new list
      std::string current_name = m_device_list[m_device_id].name;
      int device_id = 0;
      bool replaced = false;
      int size = device_list.size();
      for (; device_id < size; device_id++)
      {
        std::string iter_name = device_list[device_id].name;
        if (current_name == iter_name)
        {
          // Found device
          m_device_id = device_id;
          replaced = true;
          break;
        }
      }
      // The selected device was removed
      if (!replaced)
        m_device_id = -1;
  }
  m_device_list = device_list;
}
コード例 #2
0
ファイル: TitleState.cpp プロジェクト: qdii/linthesia
void TitleState::Init() {

   m_back_button = ButtonState(
      Layout::ScreenMarginX,
      GetStateHeight() - Layout::ScreenMarginY/2 - Layout::ButtonHeight/2,
      Layout::ButtonWidth, Layout::ButtonHeight);

   m_continue_button = ButtonState(
      GetStateWidth() - Layout::ScreenMarginX - Layout::ButtonWidth,
      GetStateHeight() - Layout::ScreenMarginY/2 - Layout::ButtonHeight/2,
      Layout::ButtonWidth, Layout::ButtonHeight);

   string last_output_device = UserSetting::Get(OutputDeviceKey, "");
   string last_input_device = UserSetting::Get(InputDeviceKey, "");

   // midi_out could be in one of three states right now:
   //    1. We just started and were passed a null MidiCommOut pointer
   // Or, we're returning from track selection either with:
   //    2. a null MidiCommOut because the user didn't want any output, or
   //    3. a valid MidiCommOut we constructed previously.
   if (!m_state.midi_out) {

      // Try to find the previously used device
     MidiCommDescriptionList devices = MidiCommOut::GetDeviceList();
     MidiCommDescriptionList::const_iterator it;
     for (it = devices.begin(); it != devices.end(); it++) {
       if (it->name == last_output_device) {
         m_state.midi_out = new MidiCommOut(it->id);
         break;
       }
     }

     // Next, if we couldn't find a previously used device,
     // use the first one
     if (last_output_device != OutputKeySpecialDisabled &&
         !m_state.midi_out && devices.size() > 0)

       m_state.midi_out = new MidiCommOut(devices[0].id);
   }

   if (!m_state.midi_in) {

     // Try to find the previously used device
     MidiCommDescriptionList devices = MidiCommIn::GetDeviceList();
     MidiCommDescriptionList::const_iterator it;
     for (it = devices.begin(); it != devices.end(); it++) {
       if (it->name == last_input_device) {
         try {
           m_state.midi_in = new MidiCommIn(it->id);
           break;
         }
         catch (MidiErrorCode) {
           m_state.midi_in = 0;
         }
       }
     }

     // If we couldn't find the previously used device,
     // disabling by default (i.e. leaving it null) is
     // completely acceptable.
   }

   int output_device_id = -1;
   if (m_state.midi_out) {
     output_device_id = m_state.midi_out->GetDeviceDescription().id;
     m_state.midi_out->Reset();
   }

   int input_device_id = -1;
   if (m_state.midi_in) {
     input_device_id = m_state.midi_in->GetDeviceDescription().id;
     m_state.midi_in->Reset();
   }

   const bool compress_height = (GetStateHeight() < 750);
   const int initial_y = (compress_height ? 230 : 360);
   const int each_y = (compress_height ? 94 : 100);

   m_file_tile = new StringTile((GetStateWidth() - StringTileWidth) / 2,
                                initial_y + each_y*0,
                                GetTexture(SongBox));

   m_file_tile->SetString(m_state.song_title);

   const MidiCommDescriptionList output_devices = MidiCommOut::GetDeviceList();
   const MidiCommDescriptionList input_devices = MidiCommIn::GetDeviceList();

   m_output_tile = new DeviceTile((GetStateWidth() - DeviceTileWidth) / 2,
                                  initial_y + each_y*1,
                                  output_device_id,
                                  DeviceTileOutput,
                                  output_devices,
                                  GetTexture(InterfaceButtons),
                                  GetTexture(OutputBox));

   m_input_tile = new DeviceTile((GetStateWidth() - DeviceTileWidth) / 2,
                                 initial_y + each_y*2,
                                 input_device_id,
                                 DeviceTileInput,
                                 input_devices,
                                 GetTexture(InterfaceButtons),
                                 GetTexture(InputBox));
}