@@ -212,7 +212,7 @@ void carla_register_all_plugins() | |||
void carla_register_native_plugin_3BandEQ(); | |||
void carla_register_native_plugin_3BandSplitter(); | |||
void carla_register_native_plugin_PingPongPan(); | |||
//void carla_register_native_plugin_Notes(); | |||
void carla_register_native_plugin_Notes(); | |||
#ifdef WANT_AUDIOFILE | |||
// AudioFile | |||
@@ -8,7 +8,7 @@ include ../Makefile.mk | |||
# -------------------------------------------------------------- | |||
BUILD_CXX_FLAGS += $(shell pkg-config --cflags QtCore QtGui) | |||
BUILD_CXX_FLAGS += $(shell pkg-config --cflags QtCore QtGui) -I../../widgets | |||
LINK_FLAGS += $(shell pkg-config --libs QtCore QtGui) | |||
ifeq ($(HAVE_AF_DEPS),true) | |||
@@ -38,8 +38,8 @@ OBJS = \ | |||
OBJS += \ | |||
distrho-3bandeq.cpp.o \ | |||
distrho-3bandsplitter.cpp.o \ | |||
distrho-pingpongpan.cpp.o | |||
# distrho-notes.cpp.o | |||
distrho-pingpongpan.cpp.o \ | |||
distrho-notes.cpp.o | |||
# AudioFile | |||
ifeq ($(HAVE_AF_DEPS),true) | |||
@@ -30,7 +30,7 @@ START_NAMESPACE_DISTRHO | |||
static const PluginDescriptor notesDesc = { | |||
/* category */ ::PLUGIN_CATEGORY_UTILITY, | |||
/* hints */ static_cast<PluginHints>(::PLUGIN_IS_RTSAFE | ::PLUGIN_HAS_GUI | ::PLUGIN_USES_SINGLE_THREAD), | |||
/* hints */ static_cast<PluginHints>(::PLUGIN_IS_RTSAFE|::PLUGIN_HAS_GUI|::PLUGIN_USES_SINGLE_THREAD), | |||
/* audioIns */ DISTRHO_PLUGIN_NUM_INPUTS, | |||
/* audioOuts */ DISTRHO_PLUGIN_NUM_OUTPUTS, | |||
/* midiIns */ 0, | |||
@@ -17,9 +17,6 @@ | |||
#include "DistrhoUINotes.hpp" | |||
#include "notes/ParamProgressBar.cpp" | |||
#include "moc_ParamProgressBar.cpp" | |||
#include <QtGui/QResizeEvent> | |||
START_NAMESPACE_DISTRHO | |||
@@ -19,7 +19,7 @@ | |||
#define __DISTRHO_UI_NOTES_HPP__ | |||
#include "DistrhoUIQt4.hpp" | |||
#include "ParamProgressBar.hpp" | |||
#include "paramspinbox.hpp" | |||
#include <QtGui/QGridLayout> | |||
#include <QtGui/QLabel> | |||
@@ -1,118 +0,0 @@ | |||
/* | |||
* Parameter Progress-Bar, a custom Qt4 widget | |||
* Copyright (C) 2012 Filipe Coelho <falktx@falktx.com> | |||
* | |||
* This program is free software; you can redistribute it and/or modify | |||
* it under the terms of the GNU General Public License as published by | |||
* the Free Software Foundation; either version 2 of the License, or | |||
* any later version. | |||
* | |||
* This program is distributed in the hope that it will be useful, | |||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | |||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |||
* GNU General Public License for more details. | |||
* | |||
* For a full copy of the GNU General Public License see the COPYING file | |||
*/ | |||
#include "ParamProgressBar.hpp" | |||
#include <QtGui/QMouseEvent> | |||
ParamProgressBar::ParamProgressBar(QWidget* parent) | |||
: QProgressBar(parent) | |||
{ | |||
m_leftClickDown = false; | |||
m_minimum = 0.0f; | |||
m_maximum = 1.0f; | |||
m_rvalue = 0.0f; | |||
m_textCall = nullptr; | |||
setMinimum(0); | |||
setMaximum(1000); | |||
setValue(0); | |||
setFormat("(none)"); | |||
} | |||
void ParamProgressBar::set_minimum(float value) | |||
{ | |||
m_minimum = value; | |||
} | |||
void ParamProgressBar::set_maximum(float value) | |||
{ | |||
m_maximum = value; | |||
} | |||
void ParamProgressBar::set_value(float value) | |||
{ | |||
m_rvalue = value; | |||
float vper = (value - m_minimum) / (m_maximum - m_minimum); | |||
setValue(vper * 1000); | |||
} | |||
void ParamProgressBar::set_label(QString label) | |||
{ | |||
m_label = label; | |||
if (m_label == "(coef)") | |||
{ | |||
m_label = ""; | |||
m_preLabel = "*"; | |||
} | |||
} | |||
void ParamProgressBar::set_text_call(TextCallback* textCall) | |||
{ | |||
m_textCall = textCall; | |||
} | |||
void ParamProgressBar::handleMouseEventPos(const QPoint& pos) | |||
{ | |||
float xper = float(pos.x()) / width(); | |||
float value = xper * (m_maximum - m_minimum) + m_minimum; | |||
if (value < m_minimum) | |||
value = m_minimum; | |||
else if (value > m_maximum) | |||
value = m_maximum; | |||
emit valueChangedFromBar(value); | |||
} | |||
void ParamProgressBar::mousePressEvent(QMouseEvent* event) | |||
{ | |||
if (event->button() == Qt::LeftButton) | |||
{ | |||
handleMouseEventPos(event->pos()); | |||
m_leftClickDown = true; | |||
} | |||
else | |||
m_leftClickDown = false; | |||
QProgressBar::mousePressEvent(event); | |||
} | |||
void ParamProgressBar::mouseMoveEvent(QMouseEvent* event) | |||
{ | |||
if (m_leftClickDown) | |||
handleMouseEventPos(event->pos()); | |||
QProgressBar::mouseMoveEvent(event); | |||
} | |||
void ParamProgressBar::mouseReleaseEvent(QMouseEvent* event) | |||
{ | |||
m_leftClickDown = false; | |||
QProgressBar::mouseReleaseEvent(event); | |||
} | |||
void ParamProgressBar::paintEvent(QPaintEvent* event) | |||
{ | |||
if (m_textCall) | |||
setFormat(QString("%1 %2 %3").arg(m_preLabel).arg(m_textCall->textCallBack()).arg(m_label)); | |||
else | |||
setFormat(QString("%1 %2 %3").arg(m_preLabel).arg(m_rvalue).arg(m_label)); | |||
QProgressBar::paintEvent(event); | |||
} |
@@ -1,64 +0,0 @@ | |||
/* | |||
* Parameter Progress-Bar, a custom Qt4 widget | |||
* Copyright (C) 2012 Filipe Coelho <falktx@falktx.com> | |||
* | |||
* This program is free software; you can redistribute it and/or modify | |||
* it under the terms of the GNU General Public License as published by | |||
* the Free Software Foundation; either version 2 of the License, or | |||
* any later version. | |||
* | |||
* This program is distributed in the hope that it will be useful, | |||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | |||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |||
* GNU General Public License for more details. | |||
* | |||
* For a full copy of the GNU General Public License see the COPYING file | |||
*/ | |||
#ifndef PARAMPROGRESSBAR_H | |||
#define PARAMPROGRESSBAR_H | |||
#include <QtGui/QProgressBar> | |||
class TextCallback | |||
{ | |||
public: | |||
virtual ~TextCallback(); | |||
virtual const char* textCallBack() = 0; | |||
}; | |||
class ParamProgressBar : public QProgressBar | |||
{ | |||
Q_OBJECT | |||
public: | |||
ParamProgressBar(QWidget* parent); | |||
void set_minimum(float value); | |||
void set_maximum(float value); | |||
void set_value(float value); | |||
void set_label(QString label); | |||
void set_text_call(TextCallback* textCall); | |||
signals: | |||
void valueChangedFromBar(float value); | |||
protected: | |||
void handleMouseEventPos(const QPoint& pos); | |||
void mousePressEvent(QMouseEvent* event); | |||
void mouseMoveEvent(QMouseEvent* event); | |||
void mouseReleaseEvent(QMouseEvent* event); | |||
void paintEvent(QPaintEvent* event); | |||
private: | |||
bool m_leftClickDown; | |||
float m_minimum; | |||
float m_maximum; | |||
float m_rvalue; | |||
QString m_label; | |||
QString m_preLabel; | |||
TextCallback* m_textCall; | |||
}; | |||
#endif // #define PARAMPROGRESSBAR_H |
@@ -9,7 +9,7 @@ include ../Makefile.mk | |||
# -------------------------------------------------------------- | |||
# Common | |||
LINK_FLAGS += $(shell pkg-config --libs liblo QtCore QtGui QtXml) | |||
LINK_FLAGS += $(shell pkg-config --libs gl liblo QtCore QtGui QtXml) | |||
# -------------------------------------------------------------- | |||
# Engine | |||
@@ -27,9 +27,6 @@ endif | |||
# -------------------------------------------------------------- | |||
# Plugin | |||
ifeq ($(HAVE_SUIL),true) | |||
LINK_FLAGS += $(shell pkg-config --libs suil-0) | |||
endif | |||
ifeq ($(HAVE_FLUIDSYNTH),true) | |||
LINK_FLAGS += $(shell pkg-config --libs fluidsynth) | |||
endif | |||
@@ -40,12 +37,9 @@ endif | |||
# -------------------------------------------------------------- | |||
# Native | |||
LINK_FLAGS += $(shell pkg-config --libs gl) | |||
ifeq ($(HAVE_AF_DEPS),true) | |||
LINK_FLAGS += $(shell pkg-config --libs libavcodec libavformat sndfile) | |||
endif | |||
ifeq ($(HAVE_ZYN_DEPS),true) | |||
LINK_FLAGS += $(shell pkg-config --libs fftw3 mxml) | |||
endif | |||
@@ -58,6 +52,7 @@ LIBS += ../libcarla_native.a | |||
LIBS += ../../libs/dgl.a | |||
LIBS += ../../libs/lilv.a | |||
LIBS += ../../libs/rtmempool.a | |||
LIBS += ../../libs/widgets.a | |||
OBJS = \ | |||
CarlaStandalone.cpp.o | |||
@@ -32,6 +32,11 @@ rtmempool.%.a: | |||
# -------------------------------------------------------------- | |||
widgets.a: | |||
$(MAKE) -C ../widgets | |||
# -------------------------------------------------------------- | |||
jackbridge-win32.dll: | |||
$(MAKE) -C jackbridge win32 | |||
@@ -51,3 +56,4 @@ clean: | |||
$(MAKE) clean -C distrho/dgl | |||
$(MAKE) clean -C lilv | |||
$(MAKE) clean -C rtmempool | |||
$(MAKE) clean -C ../widgets |
@@ -16,8 +16,9 @@ | |||
*/ | |||
// still need qt classes check | |||
#include "plugin/CarlaPluginInternal.hpp" | |||
//#include "plugin/CarlaPluginInternal.hpp" | |||
//#include "plugin/DssiPlugin.cpp" | |||
#include "../widgets/digitalpeakmeter.cpp" | |||
#if 0 | |||
#include "CarlaDefines.hpp" | |||
@@ -0,0 +1,49 @@ | |||
#!/usr/bin/make -f | |||
# Makefile for widgets # | |||
# -------------------- # | |||
# Created by falkTX | |||
# | |||
include ../Makefile.mk | |||
# -------------------------------------------------------------- | |||
BUILD_CXX_FLAGS += -fvisibility=hidden -fPIC -I. | |||
BUILD_CXX_FLAGS += $(shell pkg-config --cflags QtCore) | |||
LINK_FLAGS += $(shell pkg-config --libs QtCore) | |||
FILES = \ | |||
moc_pixmapkeyboard.cpp | |||
OBJS = \ | |||
digitalpeakmeter.cpp.o \ | |||
ledbutton.cpp.o \ | |||
paramspinbox.cpp.o \ | |||
pixmapdial.cpp.o \ | |||
pixmapkeyboard.cpp.o \ | |||
moc_pixmapkeyboard.cpp.o | |||
TARGET = ../libs/widgets.a | |||
# -------------------------------------------------------------- | |||
all: $(TARGET) | |||
clean: | |||
rm -f $(FILES) $(OBJS) $(TARGET) | |||
debug: | |||
$(MAKE) DEBUG=true | |||
# -------------------------------------------------------------- | |||
$(TARGET): $(FILES) $(OBJS) | |||
$(AR) rs $@ $(OBJS) | |||
# -------------------------------------------------------------- | |||
%.cpp.o: %.cpp | |||
$(CXX) $< $(BUILD_CXX_FLAGS) -c -o $@ | |||
moc_%.cpp: %.hpp | |||
$(MOC) $< -o $@ |
@@ -18,31 +18,46 @@ | |||
#include "digitalpeakmeter.hpp" | |||
#include <QtGui/QPainter> | |||
#include <QtGui/QPaintEvent> | |||
DigitalPeakMeter::DigitalPeakMeter(QWidget* parent) | |||
: QWidget(parent), | |||
m_paintTimer(this) | |||
fChannels(0), | |||
fSmoothMultiplier(1), | |||
fWidth(0), | |||
fHeight(0), | |||
fSizeMeter(0), | |||
fOrientation(VERTICAL), | |||
fColorBackground("#111111"), | |||
fGradientMeter(0, 0, 1, 1), | |||
fColorBase(93, 231, 61), | |||
fColorBaseAlt(15, 110, 15, 100), | |||
fChannelsData(nullptr), | |||
fLastValueData(nullptr), | |||
fPaintTimer(this) | |||
{ | |||
m_channels = 0; | |||
m_orientation = VERTICAL; | |||
m_smoothMultiplier = 1; | |||
m_colorBackground = QColor("#111111"); | |||
m_gradientMeter = QLinearGradient(0, 0, 1, 1); | |||
setChannels(0); | |||
setColor(GREEN); | |||
m_paintTimer.setInterval(60); | |||
connect(&m_paintTimer, SIGNAL(timeout()), this, SLOT(update())); | |||
m_paintTimer.start(); | |||
fPaintTimer.setInterval(60); | |||
connect(&fPaintTimer, SIGNAL(timeout()), this, SLOT(update())); | |||
fPaintTimer.start(); | |||
} | |||
DigitalPeakMeter::~DigitalPeakMeter() | |||
{ | |||
if (fChannelsData != nullptr) | |||
delete[] fChannelsData; | |||
if (fLastValueData != nullptr) | |||
delete[] fLastValueData; | |||
} | |||
void DigitalPeakMeter::displayMeter(int meter, float level) | |||
{ | |||
Q_ASSERT(meter > 0 && meter <= m_channels); | |||
Q_ASSERT(fChannelsData != nullptr); | |||
Q_ASSERT(meter > 0 && meter <= fChannels); | |||
if (meter <= 0 || meter > m_channels) | |||
if (meter <= 0 || meter > fChannels || fChannelsData == nullptr) | |||
return qCritical("DigitalPeakMeter::displayMeter(%i, %f) - invalid meter number", meter, level); | |||
if (level < 0.0f) | |||
@@ -50,7 +65,7 @@ void DigitalPeakMeter::displayMeter(int meter, float level) | |||
else if (level > 1.0f) | |||
level = 1.0f; | |||
m_channelsData[meter-1] = level; | |||
fChannelsData[meter-1] = level; | |||
} | |||
void DigitalPeakMeter::setChannels(int channels) | |||
@@ -60,14 +75,28 @@ void DigitalPeakMeter::setChannels(int channels) | |||
if (channels < 0) | |||
return qCritical("DigitalPeakMeter::setChannels(%i) - 'channels' must be a positive integer", channels); | |||
m_channels = channels; | |||
m_channelsData.clear(); | |||
m_lastValueData.clear(); | |||
fChannels = channels; | |||
for (int i=0; i < channels; i++) | |||
if (fChannelsData != nullptr) | |||
delete[] fChannelsData; | |||
if (fLastValueData != nullptr) | |||
delete[] fLastValueData; | |||
if (channels > 0) | |||
{ | |||
m_channelsData.append(0.0f); | |||
m_lastValueData.append(0.0f); | |||
fChannelsData = new float[channels]; | |||
fLastValueData = new float[channels]; | |||
for (int i=0; i < channels; i++) | |||
{ | |||
fChannelsData[i] = 0.0f; | |||
fLastValueData[i] = 0.0f; | |||
} | |||
} | |||
else | |||
{ | |||
fChannelsData = nullptr; | |||
fLastValueData = nullptr; | |||
} | |||
} | |||
@@ -75,41 +104,41 @@ void DigitalPeakMeter::setColor(Color color) | |||
{ | |||
if (color == GREEN) | |||
{ | |||
m_colorBase = QColor(93, 231, 61); | |||
m_colorBaseT = QColor(15, 110, 15, 100); | |||
fColorBase = QColor(93, 231, 61); | |||
fColorBaseAlt = QColor(15, 110, 15, 100); | |||
} | |||
else if (color == BLUE) | |||
{ | |||
m_colorBase = QColor(82, 238, 248); | |||
m_colorBaseT = QColor(15, 15, 110, 100); | |||
fColorBase = QColor(82, 238, 248); | |||
fColorBaseAlt = QColor(15, 15, 110, 100); | |||
} | |||
else | |||
return qCritical("DigitalPeakMeter::setColor(%i) - invalid color", color); | |||
setOrientation(m_orientation); | |||
setOrientation(fOrientation); | |||
} | |||
void DigitalPeakMeter::setOrientation(Orientation orientation) | |||
{ | |||
m_orientation = orientation; | |||
fOrientation = orientation; | |||
if (m_orientation == HORIZONTAL) | |||
if (fOrientation == HORIZONTAL) | |||
{ | |||
m_gradientMeter.setColorAt(0.0f, m_colorBase); | |||
m_gradientMeter.setColorAt(0.2f, m_colorBase); | |||
m_gradientMeter.setColorAt(0.4f, m_colorBase); | |||
m_gradientMeter.setColorAt(0.6f, m_colorBase); | |||
m_gradientMeter.setColorAt(0.8f, Qt::yellow); | |||
m_gradientMeter.setColorAt(1.0f, Qt::red); | |||
fGradientMeter.setColorAt(0.0f, fColorBase); | |||
fGradientMeter.setColorAt(0.2f, fColorBase); | |||
fGradientMeter.setColorAt(0.4f, fColorBase); | |||
fGradientMeter.setColorAt(0.6f, fColorBase); | |||
fGradientMeter.setColorAt(0.8f, Qt::yellow); | |||
fGradientMeter.setColorAt(1.0f, Qt::red); | |||
} | |||
else if (m_orientation == VERTICAL) | |||
else if (fOrientation == VERTICAL) | |||
{ | |||
m_gradientMeter.setColorAt(0.0f, Qt::red); | |||
m_gradientMeter.setColorAt(0.2f, Qt::yellow); | |||
m_gradientMeter.setColorAt(0.4f, m_colorBase); | |||
m_gradientMeter.setColorAt(0.6f, m_colorBase); | |||
m_gradientMeter.setColorAt(0.8f, m_colorBase); | |||
m_gradientMeter.setColorAt(1.0f, m_colorBase); | |||
fGradientMeter.setColorAt(0.0f, Qt::red); | |||
fGradientMeter.setColorAt(0.2f, Qt::yellow); | |||
fGradientMeter.setColorAt(0.4f, fColorBase); | |||
fGradientMeter.setColorAt(0.6f, fColorBase); | |||
fGradientMeter.setColorAt(0.8f, fColorBase); | |||
fGradientMeter.setColorAt(1.0f, fColorBase); | |||
} | |||
else | |||
return qCritical("DigitalPeakMeter::setOrientation(%i) - invalid orientation", orientation); | |||
@@ -121,9 +150,9 @@ void DigitalPeakMeter::setRefreshRate(int rate) | |||
{ | |||
Q_ASSERT(rate > 0); | |||
m_paintTimer.stop(); | |||
m_paintTimer.setInterval(rate); | |||
m_paintTimer.start(); | |||
fPaintTimer.stop(); | |||
fPaintTimer.setInterval(rate); | |||
fPaintTimer.start(); | |||
} | |||
void DigitalPeakMeter::setSmoothRelease(int value) | |||
@@ -135,7 +164,7 @@ void DigitalPeakMeter::setSmoothRelease(int value) | |||
else if (value > 5) | |||
value = 5; | |||
m_smoothMultiplier = value; | |||
fSmoothMultiplier = value; | |||
} | |||
QSize DigitalPeakMeter::minimumSizeHint() const | |||
@@ -145,121 +174,122 @@ QSize DigitalPeakMeter::minimumSizeHint() const | |||
QSize DigitalPeakMeter::sizeHint() const | |||
{ | |||
return QSize(m_width, m_height); | |||
return QSize(fWidth, fHeight); | |||
} | |||
void DigitalPeakMeter::updateSizes() | |||
{ | |||
m_width = width(); | |||
m_height = height(); | |||
m_sizeMeter = 0; | |||
fWidth = width(); | |||
fHeight = height(); | |||
fSizeMeter = 0; | |||
if (m_orientation == HORIZONTAL) | |||
if (fOrientation == HORIZONTAL) | |||
{ | |||
m_gradientMeter.setFinalStop(m_width, 0); | |||
fGradientMeter.setFinalStop(fWidth, 0); | |||
if (m_channels > 0) | |||
m_sizeMeter = m_height/m_channels; | |||
if (fChannels > 0) | |||
fSizeMeter = fHeight/fChannels; | |||
} | |||
else if (m_orientation == VERTICAL) | |||
else if (fOrientation == VERTICAL) | |||
{ | |||
m_gradientMeter.setFinalStop(0, m_height); | |||
fGradientMeter.setFinalStop(0, fHeight); | |||
if (m_channels > 0) | |||
m_sizeMeter = m_width/m_channels; | |||
if (fChannels > 0) | |||
fSizeMeter = fWidth/fChannels; | |||
} | |||
} | |||
void DigitalPeakMeter::paintEvent(QPaintEvent*) | |||
void DigitalPeakMeter::paintEvent(QPaintEvent* event) | |||
{ | |||
QPainter painter(this); | |||
event->accept(); | |||
painter.setPen(Qt::black); | |||
painter.setBrush(Qt::black); | |||
painter.drawRect(0, 0, m_width, m_height); | |||
painter.drawRect(0, 0, fWidth, fHeight); | |||
int meterX = 0; | |||
painter.setPen(m_colorBackground); | |||
painter.setBrush(m_gradientMeter); | |||
painter.setPen(fColorBackground); | |||
painter.setBrush(fGradientMeter); | |||
for (int i=0; i < m_channels; i++) | |||
for (int i=0; i < fChannels; i++) | |||
{ | |||
float value, level = m_channelsData[i]; | |||
float value, level = fChannelsData[i]; | |||
if (level == m_lastValueData[i]) | |||
if (level == fLastValueData[i]) | |||
continue; | |||
if (m_orientation == HORIZONTAL) | |||
value = level * m_width; | |||
else if (m_orientation == VERTICAL) | |||
value = float(m_height) - (level * m_height); | |||
if (fOrientation == HORIZONTAL) | |||
value = level * float(fWidth); | |||
else if (fOrientation == VERTICAL) | |||
value = float(fHeight) - (level * float(fHeight)); | |||
else | |||
value = 0.0f; | |||
if (value < 0.0f) | |||
value = 0.0f; | |||
else if (m_smoothMultiplier > 0) | |||
value = (m_lastValueData[i] * m_smoothMultiplier + value) / (m_smoothMultiplier + 1); | |||
else if (fSmoothMultiplier > 0) | |||
value = (fLastValueData[i] * float(fSmoothMultiplier) + value) / float(fSmoothMultiplier + 1); | |||
if (m_orientation == HORIZONTAL) | |||
painter.drawRect(0, meterX, value, m_sizeMeter); | |||
else if (m_orientation == VERTICAL) | |||
painter.drawRect(meterX, value, m_sizeMeter, m_height); | |||
if (fOrientation == HORIZONTAL) | |||
painter.drawRect(0, meterX, int(value), fSizeMeter); | |||
else if (fOrientation == VERTICAL) | |||
painter.drawRect(meterX, int(value), fSizeMeter, fHeight); | |||
meterX += m_sizeMeter; | |||
m_lastValueData[i] = value; | |||
meterX += fSizeMeter; | |||
fLastValueData[i] = value; | |||
} | |||
painter.setBrush(QColor(0, 0, 0, 0)); | |||
painter.setBrush(Qt::black); | |||
if (m_orientation == HORIZONTAL) | |||
if (fOrientation == HORIZONTAL) | |||
{ | |||
// Variables | |||
int lsmall = m_width; | |||
int lfull = m_height - 1; | |||
float lsmall = fWidth; | |||
float lfull = fHeight - 1; | |||
// Base | |||
painter.setPen(m_colorBaseT); | |||
painter.drawLine(lsmall * 0.25f, 2, lsmall * 0.25f, lfull-2); | |||
painter.drawLine(lsmall * 0.50f, 2, lsmall * 0.50f, lfull-2); | |||
painter.setPen(fColorBaseAlt); | |||
painter.drawLine(lsmall * 0.25f, 2, lsmall * 0.25f, lfull-2.0f); | |||
painter.drawLine(lsmall * 0.50f, 2, lsmall * 0.50f, lfull-2.0f); | |||
// Yellow | |||
painter.setPen(QColor(110, 110, 15, 100)); | |||
painter.drawLine(lsmall * 0.70f, 2, lsmall * 0.70f, lfull-2); | |||
painter.drawLine(lsmall * 0.83f, 2, lsmall * 0.83f, lfull-2); | |||
painter.drawLine(lsmall * 0.70f, 2, lsmall * 0.70f, lfull-2.0f); | |||
painter.drawLine(lsmall * 0.83f, 2, lsmall * 0.83f, lfull-2.0f); | |||
// Orange | |||
painter.setPen(QColor(180, 110, 15, 100)); | |||
painter.drawLine(lsmall * 0.90f, 2, lsmall * 0.90f, lfull-2); | |||
painter.drawLine(lsmall * 0.90f, 2, lsmall * 0.90f, lfull-2.0f); | |||
// Red | |||
painter.setPen(QColor(110, 15, 15, 100)); | |||
painter.drawLine(lsmall * 0.96f, 2, lsmall * 0.96f, lfull-2); | |||
painter.drawLine(lsmall * 0.96f, 2, lsmall * 0.96f, lfull-2.0f); | |||
} | |||
else if (m_orientation == VERTICAL) | |||
else if (fOrientation == VERTICAL) | |||
{ | |||
// Variables | |||
int lsmall = m_height; | |||
int lfull = m_width - 1; | |||
float lsmall = fHeight; | |||
float lfull = fWidth - 1; | |||
// Base | |||
painter.setPen(m_colorBaseT); | |||
painter.drawLine(2, lsmall - (lsmall * 0.25f), lfull-2, lsmall - (lsmall * 0.25f)); | |||
painter.drawLine(2, lsmall - (lsmall * 0.50f), lfull-2, lsmall - (lsmall * 0.50f)); | |||
painter.setPen(fColorBaseAlt); | |||
painter.drawLine(2, lsmall - (lsmall * 0.25f), lfull-2.0f, lsmall - (lsmall * 0.25f)); | |||
painter.drawLine(2, lsmall - (lsmall * 0.50f), lfull-2.0f, lsmall - (lsmall * 0.50f)); | |||
// Yellow | |||
painter.setPen(QColor(110, 110, 15, 100)); | |||
painter.drawLine(2, lsmall - (lsmall * 0.70f), lfull-2, lsmall - (lsmall * 0.70f)); | |||
painter.drawLine(2, lsmall - (lsmall * 0.83f), lfull-2, lsmall - (lsmall * 0.83f)); | |||
painter.drawLine(2, lsmall - (lsmall * 0.70f), lfull-2.0f, lsmall - (lsmall * 0.70f)); | |||
painter.drawLine(2, lsmall - (lsmall * 0.83f), lfull-2.0f, lsmall - (lsmall * 0.83f)); | |||
// Orange | |||
painter.setPen(QColor(180, 110, 15, 100)); | |||
painter.drawLine(2, lsmall - (lsmall * 0.90f), lfull-2, lsmall - (lsmall * 0.90f)); | |||
painter.drawLine(2, lsmall - (lsmall * 0.90f), lfull-2.0f, lsmall - (lsmall * 0.90f)); | |||
// Red | |||
painter.setPen(QColor(110, 15, 15, 100)); | |||
painter.drawLine(2, lsmall - (lsmall * 0.96f), lfull-2, lsmall - (lsmall * 0.96f)); | |||
painter.drawLine(2, lsmall - (lsmall * 0.96f), lfull-2.0f, lsmall - (lsmall * 0.96f)); | |||
} | |||
} | |||
@@ -35,6 +35,7 @@ public: | |||
}; | |||
DigitalPeakMeter(QWidget* parent); | |||
~DigitalPeakMeter(); | |||
void displayMeter(int meter, float level); | |||
void setChannels(int channels); | |||
@@ -53,21 +54,21 @@ protected: | |||
void resizeEvent(QResizeEvent* event); | |||
private: | |||
int m_channels; | |||
int m_smoothMultiplier; | |||
int m_width, m_height, m_sizeMeter; | |||
Orientation m_orientation; | |||
int fChannels; | |||
int fSmoothMultiplier; | |||
int fWidth, fHeight, fSizeMeter; | |||
Orientation fOrientation; | |||
QColor m_colorBackground; | |||
QLinearGradient m_gradientMeter; | |||
QColor fColorBackground; | |||
QLinearGradient fGradientMeter; | |||
QColor m_colorBase; | |||
QColor m_colorBaseT; | |||
QColor fColorBase; | |||
QColor fColorBaseAlt; | |||
QList<float> m_channelsData; | |||
QList<float> m_lastValueData; | |||
float* fChannelsData; | |||
float* fLastValueData; | |||
QTimer m_paintTimer; | |||
QTimer fPaintTimer; | |||
}; | |||
#endif // __DIGITALPEAKMETER_HPP__ |
@@ -61,7 +61,7 @@ class DigitalPeakMeter(QWidget): | |||
elif level > 1.0: | |||
level = 1.0 | |||
self.fChannelsData[meter-1] = level | |||
self.fChannelsData[meter-1] = float(level) | |||
def setChannels(self, channels): | |||
if channels < 0: | |||
@@ -77,11 +77,11 @@ class DigitalPeakMeter(QWidget): | |||
def setColor(self, color): | |||
if color == self.GREEN: | |||
self.fColorBase = QColor(93, 231, 61) | |||
self.fColorBaseT = QColor(15, 110, 15, 100) | |||
self.fColorBase = QColor(93, 231, 61) | |||
self.fColorBaseAlt = QColor(15, 110, 15, 100) | |||
elif color == self.BLUE: | |||
self.fColorBase = QColor(82, 238, 248) | |||
self.fColorBaseT = QColor(15, 15, 110, 100) | |||
self.fColorBase = QColor(82, 238, 248) | |||
self.fColorBaseAlt = QColor(15, 15, 110, 100) | |||
else: | |||
return qCritical("DigitalPeakMeter::setColor(%i) - invalid color" % color) | |||
@@ -149,6 +149,7 @@ class DigitalPeakMeter(QWidget): | |||
def paintEvent(self, event): | |||
painter = QPainter(self) | |||
event.accept() | |||
painter.setPen(Qt.black) | |||
painter.setBrush(Qt.black) | |||
@@ -165,74 +166,72 @@ class DigitalPeakMeter(QWidget): | |||
continue | |||
if self.fOrientation == self.HORIZONTAL: | |||
value = level * self.fWidth | |||
value = level * float(self.fWidth) | |||
elif self.fOrientation == self.VERTICAL: | |||
value = float(self.fHeight) - (level * self.fHeight) | |||
value = float(self.fHeight) - (level * float(self.fHeight)) | |||
else: | |||
value = 0.0 | |||
if value < 0.0: | |||
value = 0.0 | |||
elif self.fSmoothMultiplier > 0: | |||
value = (self.fLastValueData[i] * self.fSmoothMultiplier + value) / (self.fSmoothMultiplier + 1) | |||
value = (self.fLastValueData[i] * self.fSmoothMultiplier + value) / float(self.fSmoothMultiplier + 1) | |||
if self.fOrientation == self.HORIZONTAL: | |||
painter.drawRect(0, meterX, value, self.fSizeMeter) | |||
painter.drawRect(0, meterX, int(value), self.fSizeMeter) | |||
elif self.fOrientation == self.VERTICAL: | |||
painter.drawRect(meterX, value, self.fSizeMeter, self.fHeight) | |||
painter.drawRect(meterX, int(value), self.fSizeMeter, self.fHeight) | |||
meterX += self.fSizeMeter | |||
self.fLastValueData[i] = value | |||
painter.setBrush(QColor(0, 0, 0, 0)) | |||
painter.setBrush(Qt.black) | |||
if self.fOrientation == self.HORIZONTAL: | |||
# Variables | |||
lsmall = self.fWidth | |||
lfull = self.fHeight - 1 | |||
lsmall = float(self.fWidth) | |||
lfull = float(self.fHeight - 1) | |||
# Base | |||
painter.setPen(self.fColorBaseT) | |||
painter.drawLine(lsmall * 0.25, 2, lsmall * 0.25, lfull-2) | |||
painter.drawLine(lsmall * 0.50, 2, lsmall * 0.50, lfull-2) | |||
painter.setPen(self.fColorBaseAlt) | |||
painter.drawLine(lsmall * 0.25, 2, lsmall * 0.25, lfull-2.0) | |||
painter.drawLine(lsmall * 0.50, 2, lsmall * 0.50, lfull-2.0) | |||
# Yellow | |||
painter.setPen(QColor(110, 110, 15, 100)) | |||
painter.drawLine(lsmall * 0.70, 2, lsmall * 0.70, lfull-2) | |||
painter.drawLine(lsmall * 0.83, 2, lsmall * 0.83, lfull-2) | |||
painter.drawLine(lsmall * 0.70, 2, lsmall * 0.70, lfull-2.0) | |||
painter.drawLine(lsmall * 0.83, 2, lsmall * 0.83, lfull-2.0) | |||
# Orange | |||
painter.setPen(QColor(180, 110, 15, 100)) | |||
painter.drawLine(lsmall * 0.90, 2, lsmall * 0.90, lfull-2) | |||
painter.drawLine(lsmall * 0.90, 2, lsmall * 0.90, lfull-2.0) | |||
# Red | |||
painter.setPen(QColor(110, 15, 15, 100)) | |||
painter.drawLine(lsmall * 0.96, 2, lsmall * 0.96, lfull-2) | |||
painter.drawLine(lsmall * 0.96, 2, lsmall * 0.96, lfull-2.0) | |||
elif self.fOrientation == self.VERTICAL: | |||
# Variables | |||
lsmall = self.fHeight | |||
lfull = self.fWidth - 1 | |||
lsmall = float(self.fHeight) | |||
lfull = float(self.fWidth - 1) | |||
# Base | |||
painter.setPen(self.fColorBaseT) | |||
painter.drawLine(2, lsmall - (lsmall * 0.25), lfull-2, lsmall - (lsmall * 0.25)) | |||
painter.drawLine(2, lsmall - (lsmall * 0.50), lfull-2, lsmall - (lsmall * 0.50)) | |||
painter.setPen(self.fColorBaseAlt) | |||
painter.drawLine(2, lsmall - (lsmall * 0.25), lfull-2.0, lsmall - (lsmall * 0.25)) | |||
painter.drawLine(2, lsmall - (lsmall * 0.50), lfull-2.0, lsmall - (lsmall * 0.50)) | |||
# Yellow | |||
painter.setPen(QColor(110, 110, 15, 100)) | |||
painter.drawLine(2, lsmall - (lsmall * 0.70), lfull-2, lsmall - (lsmall * 0.70)) | |||
painter.drawLine(2, lsmall - (lsmall * 0.82), lfull-2, lsmall - (lsmall * 0.82)) | |||
painter.drawLine(2, lsmall - (lsmall * 0.70), lfull-2.0, lsmall - (lsmall * 0.70)) | |||
painter.drawLine(2, lsmall - (lsmall * 0.82), lfull-2.0, lsmall - (lsmall * 0.82)) | |||
# Orange | |||
painter.setPen(QColor(180, 110, 15, 100)) | |||
painter.drawLine(2, lsmall - (lsmall * 0.90), lfull-2, lsmall - (lsmall * 0.90)) | |||
painter.drawLine(2, lsmall - (lsmall * 0.90), lfull-2.0, lsmall - (lsmall * 0.90)) | |||
# Red | |||
painter.setPen(QColor(110, 15, 15, 100)) | |||
painter.drawLine(2, lsmall - (lsmall * 0.96), lfull-2, lsmall - (lsmall * 0.96)) | |||
event.accept() | |||
painter.drawLine(2, lsmall - (lsmall * 0.96), lfull-2.0, lsmall - (lsmall * 0.96)) | |||
def resizeEvent(self, event): | |||
self.updateSizes() | |||
@@ -1,21 +1,21 @@ | |||
/* | |||
* Parameter Progress-Bar, a custom Qt4 widget | |||
* Copyright (C) 2012-2013 Filipe Coelho <falktx@falktx.com> | |||
* Parameter SpinBox, a custom Qt4 widget | |||
* Copyright (C) 2011-2013 Filipe Coelho <falktx@falktx.com> | |||
* | |||
* This program is free software; you can redistribute it and/or | |||
* modify it under the terms of the GNU General Public License as | |||
* published by the Free Software Foundation; either version 2 of | |||
* the License, or any later version. | |||
* This program is free software; you can redistribute it and/or modify | |||
* it under the terms of the GNU General Public License as published by | |||
* the Free Software Foundation; either version 2 of the License, or | |||
* any later version. | |||
* | |||
* This program is distributed in the hope that it will be useful, | |||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | |||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |||
* GNU General Public License for more details. | |||
* | |||
* For a full copy of the GNU General Public License see the GPL.txt file | |||
* For a full copy of the GNU General Public License see the COPYING file | |||
*/ | |||
#include "paramspinbox.h" | |||
#include "paramspinbox.hpp" | |||
#include <QtGui/QMouseEvent> | |||
@@ -1,29 +1,29 @@ | |||
/* | |||
* Parameter Progress-Bar, a custom Qt4 widget | |||
* Copyright (C) 2012-2013 Filipe Coelho <falktx@falktx.com> | |||
* Parameter SpinBox, a custom Qt4 widget | |||
* Copyright (C) 2011-2013 Filipe Coelho <falktx@falktx.com> | |||
* | |||
* This program is free software; you can redistribute it and/or | |||
* modify it under the terms of the GNU General Public License as | |||
* published by the Free Software Foundation; either version 2 of | |||
* the License, or any later version. | |||
* This program is free software; you can redistribute it and/or modify | |||
* it under the terms of the GNU General Public License as published by | |||
* the Free Software Foundation; either version 2 of the License, or | |||
* any later version. | |||
* | |||
* This program is distributed in the hope that it will be useful, | |||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | |||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |||
* GNU General Public License for more details. | |||
* | |||
* For a full copy of the GNU General Public License see the GPL.txt file | |||
* For a full copy of the GNU General Public License see the COPYING file | |||
*/ | |||
#ifndef __PARAMPROGRESSBAR_HPP__ | |||
#define __PARAMPROGRESSBAR_HPP__ | |||
#ifndef __PARAMSPINBOX_HPP__ | |||
#define __PARAMSPINBOX_HPP__ | |||
#include <QtGui/QProgressBar> | |||
class TextCallback | |||
{ | |||
public: | |||
virtual ~TextCallback() {} | |||
virtual ~TextCallback(); | |||
virtual const char* textCallBack() = 0; | |||
}; | |||
@@ -61,4 +61,4 @@ private: | |||
TextCallback* m_textCall; | |||
}; | |||
#endif // __PARAMPROGRESSBAR_HPP__ | |||
#endif // #define __PARAMSPINBOX_HPP__ |
@@ -17,141 +17,129 @@ | |||
#include "pixmapkeyboard.hpp" | |||
#include <QtCore/QMap> | |||
#include <QtCore/QTimer> | |||
#include <QtGui/QKeyEvent> | |||
#include <QtGui/QMouseEvent> | |||
#include <QtGui/QPainter> | |||
QMap<int, QRectF> midi_key2rect_map_horizontal; | |||
QMap<int, QRectF> midi_key2rect_map_vertical; | |||
QMap<int, int> midi_keyboard2key_map; | |||
QVector<int> blackNotes; | |||
static bool pixmapkeyboard_initiated = false; | |||
void pixmapkeyboard_init() | |||
{ | |||
if (pixmapkeyboard_initiated) | |||
return; | |||
pixmapkeyboard_initiated = true; | |||
// midi_key2rect_map_horizontal ------ | |||
midi_key2rect_map_horizontal[0] = QRectF(0, 0, 18, 64); // C | |||
midi_key2rect_map_horizontal[1] = QRectF(13, 0, 11, 42); // C# | |||
midi_key2rect_map_horizontal[2] = QRectF(18, 0, 25, 64); // D | |||
midi_key2rect_map_horizontal[3] = QRectF(37, 0, 11, 42); // D# | |||
midi_key2rect_map_horizontal[4] = QRectF(42, 0, 18, 64); // E | |||
midi_key2rect_map_horizontal[5] = QRectF(60, 0, 18, 64); // F | |||
midi_key2rect_map_horizontal[6] = QRectF(73, 0, 11, 42); // F# | |||
midi_key2rect_map_horizontal[7] = QRectF(78, 0, 25, 64); // G | |||
midi_key2rect_map_horizontal[8] = QRectF(97, 0, 11, 42); // G# | |||
midi_key2rect_map_horizontal[9] = QRectF(102, 0, 25, 64); // A | |||
midi_key2rect_map_horizontal[10] = QRectF(121, 0, 11, 42); // A# | |||
midi_key2rect_map_horizontal[11] = QRectF(126, 0, 18, 64); // B | |||
// midi_key2rect_map_vertical -------- | |||
midi_key2rect_map_vertical[11] = QRectF(0, 0, 64, 18); // B | |||
midi_key2rect_map_vertical[10] = QRectF(0, 14, 42, 7); // A# | |||
midi_key2rect_map_vertical[9] = QRectF(0, 18, 64, 24); // A | |||
midi_key2rect_map_vertical[8] = QRectF(0, 38, 42, 7); // G# | |||
midi_key2rect_map_vertical[7] = QRectF(0, 42, 64, 24); // G | |||
midi_key2rect_map_vertical[6] = QRectF(0, 62, 42, 7); // F# | |||
midi_key2rect_map_vertical[5] = QRectF(0, 66, 64, 18); // F | |||
midi_key2rect_map_vertical[4] = QRectF(0, 84, 64, 18); // E | |||
midi_key2rect_map_vertical[3] = QRectF(0, 98, 42, 7); // D# | |||
midi_key2rect_map_vertical[2] = QRectF(0, 102, 64, 24); // D | |||
midi_key2rect_map_vertical[1] = QRectF(0, 122, 42, 7); // C# | |||
midi_key2rect_map_vertical[0] = QRectF(0, 126, 64, 18); // C | |||
// midi_keyboard2key_map ------------- | |||
static std::map<int, QRectF> kMidiKey2RectMapHorizontal = { | |||
{0, QRectF(0, 0, 18, 64)}, // C | |||
{1, QRectF(13, 0, 11, 42)}, // C# | |||
{2, QRectF(18, 0, 25, 64)}, // D | |||
{3, QRectF(37, 0, 11, 42)}, // D# | |||
{4, QRectF(42, 0, 18, 64)}, // E | |||
{5, QRectF(60, 0, 18, 64)}, // F | |||
{6, QRectF(73, 0, 11, 42)}, // F# | |||
{7, QRectF(78, 0, 25, 64)}, // G | |||
{8, QRectF(97, 0, 11, 42)}, // G# | |||
{9, QRectF(102, 0, 25, 64)}, // A | |||
{10, QRectF(121, 0, 11, 42)}, // A# | |||
{11, QRectF(126, 0, 18, 64)} // B | |||
}; | |||
static std::map<int, QRectF> kMidiKey2RectMapVertical = { | |||
{11, QRectF(0, 0, 64, 18)}, // B | |||
{10, QRectF(0, 14, 42, 7)}, // A# | |||
{9, QRectF(0, 18, 64, 24)}, // A | |||
{8, QRectF(0, 38, 42, 7)}, // G# | |||
{7, QRectF(0, 42, 64, 24)}, // G | |||
{6, QRectF(0, 62, 42, 7)}, // F# | |||
{5, QRectF(0, 66, 64, 18)}, // F | |||
{4, QRectF(0, 84, 64, 18)}, // E | |||
{3, QRectF(0, 98, 42, 7)}, // D# | |||
{2, QRectF(0, 102, 64, 24)}, // D | |||
{1, QRectF(0, 122, 42, 7)}, // C# | |||
{0, QRectF(0, 126, 64, 18)} // C | |||
}; | |||
static const std::map<int, int> kMidiKeyboard2KeyMap = { | |||
// 3th octave | |||
midi_keyboard2key_map[Qt::Key_Z] = 48; | |||
midi_keyboard2key_map[Qt::Key_S] = 49; | |||
midi_keyboard2key_map[Qt::Key_X] = 50; | |||
midi_keyboard2key_map[Qt::Key_D] = 51; | |||
midi_keyboard2key_map[Qt::Key_C] = 52; | |||
midi_keyboard2key_map[Qt::Key_V] = 53; | |||
midi_keyboard2key_map[Qt::Key_G] = 54; | |||
midi_keyboard2key_map[Qt::Key_B] = 55; | |||
midi_keyboard2key_map[Qt::Key_H] = 56; | |||
midi_keyboard2key_map[Qt::Key_N] = 57; | |||
midi_keyboard2key_map[Qt::Key_J] = 58; | |||
midi_keyboard2key_map[Qt::Key_M] = 59; | |||
{Qt::Key_Z, 48}, | |||
{Qt::Key_S, 49}, | |||
{Qt::Key_X, 50}, | |||
{Qt::Key_D, 51}, | |||
{Qt::Key_C, 52}, | |||
{Qt::Key_V, 53}, | |||
{Qt::Key_G, 54}, | |||
{Qt::Key_B, 55}, | |||
{Qt::Key_H, 56}, | |||
{Qt::Key_N, 57}, | |||
{Qt::Key_J, 58}, | |||
{Qt::Key_M, 59}, | |||
// 4th octave | |||
midi_keyboard2key_map[Qt::Key_Q] = 60; | |||
midi_keyboard2key_map[Qt::Key_2] = 61; | |||
midi_keyboard2key_map[Qt::Key_W] = 62; | |||
midi_keyboard2key_map[Qt::Key_3] = 63; | |||
midi_keyboard2key_map[Qt::Key_E] = 64; | |||
midi_keyboard2key_map[Qt::Key_R] = 65; | |||
midi_keyboard2key_map[Qt::Key_5] = 66; | |||
midi_keyboard2key_map[Qt::Key_T] = 67; | |||
midi_keyboard2key_map[Qt::Key_6] = 68; | |||
midi_keyboard2key_map[Qt::Key_Y] = 69; | |||
midi_keyboard2key_map[Qt::Key_7] = 70; | |||
midi_keyboard2key_map[Qt::Key_U] = 71; | |||
blackNotes << 1; | |||
blackNotes << 3; | |||
blackNotes << 6; | |||
blackNotes << 8; | |||
blackNotes << 10; | |||
} | |||
{Qt::Key_Q, 60}, | |||
{Qt::Key_2, 61}, | |||
{Qt::Key_W, 62}, | |||
{Qt::Key_3, 63}, | |||
{Qt::Key_E, 64}, | |||
{Qt::Key_R, 65}, | |||
{Qt::Key_5, 66}, | |||
{Qt::Key_T, 67}, | |||
{Qt::Key_6, 68}, | |||
{Qt::Key_Y, 69}, | |||
{Qt::Key_7, 70}, | |||
{Qt::Key_U, 71} | |||
}; | |||
static const QVector<int> kBlackNotes = {1, 3, 6, 8, 10}; | |||
PixmapKeyboard::PixmapKeyboard(QWidget* parent) | |||
: QWidget(parent), | |||
m_font("Monospace", 8, QFont::Normal) | |||
fPixmap(""), | |||
fPixmapMode(HORIZONTAL), | |||
fColorStr("orange"), | |||
fFont("Monospace", 8, QFont::Normal), | |||
fOctaves(6), | |||
fLastMouseNote(-1), | |||
fWidth(0), | |||
fHeight(0), | |||
fNeedsUpdate(false), | |||
fMidiMap(kMidiKey2RectMapHorizontal) | |||
{ | |||
pixmapkeyboard_init(); | |||
m_octaves = 6; | |||
m_lastMouseNote = -1; | |||
m_needsUpdate = false; | |||
setCursor(Qt::PointingHandCursor); | |||
setMode(HORIZONTAL); | |||
} | |||
void PixmapKeyboard::allNotesOff() | |||
{ | |||
m_enabledKeys.clear(); | |||
m_needsUpdate = true; | |||
QTimer::singleShot(0, this, SLOT(updateOnce())); | |||
fEnabledKeys.clear(); | |||
fNeedsUpdate = true; | |||
emit notesOff(); | |||
QTimer::singleShot(0, this, SLOT(updateOnce())); | |||
} | |||
void PixmapKeyboard::sendNoteOn(int note, bool sendSignal) | |||
{ | |||
if (0 <= note && note <= 127 && ! m_enabledKeys.contains(note)) | |||
if (0 <= note && note <= 127 && ! fEnabledKeys.contains(note)) | |||
{ | |||
m_enabledKeys.append(note); | |||
fEnabledKeys.append(note); | |||
if (sendSignal) | |||
emit noteOn(note); | |||
m_needsUpdate = true; | |||
fNeedsUpdate = true; | |||
QTimer::singleShot(0, this, SLOT(updateOnce())); | |||
} | |||
if (m_enabledKeys.count() == 1) | |||
if (fEnabledKeys.count() == 1) | |||
emit notesOn(); | |||
} | |||
void PixmapKeyboard::sendNoteOff(int note, bool sendSignal) | |||
{ | |||
if (note >= 0 && note <= 127 && m_enabledKeys.contains(note)) | |||
if (note >= 0 && note <= 127 && fEnabledKeys.contains(note)) | |||
{ | |||
m_enabledKeys.removeOne(note); | |||
fEnabledKeys.removeOne(note); | |||
if (sendSignal) | |||
emit noteOff(note); | |||
m_needsUpdate = true; | |||
fNeedsUpdate = true; | |||
QTimer::singleShot(0, this, SLOT(updateOnce())); | |||
} | |||
if (m_enabledKeys.count() == 0) | |||
if (fEnabledKeys.count() == 0) | |||
emit notesOff(); | |||
} | |||
@@ -159,11 +147,11 @@ void PixmapKeyboard::setMode(Orientation mode, Color color) | |||
{ | |||
if (color == COLOR_CLASSIC) | |||
{ | |||
m_colorStr = "classic"; | |||
fColorStr = "classic"; | |||
} | |||
else if (color == COLOR_ORANGE) | |||
{ | |||
m_colorStr = "orange"; | |||
fColorStr = "orange"; | |||
} | |||
else | |||
{ | |||
@@ -173,19 +161,19 @@ void PixmapKeyboard::setMode(Orientation mode, Color color) | |||
if (mode == HORIZONTAL) | |||
{ | |||
m_midi_map = &midi_key2rect_map_horizontal; | |||
m_pixmap.load(QString(":/bitmaps/kbd_h_%1.png").arg(m_colorStr)); | |||
m_pixmap_mode = HORIZONTAL; | |||
p_width = m_pixmap.width(); | |||
p_height = m_pixmap.height() / 2; | |||
fMidiMap = kMidiKey2RectMapHorizontal; | |||
fPixmap.load(QString(":/bitmaps/kbd_h_%1.png").arg(fColorStr)); | |||
fPixmapMode = HORIZONTAL; | |||
fWidth = fPixmap.width(); | |||
fHeight = fPixmap.height() / 2; | |||
} | |||
else if (mode == VERTICAL) | |||
{ | |||
m_midi_map = &midi_key2rect_map_vertical; | |||
m_pixmap.load(QString(":/bitmaps/kbd_v_%1.png").arg(m_colorStr)); | |||
m_pixmap_mode = VERTICAL; | |||
p_width = m_pixmap.width() / 2; | |||
p_height = m_pixmap.height(); | |||
fMidiMap = kMidiKey2RectMapVertical; | |||
fPixmap.load(QString(":/bitmaps/kbd_v_%1.png").arg(fColorStr)); | |||
fPixmapMode = VERTICAL; | |||
fWidth = fPixmap.width() / 2; | |||
fHeight = fPixmap.height(); | |||
} | |||
else | |||
{ | |||
@@ -193,28 +181,29 @@ void PixmapKeyboard::setMode(Orientation mode, Color color) | |||
return setMode(HORIZONTAL); | |||
} | |||
setOctaves(m_octaves); | |||
setOctaves(fOctaves); | |||
} | |||
void PixmapKeyboard::setOctaves(int octaves) | |||
{ | |||
Q_ASSERT(octaves >= 1 && octaves <= 6); | |||
Q_ASSERT(octaves >= 1 && octaves <= 8); | |||
if (octaves < 1) | |||
octaves = 1; | |||
else if (octaves > 6) | |||
octaves = 6; | |||
m_octaves = octaves; | |||
else if (octaves > 8) | |||
octaves = 8; | |||
if (m_pixmap_mode == HORIZONTAL) | |||
fOctaves = octaves; | |||
if (fPixmapMode == HORIZONTAL) | |||
{ | |||
setMinimumSize(p_width * m_octaves, p_height); | |||
setMaximumSize(p_width * m_octaves, p_height); | |||
setMinimumSize(fWidth * fOctaves, fHeight); | |||
setMaximumSize(fWidth * fOctaves, fHeight); | |||
} | |||
else if (m_pixmap_mode == VERTICAL) | |||
else if (fPixmapMode == VERTICAL) | |||
{ | |||
setMinimumSize(p_width, p_height * m_octaves); | |||
setMaximumSize(p_width, p_height * m_octaves); | |||
setMinimumSize(fWidth, fHeight * fOctaves); | |||
setMaximumSize(fWidth, fHeight * fOctaves); | |||
} | |||
update(); | |||
@@ -222,53 +211,54 @@ void PixmapKeyboard::setOctaves(int octaves) | |||
void PixmapKeyboard::handleMousePos(const QPoint& pos) | |||
{ | |||
int note, octave; | |||
QPointF n_pos; | |||
int note; | |||
int octave; | |||
QPointF keyPos; | |||
if (m_pixmap_mode == HORIZONTAL) | |||
if (fPixmapMode == HORIZONTAL) | |||
{ | |||
if (pos.x() < 0 or pos.x() > m_octaves * 144) | |||
if (pos.x() < 0 or pos.x() > fOctaves * 144) | |||
return; | |||
int posX = pos.x() - 1; | |||
octave = posX / p_width; | |||
n_pos = QPointF(posX % p_width, pos.y()); | |||
octave = posX / fWidth; | |||
keyPos = QPointF(posX % fWidth, pos.y()); | |||
} | |||
else if (m_pixmap_mode == VERTICAL) | |||
else if (fPixmapMode == VERTICAL) | |||
{ | |||
if (pos.y() < 0 or pos.y() > m_octaves * 144) | |||
if (pos.y() < 0 or pos.y() > fOctaves * 144) | |||
return; | |||
int posY = pos.y() - 1; | |||
octave = m_octaves - posY / p_height; | |||
n_pos = QPointF(pos.x(), posY % p_height); | |||
octave = fOctaves - posY / fHeight; | |||
keyPos = QPointF(pos.x(), posY % fHeight); | |||
} | |||
else | |||
return; | |||
octave += 3; | |||
if ((*m_midi_map)[1].contains(n_pos)) // C# | |||
if (fMidiMap[1].contains(keyPos)) // C# | |||
note = 1; | |||
else if ((*m_midi_map)[3].contains(n_pos)) // D# | |||
else if (fMidiMap[3].contains(keyPos)) // D# | |||
note = 3; | |||
else if ((*m_midi_map)[6].contains(n_pos)) // F# | |||
else if (fMidiMap[6].contains(keyPos)) // F# | |||
note = 6; | |||
else if ((*m_midi_map)[8].contains(n_pos)) // G# | |||
else if (fMidiMap[8].contains(keyPos)) // G# | |||
note = 8; | |||
else if ((*m_midi_map)[10].contains(n_pos))// A# | |||
else if (fMidiMap[10].contains(keyPos))// A# | |||
note = 10; | |||
else if ((*m_midi_map)[0].contains(n_pos)) // C | |||
else if (fMidiMap[0].contains(keyPos)) // C | |||
note = 0; | |||
else if ((*m_midi_map)[2].contains(n_pos)) // D | |||
else if (fMidiMap[2].contains(keyPos)) // D | |||
note = 2; | |||
else if ((*m_midi_map)[4].contains(n_pos)) // E | |||
else if (fMidiMap[4].contains(keyPos)) // E | |||
note = 4; | |||
else if ((*m_midi_map)[5].contains(n_pos)) // F | |||
else if (fMidiMap[5].contains(keyPos)) // F | |||
note = 5; | |||
else if ((*m_midi_map)[7].contains(n_pos)) // G | |||
else if (fMidiMap[7].contains(keyPos)) // G | |||
note = 7; | |||
else if ((*m_midi_map)[9].contains(n_pos)) // A | |||
else if (fMidiMap[9].contains(keyPos)) // A | |||
note = 9; | |||
else if ((*m_midi_map)[11].contains(n_pos))// B | |||
else if (fMidiMap[11].contains(keyPos))// B | |||
note = 11; | |||
else | |||
note = -1; | |||
@@ -276,16 +266,17 @@ void PixmapKeyboard::handleMousePos(const QPoint& pos) | |||
if (note != -1) | |||
{ | |||
note += octave * 12; | |||
if (m_lastMouseNote != note) | |||
if (fLastMouseNote != note) | |||
{ | |||
sendNoteOff(m_lastMouseNote); | |||
sendNoteOff(fLastMouseNote); | |||
sendNoteOn(note); | |||
} | |||
} | |||
else | |||
sendNoteOff(m_lastMouseNote); | |||
else if (fLastMouseNote != -1) | |||
sendNoteOff(fLastMouseNote); | |||
m_lastMouseNote = note; | |||
fLastMouseNote = note; | |||
} | |||
void PixmapKeyboard::keyPressEvent(QKeyEvent* event) | |||
@@ -293,8 +284,9 @@ void PixmapKeyboard::keyPressEvent(QKeyEvent* event) | |||
if (! event->isAutoRepeat()) | |||
{ | |||
int qKey = event->key(); | |||
if (midi_keyboard2key_map.keys().contains(qKey)) | |||
sendNoteOn(midi_keyboard2key_map[qKey]); | |||
std::map<int, int>::const_iterator it = kMidiKeyboard2KeyMap.find(qKey); | |||
if (it != kMidiKeyboard2KeyMap.end()) | |||
sendNoteOn(it->second); | |||
} | |||
QWidget::keyPressEvent(event); | |||
} | |||
@@ -304,15 +296,16 @@ void PixmapKeyboard::keyReleaseEvent(QKeyEvent* event) | |||
if (! event->isAutoRepeat()) | |||
{ | |||
int qKey = event->key(); | |||
if (midi_keyboard2key_map.keys().contains(qKey)) | |||
sendNoteOff(midi_keyboard2key_map[qKey]); | |||
std::map<int, int>::const_iterator it = kMidiKeyboard2KeyMap.find(qKey); | |||
if (it != kMidiKeyboard2KeyMap.end()) | |||
sendNoteOff(it->second); | |||
} | |||
QWidget::keyReleaseEvent(event); | |||
} | |||
void PixmapKeyboard::mousePressEvent(QMouseEvent* event) | |||
{ | |||
m_lastMouseNote = -1; | |||
fLastMouseNote = -1; | |||
handleMousePos(event->pos()); | |||
setFocus(); | |||
QWidget::mousePressEvent(event); | |||
@@ -326,34 +319,35 @@ void PixmapKeyboard::mouseMoveEvent(QMouseEvent* event) | |||
void PixmapKeyboard::mouseReleaseEvent(QMouseEvent* event) | |||
{ | |||
if (m_lastMouseNote != -1) | |||
if (fLastMouseNote != -1) | |||
{ | |||
sendNoteOff(m_lastMouseNote); | |||
m_lastMouseNote = -1; | |||
sendNoteOff(fLastMouseNote); | |||
fLastMouseNote = -1; | |||
} | |||
QWidget::mouseReleaseEvent(event); | |||
} | |||
void PixmapKeyboard::paintEvent(QPaintEvent*) | |||
void PixmapKeyboard::paintEvent(QPaintEvent* event) | |||
{ | |||
QPainter painter(this); | |||
event->accept(); | |||
// ------------------------------------------------------------- | |||
// Paint clean keys (as background) | |||
for (int octave=0; octave < m_octaves; octave++) | |||
for (int octave=0; octave < fOctaves; octave++) | |||
{ | |||
QRectF target; | |||
if (m_pixmap_mode == HORIZONTAL) | |||
target = QRectF(p_width * octave, 0, p_width, p_height); | |||
else if (m_pixmap_mode == VERTICAL) | |||
target = QRectF(0, p_height * octave, p_width, p_height); | |||
if (fPixmapMode == HORIZONTAL) | |||
target = QRectF(fWidth * octave, 0, fWidth, fHeight); | |||
else if (fPixmapMode == VERTICAL) | |||
target = QRectF(0, fHeight * octave, fWidth, fHeight); | |||
else | |||
return; | |||
QRectF source = QRectF(0, 0, p_width, p_height); | |||
painter.drawPixmap(target, m_pixmap, source); | |||
QRectF source = QRectF(0, 0, fWidth, fHeight); | |||
painter.drawPixmap(target, fPixmap, source); | |||
} | |||
// ------------------------------------------------------------- | |||
@@ -361,10 +355,10 @@ void PixmapKeyboard::paintEvent(QPaintEvent*) | |||
bool paintedWhite = false; | |||
for (int i=0; i < m_enabledKeys.count(); i++) | |||
for (int i=0, count=fEnabledKeys.count(); i < count; i++) | |||
{ | |||
int octave, note = m_enabledKeys[i]; | |||
QRectF pos = _getRectFromMidiNote(note); | |||
int octave, note = fEnabledKeys[i]; | |||
const QRectF& pos(_getRectFromMidiNote(note)); | |||
if (_isNoteBlack(note)) | |||
continue; | |||
@@ -384,30 +378,34 @@ void PixmapKeyboard::paintEvent(QPaintEvent*) | |||
octave = 4; | |||
else if (note < 108) | |||
octave = 5; | |||
else if (note < 120) | |||
octave = 6; | |||
else if (note < 132) | |||
octave = 7; | |||
else | |||
// cannot paint this note either | |||
continue; | |||
if (m_pixmap_mode == VERTICAL) | |||
octave = m_octaves - octave - 1; | |||
if (fPixmapMode == VERTICAL) | |||
octave = fOctaves - octave - 1; | |||
QRectF target, source; | |||
if (m_pixmap_mode == HORIZONTAL) | |||
if (fPixmapMode == HORIZONTAL) | |||
{ | |||
target = QRectF(pos.x() + (p_width * octave), 0, pos.width(), pos.height()); | |||
source = QRectF(pos.x(), p_height, pos.width(), pos.height()); | |||
target = QRectF(pos.x() + (fWidth * octave), 0, pos.width(), pos.height()); | |||
source = QRectF(pos.x(), fHeight, pos.width(), pos.height()); | |||
} | |||
else if (m_pixmap_mode == VERTICAL) | |||
else if (fPixmapMode == VERTICAL) | |||
{ | |||
target = QRectF(pos.x(), pos.y() + (p_height * octave), pos.width(), pos.height()); | |||
source = QRectF(p_width, pos.y(), pos.width(), pos.height()); | |||
target = QRectF(pos.x(), pos.y() + (fHeight * octave), pos.width(), pos.height()); | |||
source = QRectF(fWidth, pos.y(), pos.width(), pos.height()); | |||
} | |||
else | |||
return; | |||
paintedWhite = true; | |||
painter.drawPixmap(target, m_pixmap, source); | |||
painter.drawPixmap(target, fPixmap, source); | |||
} | |||
// ------------------------------------------------------------- | |||
@@ -415,26 +413,27 @@ void PixmapKeyboard::paintEvent(QPaintEvent*) | |||
if (paintedWhite) | |||
{ | |||
for (int octave=0; octave < m_octaves; octave++) | |||
for (int octave=0; octave < fOctaves; octave++) | |||
{ | |||
foreach (int note, blackNotes) | |||
foreach (int note, kBlackNotes) | |||
{ | |||
QRectF target, source; | |||
QRectF pos = _getRectFromMidiNote(note); | |||
if (m_pixmap_mode == HORIZONTAL) | |||
const QRectF& pos(_getRectFromMidiNote(note)); | |||
if (fPixmapMode == HORIZONTAL) | |||
{ | |||
target = QRectF(pos.x() + (p_width * octave), 0, pos.width(), pos.height()); | |||
target = QRectF(pos.x() + (fWidth * octave), 0, pos.width(), pos.height()); | |||
source = QRectF(pos.x(), 0, pos.width(), pos.height()); | |||
} | |||
else if (m_pixmap_mode == VERTICAL) | |||
else if (fPixmapMode == VERTICAL) | |||
{ | |||
target = QRectF(pos.x(), pos.y() + (p_height * octave), pos.width(), pos.height()); | |||
target = QRectF(pos.x(), pos.y() + (fHeight * octave), pos.width(), pos.height()); | |||
source = QRectF(0, pos.y(), pos.width(), pos.height()); | |||
} | |||
else | |||
return; | |||
painter.drawPixmap(target, m_pixmap, source); | |||
painter.drawPixmap(target, fPixmap, source); | |||
} | |||
} | |||
} | |||
@@ -442,10 +441,10 @@ void PixmapKeyboard::paintEvent(QPaintEvent*) | |||
// ------------------------------------------------------------- | |||
// Paint (black) pressed keys | |||
for (int i=0; i < m_enabledKeys.count(); i++) | |||
for (int i=0, count=fEnabledKeys.count(); i < count; i++) | |||
{ | |||
int octave, note = m_enabledKeys[i]; | |||
QRectF pos = _getRectFromMidiNote(note); | |||
int octave, note = fEnabledKeys[i]; | |||
const QRectF& pos(_getRectFromMidiNote(note)); | |||
if (! _isNoteBlack(note)) | |||
continue; | |||
@@ -465,60 +464,64 @@ void PixmapKeyboard::paintEvent(QPaintEvent*) | |||
octave = 4; | |||
else if (note < 108) | |||
octave = 5; | |||
else if (note < 120) | |||
octave = 6; | |||
else if (note < 132) | |||
octave = 7; | |||
else | |||
// cannot paint this note either | |||
continue; | |||
if (m_pixmap_mode == VERTICAL) | |||
octave = m_octaves - octave - 1; | |||
if (fPixmapMode == VERTICAL) | |||
octave = fOctaves - octave - 1; | |||
QRectF target, source; | |||
if (m_pixmap_mode == HORIZONTAL) | |||
if (fPixmapMode == HORIZONTAL) | |||
{ | |||
target = QRectF(pos.x() + (p_width * octave), 0, pos.width(), pos.height()); | |||
source = QRectF(pos.x(), p_height, pos.width(), pos.height()); | |||
target = QRectF(pos.x() + (fWidth * octave), 0, pos.width(), pos.height()); | |||
source = QRectF(pos.x(), fHeight, pos.width(), pos.height()); | |||
} | |||
else if (m_pixmap_mode == VERTICAL) | |||
else if (fPixmapMode == VERTICAL) | |||
{ | |||
target = QRectF(pos.x(), pos.y() + (p_height * octave), pos.width(), pos.height()); | |||
source = QRectF(p_width, pos.y(), pos.width(), pos.height()); | |||
target = QRectF(pos.x(), pos.y() + (fHeight * octave), pos.width(), pos.height()); | |||
source = QRectF(fWidth, pos.y(), pos.width(), pos.height()); | |||
} | |||
else | |||
return; | |||
painter.drawPixmap(target, m_pixmap, source); | |||
painter.drawPixmap(target, fPixmap, source); | |||
} | |||
// Paint C-number note info | |||
painter.setFont(m_font); | |||
painter.setFont(fFont); | |||
painter.setPen(Qt::black); | |||
for (int i=0; i < m_octaves; i++) | |||
for (int i=0; i < fOctaves; i++) | |||
{ | |||
if (m_pixmap_mode == HORIZONTAL) | |||
if (fPixmapMode == HORIZONTAL) | |||
painter.drawText(i * 144, 48, 18, 18, Qt::AlignCenter, QString("C%1").arg(i + 2)); | |||
else if (m_pixmap_mode == VERTICAL) | |||
painter.drawText(45, (m_octaves * 144) - (i * 144) - 16, 18, 18, Qt::AlignCenter, QString("C%1").arg(i + 2)); | |||
else if (fPixmapMode == VERTICAL) | |||
painter.drawText(45, (fOctaves * 144) - (i * 144) - 16, 18, 18, Qt::AlignCenter, QString("C%1").arg(i + 2)); | |||
} | |||
} | |||
void PixmapKeyboard::updateOnce() | |||
{ | |||
if (m_needsUpdate) | |||
if (fNeedsUpdate) | |||
{ | |||
update(); | |||
m_needsUpdate = false; | |||
fNeedsUpdate = false; | |||
} | |||
} | |||
bool PixmapKeyboard::_isNoteBlack(int note) | |||
bool PixmapKeyboard::_isNoteBlack(int note) const | |||
{ | |||
int baseNote = note % 12; | |||
return blackNotes.contains(baseNote); | |||
return kBlackNotes.contains(baseNote); | |||
} | |||
QRectF PixmapKeyboard::_getRectFromMidiNote(int note) | |||
const QRectF& PixmapKeyboard::_getRectFromMidiNote(int note) const | |||
{ | |||
return (*m_midi_map)[note % 12]; | |||
return fMidiMap[note % 12]; | |||
} |
@@ -18,6 +18,7 @@ | |||
#ifndef __PIXMAPKEYBOARD_HPP__ | |||
#define __PIXMAPKEYBOARD_HPP__ | |||
#include <map> | |||
#include <QtGui/QPixmap> | |||
#include <QtGui/QWidget> | |||
@@ -64,22 +65,23 @@ private Q_SLOTS: | |||
void updateOnce(); | |||
private: | |||
QPixmap m_pixmap; | |||
Orientation m_pixmap_mode; | |||
QPixmap fPixmap; | |||
Orientation fPixmapMode; | |||
QString m_colorStr; | |||
QFont m_font; | |||
QString fColorStr; | |||
QFont fFont; | |||
int m_octaves; | |||
int m_lastMouseNote; | |||
int p_width, p_height; | |||
int fOctaves; | |||
int fLastMouseNote; | |||
int fWidth; | |||
int fHeight; | |||
bool m_needsUpdate; | |||
QList<int> m_enabledKeys; | |||
QMap<int, QRectF> *m_midi_map; | |||
bool fNeedsUpdate; | |||
QList<int> fEnabledKeys; | |||
std::map<int, QRectF>& fMidiMap; | |||
bool _isNoteBlack(int note); | |||
QRectF _getRectFromMidiNote(int note); | |||
bool _isNoteBlack(int note) const; | |||
const QRectF& _getRectFromMidiNote(int note) const; | |||
}; | |||
#endif // __PIXMAPKEYBOARD_HPP__ |
@@ -24,7 +24,7 @@ from PyQt4.QtGui import QFont, QPainter, QPixmap, QWidget | |||
# ------------------------------------------------------------------------------------------------------------ | |||
midi_key2rect_map_horizontal = { | |||
kMidiKey2RectMapHorizontal = { | |||
'0': QRectF(0, 0, 18, 64), # C | |||
'1': QRectF(13, 0, 11, 42), # C# | |||
'2': QRectF(18, 0, 25, 64), # D | |||
@@ -39,7 +39,7 @@ midi_key2rect_map_horizontal = { | |||
'11': QRectF(126, 0, 18, 64) # B | |||
} | |||
midi_key2rect_map_vertical = { | |||
kMidiKey2RectMapVertical = { | |||
'11': QRectF(0, 0, 64, 18), # B | |||
'10': QRectF(0, 14, 42, 7), # A# | |||
'9': QRectF(0, 18, 64, 24), # A | |||
@@ -54,7 +54,7 @@ midi_key2rect_map_vertical = { | |||
'0': QRectF(0, 126, 64, 18) # C | |||
} | |||
midi_keyboard2key_map = { | |||
kMidiKeyboard2KeyMap = { | |||
# 3th octave | |||
'%i' % Qt.Key_Z: 48, | |||
'%i' % Qt.Key_S: 49, | |||
@@ -81,7 +81,9 @@ midi_keyboard2key_map = { | |||
'%i' % Qt.Key_Y: 69, | |||
'%i' % Qt.Key_7: 70, | |||
'%i' % Qt.Key_U: 71, | |||
} | |||
} | |||
kBlackNotes = (1, 3, 6, 8, 10) | |||
# ------------------------------------------------------------------------------------------------------------ | |||
# MIDI Keyboard, using a pixmap for painting | |||
@@ -112,15 +114,15 @@ class PixmapKeyboard(QWidget): | |||
def allNotesOff(self): | |||
self.fEnabledKeys = [] | |||
self.fNeedsUpdate = True | |||
QTimer.singleShot(0, self, SLOT("slot_updateOnce()")) | |||
self.emit(SIGNAL("notesOff()")) | |||
QTimer.singleShot(0, self, SLOT("slot_updateOnce()")) | |||
def sendNoteOn(self, note, sendSignal=True): | |||
if 0 <= note <= 127 and note not in self.fEnabledKeys: | |||
self.fEnabledKeys.append(note) | |||
if sendSignal: | |||
self.emit(SIGNAL("noteOn(int)"), note) | |||
@@ -133,6 +135,7 @@ class PixmapKeyboard(QWidget): | |||
def sendNoteOff(self, note, sendSignal=True): | |||
if 0 <= note <= 127 and note in self.fEnabledKeys: | |||
self.fEnabledKeys.remove(note) | |||
if sendSignal: | |||
self.emit(SIGNAL("noteOff(int)"), note) | |||
@@ -152,13 +155,13 @@ class PixmapKeyboard(QWidget): | |||
return self.setMode(mode) | |||
if mode == self.HORIZONTAL: | |||
self.fMidiMap = midi_key2rect_map_horizontal | |||
self.fMidiMap = kMidiKey2RectMapHorizontal | |||
self.fPixmap.load(":/bitmaps/kbd_h_%s.png" % self.fColorStr) | |||
self.fPixmapMode = self.HORIZONTAL | |||
self.fWidth = self.fPixmap.width() | |||
self.fHeight = self.fPixmap.height() / 2 | |||
elif mode == self.VERTICAL: | |||
self.fMidiMap = midi_key2rect_map_vertical | |||
self.fMidiMap = kMidiKey2RectMapVertical | |||
self.fPixmap.load(":/bitmaps/kbd_v_%s.png" % self.fColorStr) | |||
self.fPixmapMode = self.VERTICAL | |||
self.fWidth = self.fPixmap.width() / 2 | |||
@@ -174,6 +177,7 @@ class PixmapKeyboard(QWidget): | |||
octaves = 1 | |||
elif octaves > 8: | |||
octaves = 8 | |||
self.fOctaves = octaves | |||
if self.fPixmapMode == self.HORIZONTAL: | |||
@@ -189,53 +193,55 @@ class PixmapKeyboard(QWidget): | |||
if self.fPixmapMode == self.HORIZONTAL: | |||
if pos.x() < 0 or pos.x() > self.fOctaves * 144: | |||
return | |||
posX = pos.x() - 1 | |||
posX = pos.x() - 1 | |||
octave = int(posX / self.fWidth) | |||
n_pos = QPointF(posX % self.fWidth, pos.y()) | |||
keyPos = QPointF(posX % self.fWidth, pos.y()) | |||
elif self.fPixmapMode == self.VERTICAL: | |||
if pos.y() < 0 or pos.y() > self.fOctaves * 144: | |||
return | |||
posY = pos.y() - 1 | |||
posY = pos.y() - 1 | |||
octave = int(self.fOctaves - posY / self.fHeight) | |||
n_pos = QPointF(pos.x(), posY % self.fHeight) | |||
keyPos = QPointF(pos.x(), posY % self.fHeight) | |||
else: | |||
return | |||
octave += 3 | |||
if self.fMidiMap['1'].contains(n_pos): # C# | |||
if self.fMidiMap['1'].contains(keyPos): # C# | |||
note = 1 | |||
elif self.fMidiMap['3'].contains(n_pos): # D# | |||
elif self.fMidiMap['3'].contains(keyPos): # D# | |||
note = 3 | |||
elif self.fMidiMap['6'].contains(n_pos): # F# | |||
elif self.fMidiMap['6'].contains(keyPos): # F# | |||
note = 6 | |||
elif self.fMidiMap['8'].contains(n_pos): # G# | |||
elif self.fMidiMap['8'].contains(keyPos): # G# | |||
note = 8 | |||
elif self.fMidiMap['10'].contains(n_pos):# A# | |||
elif self.fMidiMap['10'].contains(keyPos):# A# | |||
note = 10 | |||
elif self.fMidiMap['0'].contains(n_pos): # C | |||
elif self.fMidiMap['0'].contains(keyPos): # C | |||
note = 0 | |||
elif self.fMidiMap['2'].contains(n_pos): # D | |||
elif self.fMidiMap['2'].contains(keyPos): # D | |||
note = 2 | |||
elif self.fMidiMap['4'].contains(n_pos): # E | |||
elif self.fMidiMap['4'].contains(keyPos): # E | |||
note = 4 | |||
elif self.fMidiMap['5'].contains(n_pos): # F | |||
elif self.fMidiMap['5'].contains(keyPos): # F | |||
note = 5 | |||
elif self.fMidiMap['7'].contains(n_pos): # G | |||
elif self.fMidiMap['7'].contains(keyPos): # G | |||
note = 7 | |||
elif self.fMidiMap['9'].contains(n_pos): # A | |||
elif self.fMidiMap['9'].contains(keyPos): # A | |||
note = 9 | |||
elif self.fMidiMap['11'].contains(n_pos):# B | |||
elif self.fMidiMap['11'].contains(keyPos):# B | |||
note = 11 | |||
else: | |||
note = -1 | |||
if note != -1: | |||
note += octave * 12 | |||
if self.fLastMouseNote != note: | |||
self.sendNoteOff(self.fLastMouseNote) | |||
self.sendNoteOn(note) | |||
else: | |||
elif self.fLastMouseNote != -1: | |||
self.sendNoteOff(self.fLastMouseNote) | |||
self.fLastMouseNote = note | |||
@@ -243,15 +249,15 @@ class PixmapKeyboard(QWidget): | |||
def keyPressEvent(self, event): | |||
if not event.isAutoRepeat(): | |||
qKey = str(event.key()) | |||
if qKey in midi_keyboard2key_map.keys(): | |||
self.sendNoteOn(midi_keyboard2key_map.get(qKey)) | |||
if qKey in kMidiKeyboard2KeyMap.keys(): | |||
self.sendNoteOn(kMidiKeyboard2KeyMap.get(qKey)) | |||
QWidget.keyPressEvent(self, event) | |||
def keyReleaseEvent(self, event): | |||
if not event.isAutoRepeat(): | |||
qKey = str(event.key()) | |||
if qKey in midi_keyboard2key_map.keys(): | |||
self.sendNoteOff(midi_keyboard2key_map.get(qKey)) | |||
if qKey in kMidiKeyboard2KeyMap.keys(): | |||
self.sendNoteOff(kMidiKeyboard2KeyMap.get(qKey)) | |||
QWidget.keyReleaseEvent(self, event) | |||
def mousePressEvent(self, event): | |||
@@ -295,7 +301,7 @@ class PixmapKeyboard(QWidget): | |||
for i in range(len(self.fEnabledKeys)): | |||
note = self.fEnabledKeys[i] | |||
pos = self._getRectFromMidiNote(note) | |||
pos = self._getRectFromMidiNote(note) | |||
if self._isNoteBlack(note): | |||
continue | |||
@@ -343,8 +349,9 @@ class PixmapKeyboard(QWidget): | |||
if paintedWhite: | |||
for octave in range(self.fOctaves): | |||
for note in (1, 3, 6, 8, 10): | |||
for note in kBlackNotes: | |||
pos = self._getRectFromMidiNote(note) | |||
if self.fPixmapMode == self.HORIZONTAL: | |||
target = QRectF(pos.x() + (self.fWidth * octave), 0, pos.width(), pos.height()) | |||
source = QRectF(pos.x(), 0, pos.width(), pos.height()) | |||
@@ -361,7 +368,7 @@ class PixmapKeyboard(QWidget): | |||
for i in range(len(self.fEnabledKeys)): | |||
note = self.fEnabledKeys[i] | |||
pos = self._getRectFromMidiNote(note) | |||
pos = self._getRectFromMidiNote(note) | |||
if not self._isNoteBlack(note): | |||
continue | |||
@@ -421,7 +428,7 @@ class PixmapKeyboard(QWidget): | |||
def _isNoteBlack(self, note): | |||
baseNote = note % 12 | |||
return bool(baseNote in (1, 3, 6, 8, 10)) | |||
return bool(baseNote in kBlackNotes) | |||
def _getRectFromMidiNote(self, note): | |||
return self.fMidiMap.get(str(note % 12)) |