-Upgraded loop loading, now shows best stretch values for current BPM

This commit is contained in:
Harry van Haaren 2013-12-11 13:22:54 +00:00
parent 80f415e8db
commit 672429d916
2 changed files with 106 additions and 6 deletions

View file

@ -49,8 +49,17 @@ class Button : public Fl_Button
highlight = false;
mouseOver = false;
greyedOut = false;
}
void setGreyOut( bool g )
{
greyedOut = g;
}
bool greyedOut;
bool mouseOver;
bool highlight;
int x, y, w, h;
@ -95,13 +104,19 @@ class Button : public Fl_Button
cairo_save( cr );
cairo_rectangle( cr, x+1, y+1, w-2, h-2 );
if ( !greyedOut )
cairo_set_source_rgb( cr, _bgr, _bgg, _bgb );
else
{
float grey = (_bgr + _bgg + _bgb) / 3;
cairo_set_source_rgb( cr, grey, grey, grey );
}
cairo_fill_preserve(cr);
cairo_set_line_width(cr, 1.3);
cairo_rectangle( cr, x+1, y+1, w-2, h-2 );
if ( highlight )
if ( highlight && !greyedOut )
{
cairo_set_source_rgba(cr, _r, _g, _b, 0.4);
cairo_fill_preserve(cr);
@ -110,8 +125,16 @@ class Button : public Fl_Button
float alpha = 0.6;
if (mouseOver)
alpha = 1;
if ( !greyedOut )
cairo_set_source_rgba(cr, _r, _g, _b, alpha);
if ( highlight )
else
{
float grey = (_r + _g + _b) / 3;
cairo_set_source_rgb( cr, grey, grey, grey );
}
if ( highlight && !greyedOut )
cairo_set_line_width(cr, 2.2);
cairo_stroke(cr);

View file

@ -22,6 +22,8 @@
#include <sstream>
#include "config.hxx"
#include "gui.hxx"
extern Gui* gui;
#include "audiobuffer.hxx"
@ -84,11 +86,86 @@ void AudioEditor::show( AudioBuffer* buf, bool modal )
else
{
std::vector<float>& tmp = ab->getData();
waveform->setData( &tmp[0], tmp.size() );
int size = tmp.size();
waveform->setData( &tmp[0], size );
const int beats[]={1,2,4,8,16,32,64};
int iBeatOne = -1;
int iBeatTwo = -1;
// figure out BPM values from size
for( int i = 0; i < 7; i++ )
{
int beat = beats[i];
int fpb = size / beat;
int bpm = (gui->samplerate / fpb) * 60;
if ( bpm < 60 || bpm > 220 )
{
// disable option: not valid
beatButtons[i]->setGreyOut( true );
beatButtons[i]->setColor( 0.4, 0.4, 0.4 );
}
else
{
printf("%i, fpb = %i, bpm= = %i\n", beat, fpb, bpm );
// enable option ( may be disabled previously! )
beatButtons[i]->setGreyOut( false );
// remember this beat was a valid one, to check for best match
if ( iBeatOne == -1 )
iBeatOne = i;
else
iBeatTwo = i;
}
}
// both valid: compare, and adjust color
if ( iBeatOne != -1 && iBeatTwo != -1 )
{
int masterFpb = (gui->samplerate * 60) / gui->getMasterTrack()->getBpm();
int oneFpb = size / beats[iBeatOne];
int twoFpb = size / beats[iBeatTwo];
int oneDelta = masterFpb - oneFpb;
int twoDelta = masterFpb - twoFpb;
if ( oneDelta < 0 ) oneDelta = -oneDelta;
if ( twoDelta < 0 ) twoDelta = -twoDelta;
if ( oneDelta == twoDelta )
{
beatButtons[iBeatOne]->setColor( 0.0, 1.0, 0.0 );
beatButtons[iBeatTwo]->setColor( 0.0, 1.0, 0.0 );
}
else if ( oneDelta <= twoDelta )
{
// one is the better match
beatButtons[iBeatOne]->setColor( 0.0, 1.0, 0.0 );
beatButtons[iBeatTwo]->setColor( 1.0, 0.0, 0.0 );
}
else
{
beatButtons[iBeatTwo]->setColor( 0.0, 1.0, 0.0 );
beatButtons[iBeatOne]->setColor( 1.0, 0.0, 0.0 );
}
}
else if( iBeatOne != -1 && iBeatTwo == -1) // only one valid
{
beatButtons[iBeatOne]->setColor( 0.0, 1.0, 0.0 );
}
else
{
// no valid BPM range..?
}
}
window->set_modal();
window->show();
}