M/V split of Bit Invader

git-svn-id: https://lmms.svn.sf.net/svnroot/lmms/branches/lmms-mv@701 0778d3d1-df1d-0410-868b-ea421aaaa00d
This commit is contained in:
Paul Giblock
2008-02-24 10:59:17 +00:00
parent 98fc05e189
commit 922d2c5f38
8 changed files with 380 additions and 736 deletions

View File

@@ -11,7 +11,7 @@ AM_CXXFLAGS := $(AM_CXXFLAGS) $(QT_CXXFLAGS) -DPLUGIN_NAME="bitinvader"
$(MOC) -o $@ $<
MOC_FILES = ./bit_invader.moc ./graph.moc
MOC_FILES = ./bit_invader.moc
BUILT_SOURCES = $(MOC_FILES) ./embedded_resources.h
EMBEDDED_RESOURCES = $(wildcard *png)
@@ -28,6 +28,6 @@ CLEANFILES = $(MOC_FILES) ./embedded_resources.h
pkglib_LTLIBRARIES = libbitinvader.la
libbitinvader_la_SOURCES = bit_invader.cpp bit_invader.h graph.cpp graph.h
libbitinvader_la_SOURCES = bit_invader.cpp bit_invader.h
$(libbitinvader_la_SOURCES): ./embedded_resources.h

View File

