Browse Source

Oscilloscope: Time out when waiting for trigger and show warning sign.

more-nodes
Ben Niemann 3 years ago
parent
commit
cee374c403
  1. 1
      data/icons/CMakeLists.txt
  2. 81
      data/icons/warning.svg
  3. 46
      noisicaa/builtin_nodes/oscilloscope/node_ui.py

1
data/icons/CMakeLists.txt

@ -58,4 +58,5 @@ install_files(
track-type-sample.svg
track-type-score.svg
track-visible.svg
warning.svg
)

81
data/icons/warning.svg

@ -0,0 +1,81 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<svg
xmlns:dc="http://purl.org/dc/elements/1.1/"
xmlns:cc="http://creativecommons.org/ns#"
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
xmlns:svg="http://www.w3.org/2000/svg"
xmlns="http://www.w3.org/2000/svg"
xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd"
xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape"
height="30"
id="svg2"
version="1.1"
viewBox="147 151 60 60"
width="30"
sodipodi:docname="warning.svg"
inkscape:version="0.92.3 (2405546, 2018-03-11)">
<metadata
id="metadata3495">
<rdf:RDF>
<cc:Work
rdf:about="">
<dc:format>image/svg+xml</dc:format>
<dc:type
rdf:resource="http://purl.org/dc/dcmitype/StillImage" />
<dc:title />
</cc:Work>
</rdf:RDF>
</metadata>
<sodipodi:namedview
pagecolor="#ffffff"
bordercolor="#666666"
borderopacity="1"
objecttolerance="10"
gridtolerance="10"
guidetolerance="10"
inkscape:pageopacity="0"
inkscape:pageshadow="2"
inkscape:window-width="2560"
inkscape:window-height="1373"
id="namedview3493"
showgrid="false"
inkscape:zoom="16.000001"
inkscape:cx="-6.3115405"
inkscape:cy="25.123386"
inkscape:window-x="0"
inkscape:window-y="0"
inkscape:window-maximized="1"
inkscape:current-layer="layer2" />
<defs
id="defs10" />
<g
id="layer2"
style="display:inline"
transform="translate(0,-637.6694)"
inkscape:groupmode="layer"
inkscape:label="Symbol">
<g
id="layer1"
transform="matrix(0.05920137,0,0,-0.05920137,128.73324,826.15201)">
<path
id="path11039"
style="fill:#ee1c23;fill-rule:nonzero;stroke:none"
d="m 840.83969,544.41993 c -14.03378,24.29258 -37.01519,24.29258 -51.06339,0 L 321.28695,-265.67834 c -14.03379,-24.29257 -2.55029,-44.16176 25.5317,-44.16176 l 936.94985,-0.0144 c 28.0964,0 39.5799,19.86919 25.5317,44.16177 z"
inkscape:connector-curvature="0" />
<path
id="path10308"
style="fill:#ffffff;fill-rule:nonzero;stroke:none"
d="m 1154.4675,-205.95549 -678.31899,0.0144 339.15949,586.4942 339.1595,-586.50861"
inkscape:connector-curvature="0" />
</g>
<g
aria-label="!"
style="font-style:normal;font-variant:normal;font-weight:normal;font-stretch:normal;font-size:33.58262253px;line-height:125%;font-family:'Arial Black';-inkscape-font-specification:'Arial Black, Normal';font-variant-ligatures:normal;font-variant-caps:normal;font-variant-numeric:normal;font-feature-settings:normal;text-align:start;letter-spacing:0px;word-spacing:0px;writing-mode:lr-tb;text-anchor:start;fill:#000000;fill-opacity:1;stroke:none;stroke-width:3.3582623pt;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1"
id="text955">
<path
d="m 173.43348,812.48346 h 7.13303 v 5.47685 l -1.37741,11.0029 h -4.411 l -1.34462,-11.0029 z m 0.24597,18.15233 h 6.65749 v 5.88679 h -6.65749 z"
style="font-style:normal;font-variant:normal;font-weight:normal;font-stretch:normal;font-size:33.58262253px;font-family:'Arial Black';-inkscape-font-specification:'Arial Black, Normal';font-variant-ligatures:normal;font-variant-caps:normal;font-variant-numeric:normal;font-feature-settings:normal;text-align:start;writing-mode:lr-tb;text-anchor:start;stroke-width:3.3582623pt"
id="path825" />
</g>
</g>
</svg>

After

Width:  |  Height:  |  Size: 3.5 KiB

46
noisicaa/builtin_nodes/oscilloscope/node_ui.py

