# Path: friture/store.py
# def GetStore():
#     global __storeInstance
#     if __storeInstance is None:
#         __storeInstance = Store()
#     return __storeInstance
# 
# Path: friture/audiobackend.py
# SAMPLING_RATE = 48000
# 
# Path: friture/scope_data.py
# class Scope_Data(QtCore.QObject):
#     show_legend_changed = QtCore.pyqtSignal(bool) 
#     plot_items_changed = QtCore.pyqtSignal()
# 
#     def __init__(self, parent=None):
#         super().__init__(parent)
# 
#         self._plot_items = []
#         self._horizontal_axis = Axis(self)
#         self._vertical_axis = Axis(self)
#         self._show_legend = True
# 
#     @pyqtProperty(QQmlListProperty, notify=plot_items_changed)
#     def plot_items(self):
#         return QQmlListProperty(Curve, self, self._plot_items)
#     
#     def insert_plot_item(self, index, plot_item):
#         self._plot_items.insert(index, plot_item)
#         self.plot_items_changed.emit()
#     
#     def add_plot_item(self, plot_item):
#         self._plot_items.append(plot_item)
#         plot_item.setParent(self) # take ownership
#         self.plot_items_changed.emit()
# 
#     def remove_plot_item(self, plot_item):
#         self._plot_items.remove(plot_item)
#         self.plot_items_changed.emit()
# 
#     @pyqtProperty(Axis, constant=True)
#     def horizontal_axis(self):
#         return self._horizontal_axis
# 
#     @pyqtProperty(Axis, constant=True)
#     def vertical_axis(self):
#         return self._vertical_axis
#     
#     @pyqtProperty(bool, notify=show_legend_changed)
#     def show_legend(self):
#         return self._show_legend
#     
#     @show_legend.setter
#     def show_legend(self, show_legend):
#         if self._show_legend != show_legend:
#             self._show_legend = show_legend
#             self.show_legend_changed.emit(show_legend)
# 
# Path: friture/curve.py
# class Curve(QtCore.QObject):
#     data_changed = QtCore.pyqtSignal()
#     name_changed = QtCore.pyqtSignal(str)
# 
#     def __init__(self, parent=None):
#         super().__init__(parent)
# 
#         self._name = ""
#         self._x_array = numpy.array([0])
#         self._y_array = numpy.array([0])
# 
#     def setData(self, x_array, y_array):
#         self._x_array = x_array
#         self._y_array = y_array
#         self.data_changed.emit()
#     
#     def x_array(self):
#         return self._x_array
# 
#     def y_array(self):
#         return self._y_array
#     
#     @pyqtProperty(str, notify=name_changed)
#     def name(self):
#         return self._name
#     
#     @name.setter
#     def name(self, name):
#         if self._name != name:
#             self._name = name
#             self.name_changed.emit(name)
# 
# Path: friture/qml_tools.py
# def qml_url(fileName):
#     return QUrl.fromLocalFile(qml_path(fileName))
# 
# def raise_if_error(quickWidget):
#     if quickWidget.status() == QQuickWidget.Error:
#         errors = '\n'.join(map(lambda x: x.toString(), quickWidget.errors()))
#         raise Exception("QML error(s): %s" % (errors))


import logging
from PyQt5 import QtWidgets
from PyQt5.QtQuickWidgets import QQuickWidget
from numpy import log10, where, sign, arange, zeros
from friture.store import GetStore
from friture.audiobackend import SAMPLING_RATE
from friture.scope_data import Scope_Data
from friture.curve import Curve
from friture.qml_tools import qml_url, raise_if_error

        self.logger = logging.getLogger(__name__)

        self.audiobuffer = None

        store = GetStore()
        self._scope_data = Scope_Data(store)
        store._dock_states.append(self._scope_data)
        state_id = len(store._dock_states) - 1

        self._curve = Curve()
        self._curve.name = "Ch1"
        self._scope_data.add_plot_item(self._curve)

        self._curve_2 = Curve()
        self._curve_2.name = "Ch2"

        self._scope_data.vertical_axis.name = "Signal"
        self._scope_data.vertical_axis.setTrackerFormatter(lambda x: "%#.3g" % (x))
        self._scope_data.horizontal_axis.name = "Time (ms)"
        self._scope_data.horizontal_axis.setTrackerFormatter(lambda x: "%#.3g ms" % (x))

        self.setObjectName("Scope_Widget")
        self.gridLayout = QtWidgets.QGridLayout(self)
        self.gridLayout.setObjectName("gridLayout")
        self.gridLayout.setContentsMargins(2, 2, 2, 2)

        self.quickWidget = QQuickWidget(engine, self)
        self.quickWidget.statusChanged.connect(self.on_status_changed)
        self.quickWidget.setResizeMode(QQuickWidget.SizeRootObjectToView)

