void broadcastPMIObject(T& obj) { if (isController()) { pmi::transmit::broadcastPMIObjectId(obj.getObjectId()); } else PMI_THROW_USER_ERROR("Called broadcastObject on worker!"); }
T* receivePMIObjectPtr() { if (isController()) PMI_THROW_USER_ERROR("Called receiveObjectPtr on controller!") else { IdType oid = pmi::transmit::receivePMIObjectId(); return getPMIObjectPtr<T>(oid); } }
float Joystick::getAxisValue(int8_t axis) const { if (axis < 0 || !isConnected()) { return 0; } if (!isController()) { return convertRange(SDL_JoystickGetAxis(m_joystickHandle, axis)); } SDL_GameControllerAxis sdlAxis = static_cast<SDL_GameControllerAxis>(axis); return convertRange(SDL_GameControllerGetAxis(m_controllerHandle, sdlAxis)); }
bool Joystick::isButtonPressed(int8_t button) const { if (button < 0 || !isConnected()) { return false; } if (!isController()) { if (SDL_JoystickGetButton(m_joystickHandle, button) == 1) { return true; } return false; } SDL_GameControllerButton sdlButton = static_cast<SDL_GameControllerButton>(button); if (SDL_GameControllerGetButton(m_controllerHandle, sdlButton) == 1) { return true; } return false; }
String MidiMessage::getDescription() const { if (isNoteOn()) return "Note on " + MidiMessage::getMidiNoteName (getNoteNumber(), true, true, 3) + " Velocity " + String (getVelocity()) + " Channel " + String (getChannel()); if (isNoteOff()) return "Note off " + MidiMessage::getMidiNoteName (getNoteNumber(), true, true, 3) + " Velocity " + String (getVelocity()) + " Channel " + String (getChannel()); if (isProgramChange()) return "Program change " + String (getProgramChangeNumber()) + " Channel " + String (getChannel()); if (isPitchWheel()) return "Pitch wheel " + String (getPitchWheelValue()) + " Channel " + String (getChannel()); if (isAftertouch()) return "Aftertouch " + MidiMessage::getMidiNoteName (getNoteNumber(), true, true, 3) + ": " + String (getAfterTouchValue()) + " Channel " + String (getChannel()); if (isChannelPressure()) return "Channel pressure " + String (getChannelPressureValue()) + " Channel " + String (getChannel()); if (isAllNotesOff()) return "All notes off Channel " + String (getChannel()); if (isAllSoundOff()) return "All sound off Channel " + String (getChannel()); if (isMetaEvent()) return "Meta event"; if (isController()) { String name (MidiMessage::getControllerName (getControllerNumber())); if (name.isEmpty()) name = String (getControllerNumber()); return "Controller " + name + ": " + String (getControllerValue()) + " Channel " + String (getChannel()); } return String::toHexString (getRawData(), getRawDataSize()); }
void Joystick::open() { if (m_joystickHandle) { close(); } m_joystickHandle = SDL_JoystickOpen(m_deviceIndex); if (m_joystickHandle) { m_instanceId = SDL_JoystickInstanceID(m_joystickHandle); char tmp[33]; SDL_JoystickGUID guid = SDL_JoystickGetDeviceGUID(m_deviceIndex); SDL_JoystickGetGUIDString(guid, tmp, sizeof(tmp)); m_guidStr = std::string(tmp); openController(); const char* name = SDL_JoystickNameForIndex(m_deviceIndex); if (isController() && !name) { name = SDL_GameControllerNameForIndex(m_deviceIndex); } m_name = std::string(name); } else { throw SDLException(SDL_GetError()); } }
int MidiMessage::getControllerValue() const noexcept { jassert (isController()); return getRawData()[2]; }
GameController::GameController(int index) : Joystick(index), _sdlController(0) { if (!isController()) throw Common::Exception("GameController::GameController() joystick %i is not a controller", getIndex()); }