Changeset View
Changeset View
Standalone View
Standalone View
src/context.h
Show First 20 Lines • Show All 80 Lines • ▼ Show 20 Line(s) | 44 | public: | |||
---|---|---|---|---|---|
81 | void setDefaultSink(const QString &name); | 81 | void setDefaultSink(const QString &name); | ||
82 | void setDefaultSource(const QString &name); | 82 | void setDefaultSource(const QString &name); | ||
83 | void streamRestoreWrite(const pa_ext_stream_restore_info *info); | 83 | void streamRestoreWrite(const pa_ext_stream_restore_info *info); | ||
84 | 84 | | |||
85 | template <typename PAFunction> | 85 | template <typename PAFunction> | ||
86 | void setGenericVolume(quint32 index, int channel, qint64 newVolume, | 86 | void setGenericVolume(quint32 index, int channel, qint64 newVolume, | ||
87 | pa_cvolume cVolume, PAFunction pa_set_volume) | 87 | pa_cvolume cVolume, PAFunction pa_set_volume) | ||
88 | { | 88 | { | ||
89 | if (!m_context) { | ||||
90 | return; | ||||
91 | } | ||||
89 | newVolume = qBound<qint64>(0, newVolume, PA_VOLUME_MAX); | 92 | newVolume = qBound<qint64>(0, newVolume, PA_VOLUME_MAX); | ||
90 | pa_cvolume newCVolume = cVolume; | 93 | pa_cvolume newCVolume = cVolume; | ||
91 | if (channel == -1) { // -1 all channels | 94 | if (channel == -1) { // -1 all channels | ||
92 | for (int i = 0; i < newCVolume.channels; ++i) { | 95 | for (int i = 0; i < newCVolume.channels; ++i) { | ||
93 | newCVolume.values[i] = newVolume; | 96 | newCVolume.values[i] = newVolume; | ||
94 | } | 97 | } | ||
95 | } else { | 98 | } else { | ||
96 | Q_ASSERT(newCVolume.channels > channel); | 99 | Q_ASSERT(newCVolume.channels > channel); | ||
97 | newCVolume.values[channel] = newVolume; | 100 | newCVolume.values[channel] = newVolume; | ||
98 | } | 101 | } | ||
99 | if (!PAOperation(pa_set_volume(m_context, index, &newCVolume, nullptr, nullptr))) { | 102 | if (!PAOperation(pa_set_volume(m_context, index, &newCVolume, nullptr, nullptr))) { | ||
100 | qCWarning(PLASMAPA) << "pa_set_volume failed"; | 103 | qCWarning(PLASMAPA) << "pa_set_volume failed"; | ||
101 | return; | 104 | return; | ||
102 | } | 105 | } | ||
103 | } | 106 | } | ||
104 | 107 | | |||
105 | template <typename PAFunction> | 108 | template <typename PAFunction> | ||
106 | void setGenericMute(quint32 index, bool mute, PAFunction pa_set_mute) | 109 | void setGenericMute(quint32 index, bool mute, PAFunction pa_set_mute) | ||
107 | { | 110 | { | ||
111 | if (!m_context) { | ||||
112 | return; | ||||
113 | } | ||||
108 | if (!PAOperation(pa_set_mute(m_context, index, mute, nullptr, nullptr))) { | 114 | if (!PAOperation(pa_set_mute(m_context, index, mute, nullptr, nullptr))) { | ||
109 | qCWarning(PLASMAPA) << "pa_set_mute failed"; | 115 | qCWarning(PLASMAPA) << "pa_set_mute failed"; | ||
110 | return; | 116 | return; | ||
111 | } | 117 | } | ||
112 | } | 118 | } | ||
113 | 119 | | |||
114 | template <typename PAFunction> | 120 | template <typename PAFunction> | ||
115 | void setGenericPort(quint32 index, const QString &portName, PAFunction pa_set_port) | 121 | void setGenericPort(quint32 index, const QString &portName, PAFunction pa_set_port) | ||
116 | { | 122 | { | ||
123 | if (!m_context) { | ||||
124 | return; | ||||
125 | } | ||||
117 | if (!PAOperation(pa_set_port(m_context, | 126 | if (!PAOperation(pa_set_port(m_context, | ||
118 | index, | 127 | index, | ||
119 | portName.toUtf8().constData(), | 128 | portName.toUtf8().constData(), | ||
120 | nullptr, | 129 | nullptr, | ||
121 | nullptr))) { | 130 | nullptr))) { | ||
122 | qCWarning(PLASMAPA) << "pa_set_port failed"; | 131 | qCWarning(PLASMAPA) << "pa_set_port failed"; | ||
123 | return; | 132 | return; | ||
124 | } | 133 | } | ||
125 | } | 134 | } | ||
126 | 135 | | |||
127 | template <typename PAFunction> | 136 | template <typename PAFunction> | ||
128 | void setGenericDeviceForStream(quint32 streamIndex, | 137 | void setGenericDeviceForStream(quint32 streamIndex, | ||
129 | quint32 deviceIndex, | 138 | quint32 deviceIndex, | ||
130 | PAFunction pa_move_stream_to_device) | 139 | PAFunction pa_move_stream_to_device) | ||
131 | { | 140 | { | ||
141 | if (!m_context) { | ||||
142 | return; | ||||
143 | } | ||||
132 | if (!PAOperation(pa_move_stream_to_device(m_context, | 144 | if (!PAOperation(pa_move_stream_to_device(m_context, | ||
133 | streamIndex, | 145 | streamIndex, | ||
134 | deviceIndex, | 146 | deviceIndex, | ||
135 | nullptr, | 147 | nullptr, | ||
136 | nullptr))) { | 148 | nullptr))) { | ||
137 | qCWarning(PLASMAPA) << "pa_move_stream_to_device failed"; | 149 | qCWarning(PLASMAPA) << "pa_move_stream_to_device failed"; | ||
138 | return; | 150 | return; | ||
139 | } | 151 | } | ||
Show All 26 Lines |