void XAirAuxBlock::retrieveStateFromConsole() {
    // get fader position:
    QString faderPosMessage = "/rtn/aux/mix";
    if (m_bus == 0) {
        faderPosMessage.append("/fader");
    } else {
        faderPosMessage.append("/%1/level");
        faderPosMessage = faderPosMessage.arg(m_bus, 2, 10, QChar('0'));
    }
    m_controller->audioConsole()->sendMessage(faderPosMessage);

    // get label:
    QString message = "/rtn/aux/config/name";
    m_controller->audioConsole()->sendMessage(message);

    // get pan:
    message = "/rtn/aux/mix/pan";
    m_controller->audioConsole()->sendMessage(message);

    // get on state:
    message = "/rtn/aux/mix/on";
    m_controller->audioConsole()->sendMessage(message);

    updateSubscription();
}
void AdBlockSubscription::loadSubscription(const QStringList &disabledRules)
{
    QFile file(m_filePath);

    if (!file.exists()) {
        QTimer::singleShot(0, this, SLOT(updateSubscription()));
        return;
    }

    if (!file.open(QFile::ReadOnly)) {
        qWarning() << "AdBlockSubscription::" << __FUNCTION__ << "Unable to open adblock file for reading" << m_filePath;
        QTimer::singleShot(0, this, SLOT(updateSubscription()));
        return;
    }

    QTextStream textStream(&file);
    textStream.setCodec("UTF-8");
    // Header is on 3rd line
    textStream.readLine(1024);
    textStream.readLine(1024);
    QString header = textStream.readLine(1024);

    if (!header.startsWith(QLatin1String("[Adblock")) || m_title.isEmpty()) {
        qWarning() << "AdBlockSubscription::" << __FUNCTION__ << "invalid format of adblock file" << m_filePath;
        QTimer::singleShot(0, this, SLOT(updateSubscription()));
        return;
    }

    m_rules.clear();

    while (!textStream.atEnd()) {
        AdBlockRule* rule = new AdBlockRule(textStream.readLine(), this);

        if (disabledRules.contains(rule->filter())) {
            rule->setEnabled(false);
        }

        m_rules.append(rule);
    }

    populateCache();

    // Initial update
    if (m_rules.isEmpty() && !m_updated) {
        QTimer::singleShot(0, this, SLOT(updateSubscription()));
    }
}
XAirAuxBlock::XAirAuxBlock(MainController* controller, QString uid)
    : OneInputBlock(controller, uid)
    , m_panNode(nullptr)
    , m_onNode(nullptr)
    , m_channelNumber(this, "channelNumber", 1, 1, 32)
    , m_bus(this, "bus", 0, 0, 16)
    , m_faderPos(this, "faderPos", 0.0, 0, 1)
    , m_pan(this, "pan", 0.5)
    , m_boost(this, "boost", true)
    , m_on(this, "on", true)
    , m_pauseValueTransmission(false)
{
    m_heightIsResizable = true;

    m_panNode = createInputNode("panNode");
    m_onNode = createInputNode("onNode");

    m_onNode->enableImpulseDetection();
    connect(m_onNode, &NodeBase::impulseBegin, [this](){ m_on = true; });
    connect(m_onNode, &NodeBase::impulseEnd, [this](){ m_on = false; });

    m_subscribeRefreshTimer.setInterval(10000);  // 10s
    connect(&m_subscribeRefreshTimer, SIGNAL(timeout()), this, SLOT(updateSubscription()));
    m_subscribeRefreshTimer.start();

    connect(&m_faderPos, SIGNAL(valueChanged()), this, SIGNAL(decibelChanged()));

    connect(&m_label, SIGNAL(valueChanged()), this, SLOT(sendName()));
    connect(&m_faderPos, SIGNAL(valueChanged()), this, SLOT(sendFaderPos()));
    connect(&m_pan, SIGNAL(valueChanged()), this, SLOT(sendPan()));
    connect(&m_on, SIGNAL(valueChanged()), this, SLOT(sendOn()));

    connect(&m_channelNumber, SIGNAL(valueChanged()), this, SLOT(retrieveStateFromConsole()));
    connect(&m_bus, SIGNAL(valueChanged()), this, SLOT(retrieveStateFromConsole()));

    connect(m_inputNode, &NodeBase::dataChanged, [this](){ m_faderPos.setValue(m_inputNode->getValue()); });
    connect(m_panNode, &NodeBase::dataChanged, [this](){ m_pan.setValue(m_panNode->getValue()); });

    connect(controller->audioConsole(), SIGNAL(messageReceived(OSCMessage)), this, SLOT(onMessageReceived(OSCMessage)));

}