MidiCommDescriptionList MidiCommOut::GetDeviceList() { if (built_output_list) return out_list; MidiCommDescriptionList devices; // Add the built-in synth MidiCommDescription mac_synth; mac_synth.id = 0; mac_synth.name = L"Built-in MIDI Synthesizer"; devices.push_back(mac_synth); // Add any external devices ItemCount destinations = MIDIGetNumberOfDestinations(); for (int i = 0; i < destinations; ++i) { MIDIEndpointRef endpoint = MIDIGetDestination(i); CFStringRef cf_name = BuildEndpointName(endpoint); MidiCommDescription d; d.id = i + 1; d.name = WideFromMacString(cf_name); CFRelease(cf_name); devices.push_back(d); } built_output_list = true; return devices; }
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; }
MidiCommDescriptionList MidiCommOut::GetDeviceList() { MidiCommDescriptionList devices; unsigned int dev_count = midiOutGetNumDevs(); for (unsigned int i = 0; i < dev_count; ++i) { MIDIOUTCAPS dev; midi_check(midiOutGetDevCaps(i, &dev, sizeof(MIDIOUTCAPS))); MidiCommDescription d; d.id = i; d.name = dev.szPname; devices.push_back(d); } return devices; }
MidiCommDescriptionList MidiCommIn::GetDeviceList() { MidiCommDescriptionList devices; unsigned int dev_count = midiInGetNumDevs(); for (unsigned int i = 0; i < dev_count; ++i) { MIDIINCAPS dev; const static int MaxTries = 10; int tries = 0; while (tries++ < MaxTries) { try { midi_check(midiInGetDevCaps(i, &dev, sizeof(MIDIINCAPS))); break; } catch (MidiError ex) { // Sometimes input needs to take a quick break if (ex.m_error != MidiError_MM_NotEnabled) throw; Sleep(50); } } if (tries == MaxTries) throw MidiError_MM_NotEnabled; MidiCommDescription d; d.id = i; d.name = dev.szPname; devices.push_back(d); } return devices; }
MidiCommDescriptionList MidiCommIn::GetDeviceList() { if (built_input_list) return in_list; MidiCommDescriptionList devices; ItemCount sources = MIDIGetNumberOfSources(); for (int i = 0; i < sources; ++i) { MIDIEndpointRef endpoint = MIDIGetSource(i); CFStringRef cf_name = BuildEndpointName(endpoint); MidiCommDescription d; d.id = i; d.name = WideFromMacString(cf_name); CFRelease(cf_name); devices.push_back(d); } built_input_list = true; return devices; }
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)); }