# Path: friture/store.py
# def GetStore():
#     global __storeInstance
#     if __storeInstance is None:
#         __storeInstance = Store()
#     return __storeInstance
# 
# Path: friture/audiobackend.py
# SAMPLING_RATE = 48000
# 
# Path: friture/scope_data.py
# class Scope_Data(QtCore.QObject):
#     show_legend_changed = QtCore.pyqtSignal(bool) 
#     plot_items_changed = QtCore.pyqtSignal()
# 
#     def __init__(self, parent=None):
#         super().__init__(parent)
# 
#         self._plot_items = []
#         self._horizontal_axis = Axis(self)
#         self._vertical_axis = Axis(self)
#         self._show_legend = True
# 
#     @pyqtProperty(QQmlListProperty, notify=plot_items_changed)
#     def plot_items(self):
#         return QQmlListProperty(Curve, self, self._plot_items)
#     
#     def insert_plot_item(self, index, plot_item):
#         self._plot_items.insert(index, plot_item)
#         self.plot_items_changed.emit()
#     
#     def add_plot_item(self, plot_item):
#         self._plot_items.append(plot_item)
#         plot_item.setParent(self) # take ownership
#         self.plot_items_changed.emit()
# 
#     def remove_plot_item(self, plot_item):
#         self._plot_items.remove(plot_item)
#         self.plot_items_changed.emit()
# 
#     @pyqtProperty(Axis, constant=True)
#     def horizontal_axis(self):
#         return self._horizontal_axis
# 
#     @pyqtProperty(Axis, constant=True)
#     def vertical_axis(self):
#         return self._vertical_axis
#     
#     @pyqtProperty(bool, notify=show_legend_changed)
#     def show_legend(self):
#         return self._show_legend
#     
#     @show_legend.setter
#     def show_legend(self, show_legend):
#         if self._show_legend != show_legend:
#             self._show_legend = show_legend
#             self.show_legend_changed.emit(show_legend)
# 
# Path: friture/curve.py
# class Curve(QtCore.QObject):
#     data_changed = QtCore.pyqtSignal()
#     name_changed = QtCore.pyqtSignal(str)
# 
#     def __init__(self, parent=None):
#         super().__init__(parent)
# 
#         self._name = ""
#         self._x_array = numpy.array([0])
#         self._y_array = numpy.array([0])
# 
#     def setData(self, x_array, y_array):
#         self._x_array = x_array
#         self._y_array = y_array
#         self.data_changed.emit()
#     
#     def x_array(self):
#         return self._x_array
# 
#     def y_array(self):
#         return self._y_array
#     
#     @pyqtProperty(str, notify=name_changed)
#     def name(self):
#         return self._name
#     
#     @name.setter
#     def name(self, name):
#         if self._name != name:
#             self._name = name
#             self.name_changed.emit(name)
# 
# Path: friture/qml_tools.py
# def qml_url(fileName):
#     return QUrl.fromLocalFile(qml_path(fileName))
# 
# def raise_if_error(quickWidget):
#     if quickWidget.status() == QQuickWidget.Error:
#         errors = '\n'.join(map(lambda x: x.toString(), quickWidget.errors()))
#         raise Exception("QML error(s): %s" % (errors))


# Path: friture/scope.py
import logging
from PyQt5 import QtWidgets
from PyQt5.QtQuickWidgets import QQuickWidget
from numpy import log10, where, sign, arange, zeros
from friture.store import GetStore
from friture.audiobackend import SAMPLING_RATE
from friture.scope_data import Scope_Data
from friture.curve import Curve
from friture.qml_tools import qml_url, raise_if_error


        self.logger = logging.getLogger(__name__)

        self.audiobuffer = None

        store = GetStore()
        self._scope_data = Scope_Data(store)
        store._dock_states.append(self._scope_data)
        state_id = len(store._dock_states) - 1

        self._curve = Curve()
        self._curve.name = "Ch1"
        self._scope_data.add_plot_item(self._curve)

        self._curve_2 = Curve()
        self._curve_2.name = "Ch2"

        self._scope_data.vertical_axis.name = "Signal"
        self._scope_data.vertical_axis.setTrackerFormatter(lambda x: "%#.3g" % (x))
        self._scope_data.horizontal_axis.name = "Time (ms)"
        self._scope_data.horizontal_axis.setTrackerFormatter(lambda x: "%#.3g ms" % (x))

        self.setObjectName("Scope_Widget")
        self.gridLayout = QtWidgets.QGridLayout(self)
        self.gridLayout.setObjectName("gridLayout")
        self.gridLayout.setContentsMargins(2, 2, 2, 2)

        self.quickWidget = QQuickWidget(engine, self)
        self.quickWidget.statusChanged.connect(self.on_status_changed)
        self.quickWidget.setResizeMode(QQuickWidget.SizeRootObjectToView)

        self.quickWidget.setSource(qml_url("Scope.qml"))