# Path: hearinglosssimulator/gui/myqt.py
# QT = ModuleProxy(['', 'Q', 'Qt'], [QtCore.Qt, QtCore, QtGui, QtWidgets])
# 
# Path: hearinglosssimulator/gui/gpuselection.py
# class GpuDeviceSelection(QT.QWidget):
#     def __init__(self, parent = None):
#         QT.QWidget.__init__(self, parent)
#         mainlayout  =QT.QVBoxLayout()
#         self.setLayout(mainlayout)
# 
#         mainlayout.addWidget(QT.QLabel(u'OpenCL Platform'))
#         self.combo_platform = QT.QComboBox()
#         mainlayout.addWidget(self.combo_platform)
#         
#         mainlayout.addWidget(QT.QLabel(u'OpenCL Device'))
#         self.combo_dev = QT.QComboBox()
#         mainlayout.addWidget(self.combo_dev)
#         
#         mainlayout.addStretch()
#         
#         self.resfresh_platform_list()
#         self.combo_platform.currentIndexChanged.connect(self.resfresh_device_list)
#         
#         if len(pyopencl.get_platforms())>0:
#             self.resfresh_device_list(0)
#     
#     def set_configuration(self, platform_index = 0, device_index = 0):
#         self.combo_platform.currentIndexChanged.disconnect(self.resfresh_device_list)
#         try: 
#             self.combo_platform.setCurrentIndex(platform_index)
#         except: 
#             pass
#         try:
#             self.resfresh_device_list(platform_index)
#         except:
#             pass
#         try:
#             self.combo_dev.setCurrentIndex(device_index)
#         except: 
#             pass
#         self.combo_platform.currentIndexChanged.connect(self.resfresh_device_list)
#     
#     def get_configuration(self):
#         config = {'platform_index': int(self.combo_platform.currentIndex()),
#                         'device_index':int(self.combo_dev.currentIndex()),
#                         }
#         return config
#     
#     def resfresh_platform_list(self):
#         self.combo_platform.clear()
#         for i, platform in enumerate(pyopencl.get_platforms()):
#             self.combo_platform.addItem(u'{}: {}'.format(i, platform.name))
#         
#     def resfresh_device_list(self, platform_index):
#         self.combo_dev.clear()
#         platform = pyopencl.get_platforms()[platform_index]
#         
#         for i, dev in enumerate(platform.get_devices()):
#             self.combo_dev.addItem(u'{}: {}'.format(i, dev.name))


import hearinglosssimulator as hls
import pyqtgraph as pg
import numpy as np
    import pyqtgraph as pg
