Skip to content

Commit

Permalink
various, most importantly much faster graphics
Browse files Browse the repository at this point in the history
  • Loading branch information
kmatheussen committed Feb 8, 2013
1 parent d30a30f commit 4a21943
Show file tree
Hide file tree
Showing 19 changed files with 2,290 additions and 1,359 deletions.
63 changes: 54 additions & 9 deletions Makefile
Expand Up @@ -2,27 +2,38 @@ PREFIX ?= /usr/local
bindir ?= $(PREFIX)/bin
libdir ?= $(PREFIX)/lib

#FIX locally. Line below removed from dsp file.
#effect.bypass2(checkbox("[6] bypass"), compressor)

# These two commands are used by me, since most of the source files are stored in the Radium tree.
# You would normally just run "make" to compile the program.
#
# make copy_files && make all && ./radium_compressor
# make copy_files && rm -f benchmark && make benchmark && ./benchmark && ./benchmark && ./benchmark

OPT = -O3 -ffast-math
OPT_DSP = -O3 -ffast-math #-funroll-loops
CPP = g++ -DDEBUG -Wall -msse -mfpmath=sse -DUSE_QT_REQTYPE -DUSE_QT4 -g -I. -IQt
# -fpredictive-commoning -ftree-vectorize
# -funroll-loops -fira-loop-pressure -fipa-cp-clone -ftree-loop-distribute-patterns

CPP = g++ -DDEBUG -O3 -Wall -msse -mfpmath=sse -DUSE_QT_REQTYPE -DUSE_QT4 -g -I. -ffast-math -IQt
#-finline-functions

#FAUST = /home/kjetil/faudiostream/compiler/faust -vec
FAUST = faust -vec
FAUST = /home/kjetil/faudiostream/compiler/faust -vec
#FAUST = faust -vec

# only used for copy files
RADIUM_PATH = /home/kjetil/radium-qt4

all: audio/system_compressor.cpp
all: system_compressor_wrapper.o myladspa.o
cd Qt && ./create_source_from_ui.sh `../find_moc_and_uic_paths.sh uic` `../find_moc_and_uic_paths.sh moc` compressor_widget
$(CPP) Qt/Qt_SliderPainter.cpp `pkg-config --cflags Qt3Support` -c
$(CPP) main.cpp Qt_SliderPainter.o -Iaudio/faudiostream/architecture/ `pkg-config --libs --cflags Qt3Support` -ljack -o radium_compressor
$(CPP) Qt/Qt_SliderPainter.cpp `pkg-config --cflags Qt3Support` -c $(OPT)
$(CPP) main.cpp Qt_SliderPainter.o system_compressor_wrapper.o myladspa.o -DCOMPILING_STANDALONE -Iaudio/faudiostream/architecture/ `pkg-config --libs --cflags Qt3Support` -ljack -o radium_compressor $(OPT)
# /usr/lib64/libprofiler.so.0
# make copy_files && make all && CPUPROFILE=ls.prof ./radium_compressor

clean:
rm -f *.o

install:
install -d $(DESTDIR)$(bindir)
Expand All @@ -32,9 +43,33 @@ install:
uninstall:
rm -f $(DESTDIR)$(bindir)/radium_compressor

# ladpa plugin
radium_compressor.so: audio/system_compressor.cpp myladspa.o system_compressor_wrapper_ladspa.o
$(CPP) Qt/Qt_SliderPainter.cpp `pkg-config --cflags Qt3Support` -c -fPIC $(OPT)
$(CPP) -DCOMPILING_LADSPA main.cpp -Iaudio/faudiostream/architecture/ `pkg-config --libs --cflags Qt3Support` -c -fPIC $(OPT)
$(CPP) `pkg-config --libs Qt3Support` myladspa.o system_compressor_wrapper_ladspa.o -shared -fPIC -o radium_compressor.so

system_compressor_wrapper.o: audio/system_compressor_wrapper.cpp audio/system_compressor.cpp
$(CPP) -Ifaudiostream/architecture `pkg-config --cflags QtCore` -DCOMPILING_STANDALONE audio/system_compressor_wrapper.cpp -c -fPIC $(OPT_DSP)

system_compressor_wrapper_ladspa.o: audio/system_compressor_wrapper.cpp audio/system_compressor.cpp
$(CPP) -Ifaudiostream/architecture `pkg-config --cflags QtCore` -DCOMPILING_LADSPA audio/system_compressor_wrapper.cpp -c -fPIC -o system_compressor_wrapper_ladspa.o $(OPT_DSP)

