Skip to content

Commit

Permalink
When only spectrum data is required, prevent sending json over WS, to…
Browse files Browse the repository at this point in the history
… reduce cpu usage.
  • Loading branch information
rbn42 committed Dec 22, 2020
1 parent 6213da7 commit c08aa84
Show file tree
Hide file tree
Showing 6 changed files with 20 additions and 8 deletions.
4 changes: 4 additions & 0 deletions panon/backend/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,10 @@ async def mainloop():
if arguments['--enable-spectrum-data']:
spectrum_data = np.clip(spectrum_data[1:] / 3.0, 0, 0.99) * 256
spectrum_data_m = n2s.convert(spectrum_data)
# When only spectrum data is enabled, send raw data to reduce cpu usage.
if not arguments['--enable-wave-data']:
await websocket.send(spectrum_data_m)
continue
obj['spectrum'] = spectrum_data_m

await websocket.send(json.dumps(obj))
Expand Down
17 changes: 12 additions & 5 deletions plasmoid/contents/ui/MessageQueue.qml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ import QtQuick 2.0
*/

Item{
// When only spectrum data is enabled, receive raw data to reduce cpu usage.
property bool only_spectrum:false

readonly property var cfg:plasmoid.configuration

Expand All @@ -25,11 +27,16 @@ Item{
imgsLoading.used=false
imgsLoading.w.source = 'data:' + message
}else{
var obj = JSON.parse(message)
imgsLoading.used=false
imgsLoading.s.source = 'data:' + obj.spectrum
imgsLoading.w.source = 'data:' + obj.wave
imgsLoading.beat = obj.beat
if(only_spectrum){
imgsLoading.used=false
imgsLoading.s.source = 'data:' + message
}else{
var obj = JSON.parse(message)
imgsLoading.used=false
imgsLoading.s.source = 'data:' + obj.spectrum
imgsLoading.w.source = 'data:' + obj.wave
imgsLoading.beat = obj.beat
}
}

if(imgsLoading.ready){
Expand Down
1 change: 1 addition & 0 deletions plasmoid/contents/ui/Spectrum.qml
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,7 @@ Item{
enable_wave_data:shaderSourceReader.enable_iChannel0
enable_spectrum_data:shaderSourceReader.enable_iChannel1
queue:MessageQueue{
only_spectrum:shaderSourceReader.enable_iChannel1 && !shaderSourceReader.enable_iChannel0
onImgsReadyChanged:{

audioAvailable=imgsReady.audioAvailable
Expand Down
2 changes: 1 addition & 1 deletion plasmoid/contents/ui/config/ConfigGeneral.qml
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ Kirigami.FormLayout {
Layout.fillWidth: true

QQC2.Label {
text: "0.4.2"
text: "0.4.3"
}
}

Expand Down
2 changes: 1 addition & 1 deletion plasmoid/metadata.desktop
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ X-KDE-ServiceTypes=Plasma/Applet
X-KDE-PluginInfo-Author=rbn42
X-KDE-PluginInfo-Email=
X-KDE-PluginInfo-Name=panon
X-KDE-PluginInfo-Version=0.4.2
X-KDE-PluginInfo-Version=0.4.3
X-KDE-PluginInfo-Website=github.com/rbn42/panon
X-KDE-PluginInfo-Category=Multimedia
X-KDE-PluginInfo-Depends=
Expand Down

0 comments on commit c08aa84

Please sign in to comment.