from hearinglosssimulator.gui.myqt import QT
from hearinglosssimulator.gui.gpuselection import GpuDeviceSelection
        in_buffer = hls.moving_erb_noise(length, sample_rate=sample_rate)
        in_buffer = np.tile(in_buffer[:, None],(1, nb_channel))

        loss_params = {  'left' : {'freqs' :  [125., 250., 500., 1000., 2000., 4000., 8000.],
                                                    'compression_degree': [0., 0., 0., 0., 0., 0., 0.],
                                                    'passive_loss_db' : [0., 0., 0., 0., 0., 0., 0.],
                                                },
                                    'right' : {'freqs' :  [125., 250., 500., 1000., 2000., 4000., 8000.],
                                                    'compression_degree': [0., 0., 0., 0., 0., 0., 0.],
                                                    'passive_loss_db' : [0., 0., 0., 0., 0., 0., 0.],
                                                }
                                }
        processing_conf = dict(nb_freq_band=32, level_step=1, loss_params=loss_params, 
                    low_freq = 100., high_freq = sample_rate*0.45, 
                    debug_mode=False, chunksize=chunksize, backward_chunksize=backward_chunksize)
        #~ node, online_arrs = hls.run_one_node_offline(hls.MainProcessing, in_buffer, chunksize, 
                        #~ sample_rate, node_conf=node_conf, buffersize_margin=backward_chunksize)


        for _class in [hls.InvCGC, hls.InvComp]:
        #~ for _class in [hls.InvComp, hls.InvComp2,]:
        #~ for _class in [hls.InvComp,]:
        #~ for _class in [hls.InvComp2,]:
            print()
            print(_class.__name__, sample_rate, chunksize, backward_chunksize, nb_channel, processing_conf['nb_freq_band'])
            processing = _class(nb_channel=nb_channel, sample_rate=sample_rate,  apply_configuration_at_init=False, **processing_conf)
            processing.create_opencl_context(gpu_platform_index=gpu_platform_index, gpu_device_index=gpu_device_index)
            print(processing.ctx)
            processing.initialize(gpu_platform_index, gpu_device_index)
            online_arrs = hls.run_instance_offline(processing, in_buffer, chunksize, sample_rate,

# Path: hearinglosssimulator/gui/myqt.py
# QT = ModuleProxy(['', 'Q', 'Qt'], [QtCore.Qt, QtCore, QtGui, QtWidgets])
# 
# Path: hearinglosssimulator/gui/gpuselection.py
# class GpuDeviceSelection(QT.QWidget):
#     def __init__(self, parent = None):
#         QT.QWidget.__init__(self, parent)
#         mainlayout  =QT.QVBoxLayout()
#         self.setLayout(mainlayout)
# 
#         mainlayout.addWidget(QT.QLabel(u'OpenCL Platform'))
#         self.combo_platform = QT.QComboBox()
#         mainlayout.addWidget(self.combo_platform)
#         
#         mainlayout.addWidget(QT.QLabel(u'OpenCL Device'))
#         self.combo_dev = QT.QComboBox()
#         mainlayout.addWidget(self.combo_dev)
#         
#         mainlayout.addStretch()
#         
#         self.resfresh_platform_list()
#         self.combo_platform.currentIndexChanged.connect(self.resfresh_device_list)
#         
#         if len(pyopencl.get_platforms())>0:
#             self.resfresh_device_list(0)
#     
#     def set_configuration(self, platform_index = 0, device_index = 0):
#         self.combo_platform.currentIndexChanged.disconnect(self.resfresh_device_list)
#         try: 
#             self.combo_platform.setCurrentIndex(platform_index)
#         except: 
#             pass
#         try:
#             self.resfresh_device_list(platform_index)
#         except:
#             pass
#         try:
#             self.combo_dev.setCurrentIndex(device_index)
#         except: 
#             pass
#         self.combo_platform.currentIndexChanged.connect(self.resfresh_device_list)
#     
#     def get_configuration(self):
#         config = {'platform_index': int(self.combo_platform.currentIndex()),
#                         'device_index':int(self.combo_dev.currentIndex()),
#                         }
#         return config
#     
#     def resfresh_platform_list(self):
#         self.combo_platform.clear()
#         for i, platform in enumerate(pyopencl.get_platforms()):
#             self.combo_platform.addItem(u'{}: {}'.format(i, platform.name))
#         
#     def resfresh_device_list(self, platform_index):
#         self.combo_dev.clear()
#         platform = pyopencl.get_platforms()[platform_index]
#         
#         for i, dev in enumerate(platform.get_devices()):
#             self.combo_dev.addItem(u'{}: {}'.format(i, dev.name))


# Path: hearinglosssimulator/gui/window_debug_gpu.py
import hearinglosssimulator as hls
import pyqtgraph as pg
import numpy as np
    import pyqtgraph as pg
from hearinglosssimulator.gui.myqt import QT
from hearinglosssimulator.gui.gpuselection import GpuDeviceSelection

        in_buffer = hls.moving_erb_noise(length, sample_rate=sample_rate)
        in_buffer = np.tile(in_buffer[:, None],(1, nb_channel))

        loss_params = {  'left' : {'freqs' :  [125., 250., 500., 1000., 2000., 4000., 8000.],
                                                    'compression_degree': [0., 0., 0., 0., 0., 0., 0.],
                                                    'passive_loss_db' : [0., 0., 0., 0., 0., 0., 0.],
                                                },
                                    'right' : {'freqs' :  [125., 250., 500., 1000., 2000., 4000., 8000.],
                                                    'compression_degree': [0., 0., 0., 0., 0., 0., 0.],
                                                    'passive_loss_db' : [0., 0., 0., 0., 0., 0., 0.],
                                                }
                                }
        processing_conf = dict(nb_freq_band=32, level_step=1, loss_params=loss_params, 
                    low_freq = 100., high_freq = sample_rate*0.45, 
                    debug_mode=False, chunksize=chunksize, backward_chunksize=backward_chunksize)
        #~ node, online_arrs = hls.run_one_node_offline(hls.MainProcessing, in_buffer, chunksize, 
                        #~ sample_rate, node_conf=node_conf, buffersize_margin=backward_chunksize)


        for _class in [hls.InvCGC, hls.InvComp]:
        #~ for _class in [hls.InvComp, hls.InvComp2,]:
        #~ for _class in [hls.InvComp,]:
        #~ for _class in [hls.InvComp2,]:
            print()
            print(_class.__name__, sample_rate, chunksize, backward_chunksize, nb_channel, processing_conf['nb_freq_band'])
            processing = _class(nb_channel=nb_channel, sample_rate=sample_rate,  apply_configuration_at_init=False, **processing_conf)
            processing.create_opencl_context(gpu_platform_index=gpu_platform_index, gpu_device_index=gpu_device_index)
            print(processing.ctx)
            processing.initialize(gpu_platform_index, gpu_device_index)
            online_arrs = hls.run_instance_offline(processing, in_buffer, chunksize, sample_rate,

                        buffersize_margin=backward_chunksize, time_stats=True)