myladspa.o: myladspa.cpp audio/system_compressor.cpp
$(CPP) -DCOMPILING_LADSPA -Ifaudiostream/architecture `pkg-config --cflags QtCore` myladspa.cpp -fPIC -c $(OPT_DSP)

audio/system_compressor.cpp: audio/system_compressor.dsp standalone_compressor.dsp
cp standalone_compressor.dsp audio/
$(FAUST) -cn Faust_system_compressor audio/standalone_compressor.dsp >audio/system_compressor.cpp

#audio/system_compressor_ladspa.cpp: audio/system_compressor.dsp standalone_compressor.dsp
# cp standalone_compressor.dsp audio/
# $(FAUST) -cn Faust_system_compressor -a myladspa.cpp audio/standalone_compressor.dsp >audio/system_compressor_ladspa.cpp


copy_files:
cp $(RADIUM_PATH)/Qt/qt4_compressor_widget.ui Qt/
cp $(RADIUM_PATH)/Qt/compressor_vertical_sliders.cpp Qt/
cp $(RADIUM_PATH)/Qt/Qt_compressor_widget_callbacks.h Qt/
cp $(RADIUM_PATH)/Qt/Qt_MyQCheckBox.h Qt/
cp $(RADIUM_PATH)/Qt/Qt_MyQButton.h Qt/
Expand All @@ -47,6 +82,9 @@ copy_files:
cp $(RADIUM_PATH)/Qt/Qt_instruments_proc.h Qt/

cp $(RADIUM_PATH)/audio/system_compressor.dsp audio/
cp $(RADIUM_PATH)/audio/fast_log_exp.dsp audio/
cp $(RADIUM_PATH)/audio/system_compressor_wrapper_proc.h audio/
cp $(RADIUM_PATH)/audio/system_compressor_wrapper.cpp audio/
cp $(RADIUM_PATH)/audio/typepunning.h audio/
cp $(RADIUM_PATH)/audio/undo_audio_effect_proc.h audio/
cp $(RADIUM_PATH)/audio/SoundPlugin.h audio/
Expand Down Expand Up @@ -75,9 +113,6 @@ copy_files:
cp -a $(RADIUM_PATH)/audio/faudiostream audio/


audio/system_compressor.cpp: audio/system_compressor.dsp
$(FAUST) audio/system_compressor.dsp >audio/system_compressor.cpp

# Note that 0.9.55 runs the benchmark program a bit faster than 0.9.46.
# I guess it's because of more min/max functions in 0.9.55, but it could also
# be because of some castings.
Expand All @@ -94,3 +129,13 @@ benchmark:
# Relative accuracy of faster pow2 / faster log: 0.0152579 / 0.0130367
# Relative accuracy of fast pow2 / fast log: 1.58868e-05 / 2.09348e-05

#/home/kjetil/faudiostream/compiler/faust -a ladspa.cpp system_compressor.dsp >ladspa_compressor.cpp
#g++ ladspa_compressor.cpp -I /home/kjetil/faudiostream/architecture/ -shared -fPIC -o ladspa_compressor.so

VSTPATH = /home/kjetil/Dropbox/radium_build/vstsdk2.4
vst:
$(FAUST) audio/standalone_compressor.dsp >compressor_vst.cpp
$(CPP) Qt/Qt_SliderPainter.cpp `pkg-config --cflags Qt3Support` -c -fPIC
$(CPP) -DCOMPILING_VST main.cpp -Iaudio/faudiostream/architecture/ `pkg-config --libs --cflags Qt3Support` -c -fPIC
$(CPP) -I $(VSTPATH)/public.sdk/source/vst2.x/ -I $(VSTPATH)/pluginterfaces/vst2.x/ -I $(VSTPATH) `pkg-config --cflags QtGui` `pkg-config --libs QtGui` vstplugin.cpp -Iaudio $(VSTPATH)/public.sdk/source/vst2.x/audioeffectx.cpp $(VSTPATH)/public.sdk/source/vst2.x/audioeffect.cpp $(VSTPATH)/public.sdk/source/vst2.x/vstplugmain.cpp main.o Qt_SliderPainter.o -shared -o radium_compressor.so -fPIC

34 changes: 29 additions & 5 deletions Qt/Qt_MyQCheckBox.h
Expand Up @@ -53,6 +53,11 @@ static QColor mix_colors(const QColor &c1, const QColor &c2, float how_much){
}
}

static int get_text_width(QString text){
const QFontMetrics fn = QFontMetrics(QFont());
return fn.width(text);
}