@ -22,6 +22,7 @@
import enum
import logging
import os.path
import time
from typing import Any, Dict, List, Tuple, Iterable
@ -30,6 +31,7 @@ from PyQt5 import QtCore
from PyQt5 import QtGui
from PyQt5 import QtWidgets
from noisicaa import constants
from noisicaa import core
from noisicaa import music
from noisicaa.ui import slots
@ -69,6 +71,8 @@ class Oscilloscope(slots.SlotContainer, QtWidgets.QWidget):
self.__remainder = 0.0
self.__prev_sample = 0.0
self.__hold_begin = 0.0
self.__trigger_begin = 0.0
self.__trigger_found = False
self.__timePerPixel = 1.0
self.__timePerSample = 1.0 / 44100
@ -83,6 +87,15 @@ class Oscilloscope(slots.SlotContainer, QtWidgets.QWidget):
self.__label_font = QtGui.QFont(self.font())
self.__label_font.setPointSizeF(0.8 * self.__label_font.pointSizeF())
self.__label_font_metrics = QtGui.QFontMetrics(self.__label_font)
self.__warning_pen = QtGui.QPen(QtGui.QColor(255, 255, 255))
self.__warning_font = QtGui.QFont(self.font())
self.__warning_font.setPointSizeF(0.9 * self.__warning_font.pointSizeF())
self.__warning_font.setBold(True)
self.__warning_font_metrics = QtGui.QFontMetrics(self.__warning_font)
self.__warning_pixmap = QtGui.QIcon(QtGui.QIcon.fromTheme(
os.path.join(constants.DATA_DIR, 'icons', 'warning.svg'))).pixmap(
4 + self.__warning_font_metrics.capHeight(),
4 + self.__warning_font_metrics.capHeight())
self.__show_minor_grid = False
self.__show_major_grid = False
@ -113,6 +126,8 @@ class Oscilloscope(slots.SlotContainer, QtWidgets.QWidget):
self.__remainder = 0.0
elif state == State.HOLD:
self.__hold_begin = time.time()
elif state == State.WAIT_FOR_TRIGGER:
self.__trigger_begin = time.time()
self.__state = state
@ -171,11 +186,15 @@ class Oscilloscope(slots.SlotContainer, QtWidgets.QWidget):
for value in values:
if self.__state == State.HOLD and not self.paused():
if time.time() - self.__hold_begin > self.absHoldTime():
self.__state = State.WAIT_FOR_TRIGGER
self.__setState(State.WAIT_FOR_TRIGGER)
if self.__state == State.WAIT_FOR_TRIGGER:
if self.__prev_sample < trigger_value and value >= trigger_value:
self.__trigger_found = True
self.__setState(State.RECORDING)
elif time.time() - self.__trigger_begin > 10 * self.absTimeScale():
self.__setState(State.RECORDING)
self.__trigger_found = False
self.__prev_sample = value
@ -358,14 +377,18 @@ class Oscilloscope(slots.SlotContainer, QtWidgets.QWidget):
continue
painter.fillRect(
self.__plot_rect.left() - 3, self.__plot_rect.top() + tick_pos, 3, 1, self.__border_color)
self.__plot_rect.left() - 3, self.__plot_rect.top() + tick_pos,
3, 1,
self.__border_color)
y1 = '%g' % (tick * self.absYScale())
y1r = self.__label_font_metrics.boundingRect(y1)
painter.drawText(
self.__plot_rect.left() - y1r.width() - 4,
max(y_min, min(y_max, self.__plot_rect.top() + tick_pos + self.__label_font_metrics.capHeight() // 2)),
y1)
label_pos = (
self.__plot_rect.top()
+ tick_pos
+ self.__label_font_metrics.capHeight() // 2)
label_pos = max(y_min, min(y_max, label_pos))
painter.drawText(self.__plot_rect.left() - y1r.width() - 4, label_pos, y1)
finally:
painter.end()
@ -397,6 +420,17 @@ class Oscilloscope(slots.SlotContainer, QtWidgets.QWidget):
painter.setPen(self.__plot_pen)
painter.drawPolyline(path)
if not self.__trigger_found and h > 5 * self.__warning_font_metrics.capHeight():
x = (w - self.__warning_font_metrics.boundingRect("No Trigger").width()
- self.__warning_pixmap.width() - 8)
if x > 0:
painter.drawPixmap(x, 3, self.__warning_pixmap)
x += self.__warning_pixmap.width() + 3
painter.setPen(self.__warning_pen)
painter.setFont(self.__warning_font)
painter.drawText(x, 5 + self.__warning_font_metrics.capHeight(), "No Trigger")
finally:
painter.end()

Loading…
Cancel
Save