Hello, apologies for being a newb, and I hope my question makes sense. I am just starting to learn c++ and qt, and I'm working on a simple midi controlled oscillator with gui using the Synthesis Toolkit (mostly by copying and pasting code). I've run into a snag and I was hoping someone could help me.
I have a (working) horizontal slider and the rest of the code is working too in another Qthread. So everything works, the slider displays, the oscillator makes sound and accepts midi messages. The problem is that I want to work the value of the slider into the code, and I don't know how to do that. The applicable parts of the code are gain.h and gain.cpp, which contain the slider code, and also sine.cpp, which I want to somehow make use of gain.h/gain.cpp. Here is the code, which again I copied and pasted from the internet to get a working slider:
#ifndef LCDRANGE_H
#define LCDRANGE_H
#include <QWidget>
{
Q_OBJECT
public:
int value() const;
public slots:
void setValue(int value);
signals:
void valueChanged(int newValue);
private:
};
#endif
#ifndef LCDRANGE_H
#define LCDRANGE_H
#include <QWidget>
class QSlider;
class Gain : public QWidget
{
Q_OBJECT
public:
Gain(QWidget *parent = 0);
int value() const;
public slots:
void setValue(int value);
signals:
void valueChanged(int newValue);
private:
QSlider *slider;
};
#endif
To copy to clipboard, switch view to plain text mode
And here is gain.cpp:
#include <QSlider>
#include <QVBoxLayout>
#include "gain.h"
{
slider
= new QSlider(Qt
::Horizontal);
slider->setRange(1, 100);
slider->setValue(50);
connect(slider, SIGNAL(valueChanged(int)),
this, SIGNAL(valueChanged(int)));
layout->addWidget(slider);
setLayout(layout);
}
int Gain::value() const
{
return slider->value();
}
void Gain::setValue(int value)
{
slider->setValue(value);
}
#include <QSlider>
#include <QVBoxLayout>
#include "gain.h"
Gain::Gain(QWidget *parent)
: QWidget(parent)
{
slider = new QSlider(Qt::Horizontal);
slider->setRange(1, 100);
slider->setValue(50);
connect(slider, SIGNAL(valueChanged(int)),
this, SIGNAL(valueChanged(int)));
QVBoxLayout *layout = new QVBoxLayout;
layout->addWidget(slider);
setLayout(layout);
}
int Gain::value() const
{
return slider->value();
}
void Gain::setValue(int value)
{
slider->setValue(value);
}
To copy to clipboard, switch view to plain text mode
Now how to route it to my other code? I specifically want to take the value of the horizontal slider, convert it to a value between 0 and 1, and multiply the value of my output so that it functions as a volume control for the oscillator. Every attempt I have made so far to add any reference to the horizontal slider in my oscillator code results in the code not compiling, the gui not displaying, the oscillator making no sound, or an error about "must create application before qpaint" something-or-other.
Thanks in advance for your time and help.
Bookmarks