@@ -43,6 +43,7 @@ using namespace std;
#include "song_editor.h"
#include "templates.h"
#include "tooltip.h"
#include "song.h"
#undef SINGLE_SOURCE_COMPILE
#include "embed.cpp"
@@ -65,8 +66,6 @@ plugin::descriptor bitinvader_plugin_descriptor =
}
QPixmap * bitInvader::s_artwork = NULL;
bSynth::bSynth( float * shape, int length, float _pitch, bool _interpolation,
float factor, const sample_rate_t _sample_rate )
@@ -113,19 +112,19 @@ sample_t bSynth::nextStringSample( void )
if (interpolation) {
// find position in shape
int a = static_cast<int>(sample_realindex);
int b;
if (a < (sample_length-1)) {
b = static_cast<int>(sample_realindex+1);
} else {
b = 0;
}
// Nachkommaanteil
float frac = sample_realindex - static_cast<int>(sample_realindex);
sample = sample_shape[a]*(1-frac) + sample_shape[b]*(frac);
// find position in shape
int a = static_cast<int>(sample_realindex);
int b;
if (a < (sample_length-1)) {
b = static_cast<int>(sample_realindex+1);
} else {
b = 0;
}
// Nachkommaanteil
float frac = sample_realindex - static_cast<int>(sample_realindex);
sample = sample_shape[a]*(1-frac) + sample_shape[b]*(frac);
} else {
// No interpolation
@@ -136,8 +135,6 @@ sample_t bSynth::nextStringSample( void )
// progress in shape
sample_realindex += sample_step;
// cout << sample_index << "\t";
return sample;
}
@@ -151,275 +148,25 @@ sample_t bSynth::nextStringSample( void )
bitInvader::bitInvader( instrumentTrack * _channel_track ) :
instrument( _channel_track,
&bitinvader_plugin_descriptor )
instrument( _channel_track, &bitinvader_plugin_descriptor ),
m_sampleLength( 128, 8, 128, 1, this ),
m_graph( -1.0f, 1.0f, 128, this ),
m_interpolation( FALSE, this ),
m_normalize( FALSE, this)
{
m_graph.setWaveToSine();
m_graph = NULL;
normalize = false;
interpolation = false;
if( s_artwork == NULL )
{
s_artwork = new QPixmap( PLUGIN_NAME::getIconPixmap(
"artwork" ) );
}
connect( &m_sampleLength, SIGNAL( dataChanged( ) ),
this, SLOT( lengthChanged( ) )
);
m_sampleLengthKnob = new knob( knobDark_28, this, tr( "Samplelength" ),
_channel_track );
m_sampleLengthKnob->setRange( 8, 128, 1 );
m_sampleLengthKnob->setInitValue( 128 );
m_sampleLengthKnob->move( 10, 120 );
m_sampleLengthKnob->setHintText( tr( "Sample Length" ) + " ", "" );
connect( m_sampleLengthKnob, SIGNAL( valueChanged( float ) ),
this, SLOT ( sampleSizeChanged( float ) )
);
m_interpolationToggle = new ledCheckBox( "Interpolation", this,
tr( "Interpolation" ),
_channel_track );
m_interpolationToggle->move( 55,80 );
connect( m_interpolationToggle, SIGNAL( toggled( bool ) ),
this, SLOT ( interpolationToggle( bool ) ) );
m_normalizeToggle = new ledCheckBox( "Normalize", this,
tr( "Normalize" ),
_channel_track );
m_normalizeToggle->move( 55, 100 );
connect( m_normalizeToggle, SIGNAL( toggled( bool ) ),
this, SLOT ( normalizeToggle( bool ) ) );
m_graph = new graph( this );
m_graph->move(53,118); // 55,120 - 2px border
m_graph->setCursor( QCursor( Qt::CrossCursor ) );
toolTip::add( m_graph, tr ( "Draw your own waveform here"
"by dragging your mouse onto this graph"
));
QPixmap p = PLUGIN_NAME::getIconPixmap("wavegraph3") ;
m_graph->setBackground( p );
connect( m_graph, SIGNAL ( sampleSizeChanged( float ) ),
this, SLOT (sampleSizeChanged( float ) ) );
connect( m_graph, SIGNAL ( sampleChanged( void ) ),
this, SLOT ( sampleChanged( void ) ) );
sinWaveBtn = new pixmapButton( this, tr( "Sine wave" ),
_channel_track );
sinWaveBtn->move( 188, 120 );
sinWaveBtn->setActiveGraphic( embed::getIconPixmap(
"sin_wave_active" ) );
sinWaveBtn->setInactiveGraphic( embed::getIconPixmap(
"sin_wave_inactive" ) );
toolTip::add( sinWaveBtn,
tr( "Click here if you want a sine-wave for "
"current oscillator." ) );
triangleWaveBtn = new pixmapButton( this, tr( "Triangle wave" ),
_channel_track );
triangleWaveBtn->move( 188, 136 );
triangleWaveBtn->setActiveGraphic(
embed::getIconPixmap( "triangle_wave_active" ) );
triangleWaveBtn->setInactiveGraphic(
embed::getIconPixmap( "triangle_wave_inactive" ) );
toolTip::add( triangleWaveBtn,
tr( "Click here if you want a triangle-wave "
"for current oscillator." ) );
sawWaveBtn = new pixmapButton( this, tr( "Saw wave" ),
_channel_track );
sawWaveBtn->move( 188, 152 );
sawWaveBtn->setActiveGraphic( embed::getIconPixmap(
"saw_wave_active" ) );
sawWaveBtn->setInactiveGraphic( embed::getIconPixmap(
"saw_wave_inactive" ) );
toolTip::add( sawWaveBtn,
tr( "Click here if you want a saw-wave for "
"current oscillator." ) );
sqrWaveBtn = new pixmapButton( this, tr( "Square wave" ),
_channel_track );
sqrWaveBtn->move( 188, 168 );
sqrWaveBtn->setActiveGraphic( embed::getIconPixmap(
"square_wave_active" ) );
sqrWaveBtn->setInactiveGraphic( embed::getIconPixmap(
"square_wave_inactive" ) );
toolTip::add( sqrWaveBtn,
tr( "Click here if you want a square-wave for "
"current oscillator." ) );
whiteNoiseWaveBtn = new pixmapButton( this,
tr( "White noise wave" ),
_channel_track );
whiteNoiseWaveBtn->move( 188, 184 );
whiteNoiseWaveBtn->setActiveGraphic(
embed::getIconPixmap( "white_noise_wave_active" ) );
whiteNoiseWaveBtn->setInactiveGraphic(
embed::getIconPixmap( "white_noise_wave_inactive" ) );
toolTip::add( whiteNoiseWaveBtn,
tr( "Click here if you want a white-noise for "
"current oscillator." ) );
usrWaveBtn = new pixmapButton( this, tr( "User defined wave" ),
_channel_track );
usrWaveBtn->move( 188, 200 );
usrWaveBtn->setActiveGraphic( embed::getIconPixmap(
"usr_wave_active" ) );
usrWaveBtn->setInactiveGraphic( embed::getIconPixmap(
"usr_wave_inactive" ) );
toolTip::add( usrWaveBtn,
tr( "Click here if you want a user-defined "
"wave-shape for current oscillator." ) );
connect( sinWaveBtn, SIGNAL (clicked ( void ) ),
this, SLOT ( sinWaveClicked( void ) ) );
connect( triangleWaveBtn, SIGNAL ( clicked ( void ) ),
this, SLOT ( triangleWaveClicked( void ) ) );
connect( sawWaveBtn, SIGNAL (clicked ( void ) ),
this, SLOT ( sawWaveClicked( void ) ) );
connect( sqrWaveBtn, SIGNAL ( clicked ( void ) ),
this, SLOT ( sqrWaveClicked( void ) ) );
connect( whiteNoiseWaveBtn, SIGNAL ( clicked ( void ) ),
this, SLOT ( noiseWaveClicked( void ) ) );
connect( usrWaveBtn, SIGNAL ( clicked ( void ) ),
this, SLOT ( usrWaveClicked( void ) ) );
smoothBtn = new pixmapButton( this, tr( "Smooth" ),
_channel_track );
smoothBtn->move( 55, 225 );
smoothBtn->setActiveGraphic( PLUGIN_NAME::getIconPixmap(
"smooth" ) );
smoothBtn->setInactiveGraphic( PLUGIN_NAME::getIconPixmap(
"smooth" ) );
smoothBtn->setChecked( TRUE );
toolTip::add( smoothBtn,
tr( "Click here to "
"smooth waveform." ) );
connect( smoothBtn, SIGNAL ( clicked ( void ) ),
this, SLOT ( smoothClicked( void ) ) );
setAutoFillBackground( TRUE );
QPalette pal;
pal.setBrush( backgroundRole(), PLUGIN_NAME::getIconPixmap(
"artwork" ) );
setPalette( pal );
sample_length = 128;
sample_shape = new float[128];
m_graph->setSamplePointer( sample_shape, sample_length );
emit( sinWaveClicked() );
connect( &m_graph, SIGNAL( samplesChanged( Uint32, Uint32 ) ),
this, SLOT( samplesChanged( Uint32, Uint32 ) ) );
}
void bitInvader::sinWaveClicked( void )
{
// generate a Sinus wave using static oscillator-method
for (int i=0; i < sample_length; i++)
{
sample_shape[i] = oscillator::sinSample( i / static_cast<float>(
sample_length ) );
}
sampleChanged();
}
void bitInvader::triangleWaveClicked( void )
{
// generate a Triangle wave using static oscillator-method
for (int i=0; i < sample_length; i++)
{
sample_shape[i] = oscillator::triangleSample( i /
static_cast<float>( sample_length) );
}
sampleChanged();
}
void bitInvader::sawWaveClicked( void )
{
// generate a Saw wave using static oscillator-method
for (int i=0; i < sample_length; i++)
{
sample_shape[i] = oscillator::sawSample( i / static_cast<float>(
sample_length ) );
}
sampleChanged();
}
void bitInvader::sqrWaveClicked( void )
{
// generate a Sqr wave using static oscillator-method
for (int i=0; i < sample_length; i++)
{
sample_shape[i] = oscillator::squareSample( i /
static_cast<float>( sample_length ) );
}
sampleChanged();
}
void bitInvader::noiseWaveClicked( void )
{
// generate a Noise wave using static oscillator-method
for (int i=0; i < sample_length; i++)
{
sample_shape[i] = oscillator::noiseSample( i /
static_cast<float>( sample_length ) );
}
sampleChanged();
}
void bitInvader::usrWaveClicked( void )
{
// zero sample_shape
for (int i = 0; i < sample_length; i++)
{
sample_shape[i] = 0;
}
// load user shape
sampleBuffer buffer;
QString af = buffer.openAudioFile();
if ( af != "" )
{
buffer.setAudioFile( af );
// copy buffer data
sample_length = min( sample_length, static_cast<int>(
buffer.frames() ) );
for ( int i = 0; i < sample_length; i++ )
{
sample_shape[i] = (float)*buffer.data()[i];
}
}
sampleChanged();
}
bitInvader::~bitInvader()
{
}
@@ -434,21 +181,20 @@ void bitInvader::saveSettings( QDomDocument & _doc, QDomElement & _this )
_this.setAttribute( "version", "0.1" );
// Save sample length
m_sampleLengthKnob->saveSettings( _doc, _this, "sampleLength" );
m_sampleLength.saveSettings( _doc, _this, "sampleLength" );
// Save sample shape base64-encoded
QString sampleString;
base64::encode( (const char *)sample_shape,
sample_length * sizeof(float), sampleString );
base64::encode( (const char *)m_graph.samples(),
m_graph.length() * sizeof(float), sampleString );
_this.setAttribute( "sampleShape", sampleString );
// save LED normalize
m_interpolationToggle->saveSettings( _doc, _this, "interpolation" );
m_interpolation.saveSettings( _doc, _this, "interpolation" );
// save LED
m_normalizeToggle->saveSettings( _doc, _this, "normalize" );
m_normalize->saveSettings( _doc, _this, "normalize" );
}
@@ -457,89 +203,71 @@ void bitInvader::saveSettings( QDomDocument & _doc, QDomElement & _this )
void bitInvader::loadSettings( const QDomElement & _this )
{
// Load sample length
m_sampleLengthKnob->loadSettings( _this, "sampleLength" );
m_sampleLength.loadSettings( _this, "sampleLength" );
sample_length = (int)m_sampleLengthKnob->value();
int sampleLength = (int)m_sampleLength.value();
// Load sample shape
delete[] sample_shape;
sample_shape = new float[sample_length];
int size = 0;
char * dst = 0;
base64::decode( _this.attribute( "sampleShape"), &dst, &size );
memcpy( sample_shape, dst, tMin<int>( size, sample_length *
sizeof( float ) ) );
m_graph.setLength( size );
m_graph.setSamples( (float*) dst );
delete[] dst;
m_graph->setSamplePointer( sample_shape, sample_length );
// Load LED normalize
m_interpolationToggle->loadSettings( _this, "interpolation" );
m_interpolation.loadSettings( _this, "interpolation" );
// Load LED
m_normalizeToggle->loadSettings( _this, "normalize" );
update();
// songEditor::inst()->setModified();
}
void bitInvader::interpolationToggle( bool value )
void bitInvader::lengthChanged( void )
{
interpolation = value;
m_graph.setLength( m_sampleLength.value() );
engine::getSongEditor()->setModified();
normalize();
}
void bitInvader::normalizeToggle( bool value )
void bitInvader::samplesChanged( Uint32 _begin, Uint32 _end )
{
normalize = value;
engine::getSongEditor()->setModified();
normalize();
//engine::getSongEditor()->setModified();
}
void bitInvader::normalize( void )
{
// analyze
float max = 0;
const float* samples = m_graph.samples();
for (int i=0; i < m_graph.length(); i++)
{
if (fabsf(samples[i]) > max) { max = fabs(samples[i]); }
}
normalizeFactor = 1.0 / max;
}
QString bitInvader::nodeName( void ) const
{
return( bitinvader_plugin_descriptor.name );
}
void bitInvader::smoothClicked( void )
{
// store values in temporary array
float* temp = new float[sample_length];
memcpy( temp, sample_shape, sizeof( float ) * sample_length );
// Smoothing
sample_shape[0] = ( temp[0]+temp[sample_length-1] ) * 0.5f;
for ( int i=1; i < sample_length; i++)
{
sample_shape[i] = (temp[i-1] + temp[i]) * 0.5f;
}
// Clean up
delete[] temp;
// paint
update();
m_graph->update();
engine::getSongEditor()->setModified();
}
void bitInvader::playNote( notePlayHandle * _n, bool )
{
if ( _n->totalFramesPlayed() == 0 || _n->m_pluginData == NULL )
{
float factor;
if( !normalize )
if( !m_normalize.value() )
{
factor = 1.0f;
}
@@ -548,8 +276,9 @@ void bitInvader::playNote( notePlayHandle * _n, bool )
factor = normalizeFactor;
}
_n->m_pluginData = new bSynth( sample_shape, sample_length,
_n->frequency(), interpolation, factor,
_n->m_pluginData = new bSynth( const_cast<float*>( m_graph.samples() ),
m_graph.length(),
_n->frequency(), m_interpolation.value(), factor,
engine::getMixer()->sampleRate() );
}
@@ -574,85 +303,248 @@ void bitInvader::playNote( notePlayHandle * _n, bool )
}
void bitInvader::deleteNotePluginData( notePlayHandle * _n )
{
delete static_cast<bSynth *>( _n->m_pluginData );
}
void bitInvader::sampleSizeChanged( float _new_sample_length )
pluginView * bitInvader::instantiateView( QWidget * _parent )
{
int new_sample_length = static_cast<int>(_new_sample_length);
// ** grow array
if (new_sample_length > sample_length) {
// store values in temporary array
float* temp = new float[sample_length];
for (int i=0; i < sample_length; i++)
{
temp[i] = sample_shape[i];
}
// reinitialize sample array
delete[] sample_shape;
sample_shape = new float[new_sample_length];
for (int i=0; i < new_sample_length; i++)
{
sample_shape[i] = 0;
}
// fill in old values
for (int i=0; i < sample_length; i++)
{
sample_shape[i] = temp[i];
}
delete[] temp;
sample_length = new_sample_length;
}
// ** shrink array
if (new_sample_length < sample_length) {
sample_length = new_sample_length;
}
// update sample graph
m_graph->setSamplePointer( sample_shape, sample_length );
// set Song modified
engine::getSongEditor()->setModified();
}
void bitInvader::sampleChanged()
{
// analyze
float max = 0;
for (int i=0; i < sample_length; i++)
{
if (fabsf(sample_shape[i]) > max) { max = fabs(sample_shape[i]); }
}
normalizeFactor = 1.0 / max;
// update
if (m_graph != NULL) {
m_graph->update();
}
engine::getSongEditor()->setModified();
return( new bitInvaderView( this, _parent ) );
}
bitInvaderView::bitInvaderView( instrument * _instrument,
QWidget * _parent ) :
instrumentView( _instrument, _parent )
{
setAutoFillBackground( TRUE );
QPalette pal;
pal.setBrush( backgroundRole(), PLUGIN_NAME::getIconPixmap(
"artwork" ) );
setPalette( pal );
m_sampleLengthKnob = new knob( knobDark_28, this, tr( "Samplelength" ) );
m_sampleLengthKnob->move( 10, 120 );
m_sampleLengthKnob->setHintText( tr( "Sample Length" ) + " ", "" );
m_graph = new graph( this );
m_graph->move(53,118); // 55,120 - 2px border
m_graph->setAutoFillBackground( TRUE );
toolTip::add( m_graph, tr ( "Draw your own waveform here"
"by dragging your mouse onto this graph"
));
pal = QPalette();
pal.setBrush( backgroundRole(),
PLUGIN_NAME::getIconPixmap("wavegraph3") );
m_graph->setPalette( pal );
sinWaveBtn = new pixmapButton( this, tr( "Sine wave" ) );
sinWaveBtn->move( 188, 120 );
sinWaveBtn->setActiveGraphic( embed::getIconPixmap(
"sin_wave_active" ) );
sinWaveBtn->setInactiveGraphic( embed::getIconPixmap(
"sin_wave_inactive" ) );
toolTip::add( sinWaveBtn,
tr( "Click here if you want a sine-wave for "
"current oscillator." ) );
triangleWaveBtn = new pixmapButton( this, tr( "Triangle wave" ) );
triangleWaveBtn->move( 188, 136 );
triangleWaveBtn->setActiveGraphic(
embed::getIconPixmap( "triangle_wave_active" ) );
triangleWaveBtn->setInactiveGraphic(
embed::getIconPixmap( "triangle_wave_inactive" ) );
toolTip::add( triangleWaveBtn,
tr( "Click here if you want a triangle-wave "
"for current oscillator." ) );
sawWaveBtn = new pixmapButton( this, tr( "Saw wave" ) );
sawWaveBtn->move( 188, 152 );
sawWaveBtn->setActiveGraphic( embed::getIconPixmap(
"saw_wave_active" ) );
sawWaveBtn->setInactiveGraphic( embed::getIconPixmap(
"saw_wave_inactive" ) );
toolTip::add( sawWaveBtn,
tr( "Click here if you want a saw-wave for "
"current oscillator." ) );
sqrWaveBtn = new pixmapButton( this, tr( "Square wave" ) );
sqrWaveBtn->move( 188, 168 );
sqrWaveBtn->setActiveGraphic( embed::getIconPixmap(
"square_wave_active" ) );
sqrWaveBtn->setInactiveGraphic( embed::getIconPixmap(
"square_wave_inactive" ) );
toolTip::add( sqrWaveBtn,
tr( "Click here if you want a square-wave for "
"current oscillator." ) );
whiteNoiseWaveBtn = new pixmapButton( this,
tr( "White noise wave" ) );
whiteNoiseWaveBtn->move( 188, 184 );
whiteNoiseWaveBtn->setActiveGraphic(
embed::getIconPixmap( "white_noise_wave_active" ) );
whiteNoiseWaveBtn->setInactiveGraphic(
embed::getIconPixmap( "white_noise_wave_inactive" ) );
toolTip::add( whiteNoiseWaveBtn,
tr( "Click here if you want a white-noise for "
"current oscillator." ) );
usrWaveBtn = new pixmapButton( this, tr( "User defined wave" ) );
usrWaveBtn->move( 188, 200 );
usrWaveBtn->setActiveGraphic( embed::getIconPixmap(
"usr_wave_active" ) );
usrWaveBtn->setInactiveGraphic( embed::getIconPixmap(
"usr_wave_inactive" ) );
toolTip::add( usrWaveBtn,
tr( "Click here if you want a user-defined "
"wave-shape for current oscillator." ) );
smoothBtn = new pixmapButton( this, tr( "Smooth" ) );
smoothBtn->move( 55, 225 );
smoothBtn->setActiveGraphic( PLUGIN_NAME::getIconPixmap(
"smooth" ) );
smoothBtn->setInactiveGraphic( PLUGIN_NAME::getIconPixmap(
"smooth" ) );
smoothBtn->setChecked( TRUE );
toolTip::add( smoothBtn,
tr( "Click here to "
"smooth waveform." ) );
m_interpolationToggle = new ledCheckBox( "Interpolation", this,
tr( "Interpolation" ) );
m_interpolationToggle->move( 55,80 );
m_normalizeToggle = new ledCheckBox( "Normalize", this,
tr( "Normalize" ) );
m_normalizeToggle->move( 55, 100 );
connect( sinWaveBtn, SIGNAL (clicked ( void ) ),
this, SLOT ( sinWaveClicked( void ) ) );
connect( triangleWaveBtn, SIGNAL ( clicked ( void ) ),
this, SLOT ( triangleWaveClicked( void ) ) );
connect( sawWaveBtn, SIGNAL (clicked ( void ) ),
this, SLOT ( sawWaveClicked( void ) ) );
connect( sqrWaveBtn, SIGNAL ( clicked ( void ) ),
this, SLOT ( sqrWaveClicked( void ) ) );
connect( whiteNoiseWaveBtn, SIGNAL ( clicked ( void ) ),
this, SLOT ( noiseWaveClicked( void ) ) );
connect( usrWaveBtn, SIGNAL ( clicked ( void ) ),
this, SLOT ( usrWaveClicked( void ) ) );
connect( smoothBtn, SIGNAL ( clicked ( void ) ),
this, SLOT ( smoothClicked( void ) ) );
connect( m_interpolationToggle, SIGNAL( toggled( bool ) ),
this, SLOT ( interpolationToggled( bool ) ) );
connect( m_normalizeToggle, SIGNAL( toggled( bool ) ),
this, SLOT ( normalizeToggled( bool ) ) );
}
void bitInvaderView::modelChanged( void )
{
bitInvader * b = castModel<bitInvader>();
m_graph->setModel( &b->m_graph );
m_sampleLengthKnob->setModel( &b->m_sampleLength );
m_interpolationToggle->setModel( &b->m_interpolation );
m_normalizeToggle->setModel( &b->m_normalize );
}
void bitInvaderView::sinWaveClicked( void )
{
m_graph->model()->setWaveToSine();
engine::getSong()->setModified();
}
void bitInvaderView::triangleWaveClicked( void )
{
m_graph->model()->setWaveToTriangle();
engine::getSong()->setModified();
}
void bitInvaderView::sawWaveClicked( void )
{
m_graph->model()->setWaveToSaw();
engine::getSong()->setModified();
}
void bitInvaderView::sqrWaveClicked( void )
{
m_graph->model()->setWaveToSquare();
engine::getSong()->setModified();
}
void bitInvaderView::noiseWaveClicked( void )
{
m_graph->model()->setWaveToNoise();
engine::getSong()->setModified();
}
void bitInvaderView::usrWaveClicked( void )
{
/*
m_graph->model()->setWaveToNoise();
engine::getSong()->setModified();
// zero sample_shape
for (int i = 0; i < sample_length; i++)
{
sample_shape[i] = 0;
}
// load user shape
sampleBuffer buffer;
QString af = buffer.openAudioFile();
if ( af != "" )
{
buffer.setAudioFile( af );
// copy buffer data
sample_length = min( sample_length, static_cast<int>(
buffer.frames() ) );
for ( int i = 0; i < sample_length; i++ )
{
sample_shape[i] = (float)*buffer.data()[i];
}
}
sampleChanged();
*/
}
void bitInvaderView::smoothClicked( void )
{
m_graph->model()->smooth();
engine::getSong()->setModified();
}
void bitInvaderView::interpolationToggled( bool value )
{
engine::getSong()->setModified();
}
void bitInvaderView::normalizeToggled( bool value )
{
engine::getSong()->setModified();
}
extern "C"
{
@@ -668,5 +560,4 @@ plugin * lmms_plugin_main( void * _data )
#include "bit_invader.moc"

View File

@@ -29,15 +29,15 @@
#include "instrument.h"
#include "instrument_view.h"
#include "types.h"
#include "graph.h"
#include "knob.h"
#include "pixmap_button.h"
#include "led_checkbox.h"
class QPixmap;
class graph;
class knob;
class ledCheckBox;
class oscillator;
class pixmapButton;
class bitInvaderView;
class bSynth
{
@@ -83,29 +83,59 @@ public:
return( 64 );
}
virtual pluginView * instantiateView( QWidget * _parent );
public slots:
void sampleSizeChanged( float _new_sample_length );
void sampleChanged( void );
protected slots:
void lengthChanged( void );
void samplesChanged( Uint32, Uint32 );
void interpolationToggle( bool value );
void normalizeToggle( bool value );
void smoothClicked( void );
void normalize( void );
void sinWaveClicked( void );
void triangleWaveClicked( void );
void sqrWaveClicked( void );
void sawWaveClicked( void );
void noiseWaveClicked( void );
void usrWaveClicked( void );
/*
protected:
virtual void paintEvent( QPaintEvent * );
*/
private:
knob * m_sampleLengthKnob;
knobModel m_sampleLength;
graphModel m_graph;
boolModel m_interpolation;
boolModel m_normalize;
float normalizeFactor;
oscillator * m_osc;
friend class bitInvaderView;
} ;
class bitInvaderView : public instrumentView
{
Q_OBJECT
public:
bitInvaderView( instrument * _instrument,
QWidget * _parent );
virtual ~bitInvaderView() {};
protected slots:
//void sampleSizeChanged( float _new_sample_length );
void interpolationToggled( bool value );
void normalizeToggled( bool value );
void sinWaveClicked( void );
void triangleWaveClicked( void );
void sqrWaveClicked( void );
void sawWaveClicked( void );
void noiseWaveClicked( void );
void usrWaveClicked( void );
void smoothClicked( void );
private:
virtual void modelChanged( void );
knob * m_sampleLengthKnob;
pixmapButton * sinWaveBtn;
pixmapButton * triangleWaveBtn;
pixmapButton * sqrWaveBtn;
@@ -120,17 +150,8 @@ private:
ledCheckBox * m_interpolationToggle;
ledCheckBox * m_normalizeToggle;
int sample_length;
float* sample_shape;
bool interpolation;
bool normalize;
float normalizeFactor;
oscillator * m_osc;
} ;
#endif