inline static void CHECKBOX_paint(QPainter *painter, bool is_checked, bool is_enabled, int width, int height, QString text){
#ifdef COMPILING_RADIUM
QColor *colors = static_cast<EditorWidget*>(root->song->tracker_windows->os_visual.widget)->colors;
Expand Down Expand Up @@ -101,10 +106,22 @@ inline static void CHECKBOX_paint(QPainter *painter, bool is_checked, bool is_en
else
black.setAlpha(120);
painter->setPen(black);

if(text=="Loop")
painter->drawText(rect, Qt::AlignCenter, text + " " + QChar(8634));
else
text = text + " " + QChar(8634);

if(height>width){
painter->save();
painter->translate(0,0);
painter->rotate(90);
int text_width = get_text_width(text);
int pos = (height-text_width)/2;
painter->drawText(pos,-5, text);
painter->restore();
}else{
painter->drawText(rect, Qt::AlignCenter, text);
}

}
}

Expand All @@ -114,6 +131,8 @@ struct MyQCheckBox : public QCheckBox{
int _effect_num;
bool _undo_patchvoice;

QString vertical_text;

void init(){
_has_mouse=false;
_patch = NULL;
Expand All @@ -124,7 +143,6 @@ struct MyQCheckBox : public QCheckBox{
MyQCheckBox ( QWidget * parent = 0 ) : QCheckBox(parent) {init();}
MyQCheckBox ( const QString & text, QWidget * parent = 0) : QCheckBox(text,parent) {init();}


void mousePressEvent ( QMouseEvent * event )
{
if (event->button() == Qt::LeftButton){
Expand All @@ -137,7 +155,7 @@ struct MyQCheckBox : public QCheckBox{
#endif
//handle_mouse_event(event);
_has_mouse = true;
printf("Got it %p %d\n",_patch,_effect_num);
printf("Got it %p %d. Checked: %d\n",_patch,_effect_num,!isChecked());
setChecked(!isChecked());
}else
QCheckBox::mousePressEvent(event);
Expand All @@ -146,7 +164,13 @@ struct MyQCheckBox : public QCheckBox{

void paintEvent ( QPaintEvent * ev ){
QPainter p(this);
CHECKBOX_paint(&p, isChecked(), isEnabled(), width(), height(), text());

if(text().startsWith("V ")){
vertical_text = text().right(text().size()-2);
setText("");
}

CHECKBOX_paint(&p, isChecked(), isEnabled(), width(), height(), vertical_text!="" ? vertical_text : text());
}
};

Expand Down
146 changes: 11 additions & 135 deletions Qt/Qt_SliderPainter.cpp
Expand Up @@ -27,18 +27,13 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */

#include "Qt_SliderPainter_proc.h"

#include "Qt_SliderPainterPainter.h"

const int k_timer_interval = 50;

#ifdef COMPILING_RADIUM
extern struct Root *root;
#else
extern QColor *g_colors;
#endif

const int k_timer_interval = 50;


static int scale(int x, int x1, int x2, int y1, int y2){
static int scale_int(int x, int x1, int x2, int y1, int y2){
return (int)scale((float)x,(float)x1,(float)x2,(float)y1,(float)y2);
}

Expand Down Expand Up @@ -92,27 +87,6 @@ static float iec_scale(float db) {
#endif


static QColor mix_colors(const QColor &c1, const QColor &c2, float how_much){

float a1 = how_much;
float a2 = 1.0f-a1;

if(c1.red()==0 && c1.green()==0 && c1.blue()==0){ // some of the black lines doesn't look look very good.
int r = 74*a1 + c2.red()*a2;
int g = 74*a1 + c2.green()*a2;
int b = 74*a1 + c2.blue()*a2;

return QColor(r,g,b);
}else{

int r = c1.red()*a1 + c2.red()*a2;
int g = c1.green()*a1 + c2.green()*a2;
int b = c1.blue()*a1 + c2.blue()*a2;

return QColor(r,g,b);
}
}



#define MAX_CHANNELS 8
Expand All @@ -135,11 +109,11 @@ struct AutomationOrPeakData{
}

static int DATA_get_y1(AutomationOrPeakData *data, int height){
return scale(data->ch,0,data->num_ch,1,height-1);
return scale_int(data->ch,0,data->num_ch,1,height-1);
}

static int DATA_get_y2(AutomationOrPeakData *data, int height){
return scale(data->ch+1,0,data->num_ch,1,height-1);
return scale_int(data->ch+1,0,data->num_ch,1,height-1);
}

struct SliderPainter{
Expand Down Expand Up @@ -200,7 +174,7 @@ struct SliderPainter{
}
}; // struct Timer

std::vector<AutomationOrPeakData*> _data;
std::vector<AutomationOrPeakData*>_data;

QSlider *_qslider;
QGraphicsItem *_graphics_item; // Either widget or _graphics_item must be set.
Expand Down Expand Up @@ -415,89 +389,11 @@ struct SliderPainter{
QColor *colors = g_colors;
#endif

QColor col1;
QColor col1b;
QColor col2;

int col1num = 11;
int col2num = 9;
//int col1num = qrand() % 15;
//int col2num = qrand() % 15;

if(false && _qslider!=NULL){
if(isEnabled()){
QColor c1(70,70,33);
QColor c2(59,98,33);
col1 = mix_colors(c1,colors[col1num].light(90),0.5);
col1b = mix_colors(c2,col1,0.3);
///col2 = mix_colors(editor->colors[col2num],editor->colors[col1num],0.8).light(95);//.light(90);
col2 = colors[15];
}else{
col1 = colors[col1num].light(105);
col1b = col1;
col2 = colors[col2num].light(102);
}
}else{
if(isEnabled()){
QColor c(98,59,33);

int colnum = 8;
col1 = c.light(90);
col1b = colors[13].light(100);
//int colnum = 8;
//col1 = editor->colors[colnum].light(90);
//col1b = editor->colors[13].light(100);

col2 = colors[colnum];
}else{
//col1 = editor->colors[col1num].light(105);
col1 = mix_colors(colors[col1num], Qt::gray, 0.8f);
col1b = mix_colors(colors[col1num].light(110), Qt::gray, 0.8f);
col2 = mix_colors(colors[col2num], Qt::gray, 0.8f);
//col2 = editor->colors[col2num].light(102);
}

if(_alternative_color==true){
col1 = QColor(200,200,200);
col2 = QColor(100,100,100);
}

if(_qslider!=NULL){
col1.setAlpha(80);
col1b.setAlpha(100);
}else{
col1.setAlpha(120);
col1b.setAlpha(120);
}
col2.setAlpha(0);
}

if(orientation() == Qt::Vertical){
int pos=scale(value(),maximum(),minimum(),0,height());
p->fillRect(0,0,width(),height(),col2);
p->fillRect(0,pos,width(),height()-pos,col1);
}else{
int pos=scale(value(),minimum(),maximum(),0,width());
{
QLinearGradient gradient(0,0,width(),height()*3/4);
if(_qslider!=NULL){
//gradient.setColorAt(0,col1.light(90));
//gradient.setColorAt(1,col1.light(110));
gradient.setColorAt(0,col1.light(100));
gradient.setColorAt(1,col1b);
}else{
gradient.setColorAt(0,col1.light(150));
gradient.setColorAt(1,col1b);
}
p->setPen(QPen(QColor(Qt::gray).light(50),1));
p->setBrush(gradient);
//p->fillRect(0 ,0, pos ,height(),col1);
p->drawRect(0 ,0, pos, height());
p->setBrush(QBrush());
}
p->setPen(QPen(Qt::gray,1));
p->fillRect(pos ,0, width()-pos ,height(),col2);
}
SLIDERPAINTERPAINTER_paint(p,0,0,width(),height(),
isEnabled(),
scale(value(),minimum(),maximum(),0.0f,1.0f),
_display_string,
_alternative_color);

for(unsigned int i=0;i<_data.size();i++){
AutomationOrPeakData *data = _data.at(i);
Expand All @@ -509,32 +405,12 @@ struct SliderPainter{
2, height-1,
colors[*data->color]);

//p->setPen(editor->colors[2].dark(10));
p->setPen(QPen(colors[11].light(120),1));
p->drawRect(data->requested_pos, y1,
3, height);

data->last_drawn_pos = data->requested_pos;
}

if(1){
p->setPen(QPen(colors[11].light(110),1));
p->drawRect(0,0,width(),height());
}

QRect rect(5,2,width()-5,height()-2);

if(_display_string!=""){
QColor c(colors[1]);
if(isEnabled()){
c.setAlpha(160);
p->setPen(QPen(c,1));//editor->colors[2].darker(500));
}else{
c.setAlpha(60);
p->setPen(QPen(c,1));
}
p->drawText(rect, Qt::AlignLeft, _display_string);
}
}

};
Expand Down

0 comments on commit 4a21943

Please sign in to comment.