View File

@@ -1,221 +0,0 @@
/*
* graph.cpp - a QT widget for displaying and manipulating waveforms
*
* Copyright (c) 2006-2007 Andreas Brandmaier <andy/at/brandmaier/dot/de>
*
* This file is part of Linux MultiMedia Studio - http://lmms.sourceforge.net
*
* 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 (at your option) 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.
*
* You should have received a copy of the GNU General Public
* License along with this program (see COPYING); if not, write to the
* Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
* Boston, MA 02110-1301 USA.
*
*/
#include <QtGui/QPaintEvent>
#include <QtGui/QFontMetrics>
#include <QtGui/QPainter>
#include "graph.h"
#include "string_pair_drag.h"
#include "sample_buffer.h"
#include <iostream>
#include <cstdlib>
using namespace std;
graph::graph( QWidget * _parent ) :
QWidget( _parent )
{
// m_background = 0; TODO
m_mouseDown = false;
setFixedSize( 132, 104 );
setAcceptDrops( TRUE );
}
graph::~graph()
{
}
void graph::setBackground( const QPixmap &_pixmap )
{
m_background = _pixmap;
}
void graph::setSamplePointer( float * _pointer, int _length )
{
samplePointer = _pointer;
sampleLength = _length;
update();
}
void graph::loadSampleFromFile( const QString & _filename )
{
// zero sample_shape
for (int i = 0; i < sampleLength; i++)
{
samplePointer[i] = 0;
}
// load user shape
sampleBuffer buffer( _filename );
// copy buffer data
sampleLength = min( sampleLength, static_cast<int>(buffer.frames()) );
for ( int i = 0; i < sampleLength; i++ )
{
samplePointer[i] = (float)*buffer.data()[i];
}
}
void graph::mouseMoveEvent ( QMouseEvent * _me )
{
// get position
int x = _me->x();
int y = _me->y();
// avoid mouse leaps
int diff = x - m_lastCursorX;
if (diff >= 1) {
x = m_lastCursorX + 1;
} else if (diff <= 1) {
x = m_lastCursorX - 1;
} else {
x = m_lastCursorX;
}
changeSampleAt( x, y );
// update mouse
m_lastCursorX = x;
}
void graph::mousePressEvent( QMouseEvent * _me )
{
// toggle mouse state
m_mouseDown = true;
// get position
int x = _me->x();
int y = _me->y();
changeSampleAt( x,y );
// toggle mouse state
m_mouseDown = true;
setCursor( Qt::BlankCursor );
m_lastCursorX = x;
}
void graph::changeSampleAt(int _x, int _y)
{
// consider border of background image
_x -= 2;
_y -= 2;
// boundary check
if (_x < 0) { return; }
if (_x > sampleLength) { return; }
if (_y < 0) { return; }
if (_y >= 100) { return; }
_y = 100 - _y;
// change sample shape
samplePointer[_x] = (_y-50.0)/50.0;
emit sampleChanged();
}
void graph::mouseReleaseEvent( QMouseEvent * _me )
{
// toggle mouse state
m_mouseDown = false;
setCursor( Qt::ArrowCursor );
update();
}
void graph::paintEvent( QPaintEvent * )
{
QPainter p( this );
// if (m_background != NULL) {
p.drawPixmap( 0, 0, m_background );
// }
p.setPen( QColor( 0xFF, 0xAA, 0x00 ) );
p.drawLine( 1+sampleLength, 2, 1+sampleLength, 102);
// float xscale = 200.0 / sampleLength;
float xscale = 1.0;
for (int i=0; i < sampleLength-1; i++)
{
p.drawLine(2+static_cast<int>(i*xscale),
2+static_cast<int>(-samplePointer[i]*50) + 50,
2+static_cast<int>((i+1)*xscale),
2+static_cast<int>(-samplePointer[i+1]*50 + 50)
);
}
// draw Pointer
if (m_mouseDown) {
QPoint cursor = mapFromGlobal( QCursor::pos() );
p.setPen( QColor( 0xAA, 0xFF, 0x00 ) );
p.drawLine( 2, cursor.y(), 130, cursor.y() );
p.drawLine( cursor.x(), 2, cursor.x(), 102 );
}
}
void graph::dropEvent( QDropEvent * _de )
{
QString type = stringPairDrag::decodeKey( _de );
QString value = stringPairDrag::decodeValue( _de );
if( type == "samplefile" )
{
loadSampleFromFile( value );
_de->accept();
}
}
void graph::dragEnterEvent( QDragEnterEvent * _dee )
{
if( stringPairDrag::processDragEnterEvent( _dee,
QString( "samplefile" ) ) == FALSE )
{
_dee->ignore();
}
}
#include "graph.moc"

View File

@@ -1,72 +0,0 @@
/*
* graph.h - a QT widget for displaying and manipulating waveforms
*
* Copyright (c) 2006-2007 Andreas Brandmaier <andy/at/brandmaier/dot/de>
*
* This file is part of Linux MultiMedia Studio - http://lmms.sourceforge.net
*
* 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 (at your option) 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.
*
* You should have received a copy of the GNU General Public
* License along with this program (see COPYING); if not, write to the
* Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
* Boston, MA 02110-1301 USA.
*
*/
#ifndef _GRAPH_H
#define _GRAPH_H
#include <QtGui/QWidget>
#include <QtGui/QPixmap>
#include <QtGui/QCursor>
class graph : public QWidget
{
Q_OBJECT
public:
graph( QWidget * _parent );
virtual ~graph();
void setSamplePointer( float * pointer, int length );
void setBackground ( const QPixmap & _pixmap );
void loadSampleFromFile( const QString & _filename );
signals:
void sampleSizeChanged( float f );
void sampleChanged( void );
protected:
virtual void paintEvent( QPaintEvent * _pe );
virtual void dropEvent( QDropEvent * _de );
virtual void dragEnterEvent( QDragEnterEvent * _dee );
virtual void mousePressEvent( QMouseEvent * _me );
virtual void mouseMoveEvent( QMouseEvent * _me );
virtual void mouseReleaseEvent( QMouseEvent * _me );
private:
void changeSampleAt(int _x, int _y);
QPixmap m_background;
float *samplePointer;
int sampleLength;
bool m_mouseDown;
int m_lastCursorX;
} ;
#endif