Moved baseNoteModel from InstrumentTrack to MidiEventProcessor; cleanups
Moved baseNoteModel from InstrumentTrack class to MidiEventProcessor class in order to make Piano class independent from InstrumentTrack class (so it can be used by other classes as well). Furthermore did various cleanups and coding style improvements.
This commit is contained in:
@@ -58,7 +58,7 @@ class tabWidget;
|
||||
class trackLabelButton;
|
||||
|
||||
|
||||
class EXPORT instrumentTrack : public track, public midiEventProcessor
|
||||
class EXPORT instrumentTrack : public track, public MidiEventProcessor
|
||||
{
|
||||
Q_OBJECT
|
||||
mapPropertyFromModel(int,getVolume,setVolume,m_volumeModel);
|
||||
@@ -143,12 +143,7 @@ public:
|
||||
return &m_midiPort;
|
||||
}
|
||||
|
||||
intModel * baseNoteModel( void )
|
||||
{
|
||||
return &m_baseNoteModel;
|
||||
}
|
||||
|
||||
piano * getPiano( void )
|
||||
Piano * getPiano( void )
|
||||
{
|
||||
return &m_piano;
|
||||
}
|
||||
@@ -217,8 +212,6 @@ private:
|
||||
notePlayHandle * m_notes[NumKeys];
|
||||
int m_runningMidiNotes[NumKeys];
|
||||
|
||||
intModel m_baseNoteModel;
|
||||
|
||||
QList<notePlayHandle *> m_processHandles;
|
||||
|
||||
|
||||
@@ -234,7 +227,7 @@ private:
|
||||
arpeggiator m_arpeggiator;
|
||||
chordCreator m_chordCreator;
|
||||
|
||||
piano m_piano;
|
||||
Piano m_piano;
|
||||
|
||||
|
||||
friend class instrumentTrackView;
|
||||
@@ -401,7 +394,7 @@ private:
|
||||
effectRackView * m_effectView;
|
||||
|
||||
// test-piano at the bottom of every instrument-settings-window
|
||||
pianoView * m_pianoView;
|
||||
PianoView * m_pianoView;
|
||||
|
||||
friend class instrumentView;
|
||||
|
||||
|
||||
@@ -31,7 +31,7 @@
|
||||
#include "midi_port.h"
|
||||
#include "note.h"
|
||||
|
||||
class MidiControlListener : public midiEventProcessor
|
||||
class MidiControlListener : public MidiEventProcessor
|
||||
{
|
||||
public:
|
||||
typedef enum
|
||||
|
||||
@@ -36,7 +36,7 @@
|
||||
class midiPort;
|
||||
|
||||
|
||||
class midiController : public controller, public midiEventProcessor
|
||||
class midiController : public controller, public MidiEventProcessor
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
|
||||
@@ -1,7 +1,8 @@
|
||||
/*
|
||||
* midi_event_processor.h - base-class for midi-processing classes
|
||||
* midi_event_processor.h - class MidiEventProcessor, a base class for all
|
||||
* midi-processing classes
|
||||
*
|
||||
* Copyright (c) 2005-2008 Tobias Doerffel <tobydox/at/users.sourceforge.net>
|
||||
* Copyright (c) 2005-2009 Tobias Doerffel <tobydox/at/users.sourceforge.net>
|
||||
*
|
||||
* This file is part of Linux MultiMedia Studio - http://lmms.sourceforge.net
|
||||
*
|
||||
@@ -26,28 +27,47 @@
|
||||
#ifndef _MIDI_EVENT_PROCESSOR_H
|
||||
#define _MIDI_EVENT_PROCESSOR_H
|
||||
|
||||
class midiEvent;
|
||||
class midiTime;
|
||||
#include "piano.h"
|
||||
#include "automatable_model.h"
|
||||
|
||||
|
||||
// all classes being able to process MIDI-events should inherit from this
|
||||
class midiEventProcessor
|
||||
class MidiEventProcessor
|
||||
{
|
||||
public:
|
||||
inline midiEventProcessor( void )
|
||||
inline MidiEventProcessor() :
|
||||
m_baseNoteModel( DefaultKey,
|
||||
0,
|
||||
KeysPerOctave * NumOctaves - 1,
|
||||
NULL,
|
||||
PianoView::tr( "Base note" ) )
|
||||
{
|
||||
}
|
||||
|
||||
virtual inline ~midiEventProcessor()
|
||||
virtual inline ~MidiEventProcessor()
|
||||
{
|
||||
}
|
||||
|
||||
intModel * baseNoteModel( void )
|
||||
{
|
||||
return &m_baseNoteModel;
|
||||
}
|
||||
|
||||
const intModel * baseNoteModel( void ) const
|
||||
{
|
||||
return &m_baseNoteModel;
|
||||
}
|
||||
|
||||
|
||||
// to be implemented by inheriting classes
|
||||
virtual void processInEvent( const midiEvent & _me,
|
||||
const midiTime & _time ) = 0;
|
||||
virtual void processOutEvent( const midiEvent & _me,
|
||||
const midiTime & _time ) = 0;
|
||||
|
||||
private:
|
||||
intModel m_baseNoteModel;
|
||||
|
||||
} ;
|
||||
|
||||
#endif
|
||||
|
||||
@@ -36,7 +36,7 @@
|
||||
|
||||
|
||||
class midiClient;
|
||||
class midiEventProcessor;
|
||||
class MidiEventProcessor;
|
||||
class midiPortMenu;
|
||||
class midiTime;
|
||||
|
||||
@@ -74,7 +74,7 @@ public:
|
||||
|
||||
midiPort( const QString & _name,
|
||||
midiClient * _mc,
|
||||
midiEventProcessor * _mep,
|
||||
MidiEventProcessor * _mep,
|
||||
model * _parent = NULL,
|
||||
Modes _mode = Disabled );
|
||||
virtual ~midiPort();
|
||||
@@ -142,7 +142,7 @@ private slots:
|
||||
|
||||
private:
|
||||
midiClient * m_midiClient;
|
||||
midiEventProcessor * m_midiEventProcessor;
|
||||
MidiEventProcessor * m_midiEventProcessor;
|
||||
|
||||
Modes m_mode;
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* piano.h - piano and pianoView, an interactive piano/keyboard-widget
|
||||
* piano.h - Piano and PianoView, an interactive piano/keyboard-widget
|
||||
*
|
||||
* Copyright (c) 2004-2009 Tobias Doerffel <tobydox/at/users.sourceforge.net>
|
||||
*
|
||||
@@ -26,32 +26,25 @@
|
||||
#ifndef _PIANO_H
|
||||
#define _PIANO_H
|
||||
|
||||
#include <QtGui/QWidget>
|
||||
#include <QtGui/QPixmap>
|
||||
#include <QtGui/QScrollBar>
|
||||
|
||||
|
||||
#include "note.h"
|
||||
#include "automatable_model.h"
|
||||
#include "mv_base.h"
|
||||
|
||||
class MidiEventProcessor;
|
||||
|
||||
class instrumentTrack;
|
||||
class instrumentTrackView;
|
||||
class notePlayHandle;
|
||||
|
||||
|
||||
enum KeyTypes
|
||||
{
|
||||
WhiteKey,
|
||||
BlackKey
|
||||
} ;
|
||||
|
||||
|
||||
class piano : public model
|
||||
class Piano : public model
|
||||
{
|
||||
public:
|
||||
piano( instrumentTrack * _it );
|
||||
virtual ~piano();
|
||||
enum KeyTypes
|
||||
{
|
||||
WhiteKey,
|
||||
BlackKey
|
||||
} ;
|
||||
|
||||
Piano( MidiEventProcessor * _mep );
|
||||
virtual ~Piano();
|
||||
|
||||
void setKeyState( int _key, bool _on = FALSE );
|
||||
|
||||
@@ -60,22 +53,22 @@ public:
|
||||
|
||||
|
||||
private:
|
||||
instrumentTrack * m_instrumentTrack;
|
||||
MidiEventProcessor * m_midiEvProc;
|
||||
bool m_pressedKeys[NumKeys];
|
||||
|
||||
|
||||
friend class pianoView;
|
||||
friend class PianoView;
|
||||
|
||||
} ;
|
||||
|
||||
|
||||
|
||||
class pianoView : public QWidget, public modelView
|
||||
class PianoView : public QWidget, public modelView
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
pianoView( QWidget * _parent );
|
||||
virtual ~pianoView();
|
||||
PianoView( QWidget * _parent );
|
||||
virtual ~PianoView();
|
||||
|
||||
static int getKeyFromKeyEvent( QKeyEvent * _ke );
|
||||
|
||||
@@ -101,7 +94,7 @@ private:
|
||||
static QPixmap * s_whiteKeyPressedPm;
|
||||
static QPixmap * s_blackKeyPressedPm;
|
||||
|
||||
piano * m_piano;
|
||||
Piano * m_piano;
|
||||
|
||||
QScrollBar * m_pianoScroll;
|
||||
int m_startKey; // first key when drawing
|
||||
|
||||
@@ -1,5 +1,3 @@
|
||||
#ifndef SINGLE_SOURCE_COMPILE
|
||||
|
||||
/*
|
||||
* midi_controller.cpp - implementation of class midi-controller which handles
|
||||
* MIDI control change messages
|
||||
@@ -40,7 +38,7 @@
|
||||
|
||||
midiController::midiController( model * _parent ) :
|
||||
controller( MidiController, _parent, tr( "MIDI Controller" ) ),
|
||||
midiEventProcessor(),
|
||||
MidiEventProcessor(),
|
||||
m_midiPort( tr( "unnamed_midi_controller" ),
|
||||
engine::getMixer()->getMidiClient(), this, this,
|
||||
midiPort::Input ),
|
||||
@@ -159,5 +157,3 @@ controllerDialog * midiController::createDialog( QWidget * _parent )
|
||||
#include "moc_midi_controller.cxx"
|
||||
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
@@ -33,7 +33,7 @@
|
||||
|
||||
|
||||
midiPort::midiPort( const QString & _name, midiClient * _mc,
|
||||
midiEventProcessor * _mep, model * _parent,
|
||||
MidiEventProcessor * _mep, model * _parent,
|
||||
Modes _mode ) :
|
||||
model( _parent ),
|
||||
m_readablePortsMenu( NULL ),
|
||||
|
||||
@@ -1,10 +1,8 @@
|
||||
#ifndef SINGLE_SOURCE_COMPILE
|
||||
|
||||
/*
|
||||
* piano.cpp - implementation of piano-widget used in instrument-track-window
|
||||
* for testing
|
||||
* for testing + according model class
|
||||
*
|
||||
* Copyright (c) 2004-2008 Tobias Doerffel <tobydox/at/users.sourceforge.net>
|
||||
* Copyright (c) 2004-2009 Tobias Doerffel <tobydox/at/users.sourceforge.net>
|
||||
*
|
||||
* This file is part of Linux MultiMedia Studio - http://lmms.sourceforge.net
|
||||
*
|
||||
@@ -68,12 +66,14 @@
|
||||
|
||||
/*! The black / white order of keys as they appear on the keyboard.
|
||||
*/
|
||||
const KeyTypes KEY_ORDER[] =
|
||||
const Piano::KeyTypes KEY_ORDER[] =
|
||||
{
|
||||
// C CIS D DIS E F
|
||||
WhiteKey, BlackKey, WhiteKey, BlackKey, WhiteKey, WhiteKey,
|
||||
// FIS G GIS A B H
|
||||
BlackKey, WhiteKey, BlackKey, WhiteKey, BlackKey, WhiteKey
|
||||
// C CIS D DIS
|
||||
Piano::WhiteKey, Piano::BlackKey, Piano::WhiteKey, Piano::BlackKey,
|
||||
// E F FIS G
|
||||
Piano::WhiteKey, Piano::WhiteKey, Piano::BlackKey, Piano::WhiteKey,
|
||||
// GIS A B H
|
||||
Piano::BlackKey, Piano::WhiteKey, Piano::BlackKey, Piano::WhiteKey
|
||||
} ;
|
||||
|
||||
|
||||
@@ -85,10 +85,10 @@ Keys WhiteKeys[] =
|
||||
} ;
|
||||
|
||||
|
||||
QPixmap * pianoView::s_whiteKeyPm = NULL; /*!< A white key released */
|
||||
QPixmap * pianoView::s_blackKeyPm = NULL; /*!< A black key released */
|
||||
QPixmap * pianoView::s_whiteKeyPressedPm = NULL; /*!< A white key pressed */
|
||||
QPixmap * pianoView::s_blackKeyPressedPm = NULL; /*!< A black key pressed */
|
||||
QPixmap * PianoView::s_whiteKeyPm = NULL; /*!< A white key released */
|
||||
QPixmap * PianoView::s_blackKeyPm = NULL; /*!< A black key released */
|
||||
QPixmap * PianoView::s_whiteKeyPressedPm = NULL; /*!< A white key pressed */
|
||||
QPixmap * PianoView::s_blackKeyPressedPm = NULL; /*!< A black key pressed */
|
||||
|
||||
|
||||
const int PIANO_BASE = 11; /*!< The height of the root note display */
|
||||
@@ -105,13 +105,13 @@ const int LABEL_TEXT_SIZE = 7; /*!< The height of the key label text */
|
||||
*
|
||||
* \param _it the InstrumentTrack window to attach to
|
||||
*/
|
||||
piano::piano( instrumentTrack * _it ) :
|
||||
model( _it ), /*!< our model */
|
||||
m_instrumentTrack( _it ) /*!< the instrumentTrack model */
|
||||
Piano::Piano( MidiEventProcessor * _mep ) :
|
||||
model( NULL ), /*!< base class ctor */
|
||||
m_midiEvProc( _mep ) /*!< the instrumentTrack model */
|
||||
{
|
||||
for( int i = 0; i < KeysPerOctave * NumOctaves; ++i )
|
||||
{
|
||||
m_pressedKeys[i] = FALSE;
|
||||
m_pressedKeys[i] = false;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -122,7 +122,7 @@ piano::piano( instrumentTrack * _it ) :
|
||||
/*! \brief Destroy this new keyboard display
|
||||
*
|
||||
*/
|
||||
piano::~piano()
|
||||
Piano::~Piano()
|
||||
{
|
||||
}
|
||||
|
||||
@@ -134,7 +134,7 @@ piano::~piano()
|
||||
* \param _key the key number to change
|
||||
* \param _on the state to set the key to
|
||||
*/
|
||||
void piano::setKeyState( int _key, bool _on )
|
||||
void Piano::setKeyState( int _key, bool _on )
|
||||
{
|
||||
m_pressedKeys[tLimit( _key, 0, KeysPerOctave * NumOctaves - 1 )] = _on;
|
||||
emit dataChanged();
|
||||
@@ -147,11 +147,11 @@ void piano::setKeyState( int _key, bool _on )
|
||||
*
|
||||
* \param _key the key being pressed
|
||||
*/
|
||||
void piano::handleKeyPress( int _key )
|
||||
void Piano::handleKeyPress( int _key )
|
||||
{
|
||||
m_instrumentTrack->processInEvent( midiEvent( MidiNoteOn, 0, _key,
|
||||
m_midiEvProc->processInEvent( midiEvent( MidiNoteOn, 0, _key,
|
||||
MidiMaxVelocity ), midiTime() );
|
||||
m_pressedKeys[_key] = TRUE;
|
||||
m_pressedKeys[_key] = true;
|
||||
}
|
||||
|
||||
|
||||
@@ -162,11 +162,11 @@ void piano::handleKeyPress( int _key )
|
||||
*
|
||||
* \param _key the key being releassed
|
||||
*/
|
||||
void piano::handleKeyRelease( int _key )
|
||||
void Piano::handleKeyRelease( int _key )
|
||||
{
|
||||
m_instrumentTrack->processInEvent( midiEvent( MidiNoteOff, 0, _key, 0 ),
|
||||
m_midiEvProc->processInEvent( midiEvent( MidiNoteOff, 0, _key, 0 ),
|
||||
midiTime() );
|
||||
m_pressedKeys[_key] = FALSE;
|
||||
m_pressedKeys[_key] = false;
|
||||
}
|
||||
|
||||
|
||||
@@ -180,7 +180,7 @@ void piano::handleKeyRelease( int _key )
|
||||
* \param _parent the parent instrument plugin window
|
||||
* \todo are the descriptions of the m_startkey and m_lastkey properties correct?
|
||||
*/
|
||||
pianoView::pianoView( QWidget * _parent ) :
|
||||
PianoView::PianoView( QWidget * _parent ) :
|
||||
QWidget( _parent ), /*!< Our parent */
|
||||
modelView( NULL, this ), /*!< Our view model */
|
||||
m_piano( NULL ), /*!< Our piano model */
|
||||
@@ -231,7 +231,7 @@ pianoView::pianoView( QWidget * _parent ) :
|
||||
/*! \brief Destroy this piano display view
|
||||
*
|
||||
*/
|
||||
pianoView::~pianoView()
|
||||
PianoView::~PianoView()
|
||||
{
|
||||
}
|
||||
|
||||
@@ -244,7 +244,7 @@ pianoView::~pianoView()
|
||||
* \todo check the scan codes for ',' = c, 'L' = c#, '.' = d, ':' = d#,
|
||||
* '/' = d, '[' = f', '=' = f'#, ']' = g' - Paul's additions
|
||||
*/
|
||||
int pianoView::getKeyFromKeyEvent( QKeyEvent * _ke )
|
||||
int PianoView::getKeyFromKeyEvent( QKeyEvent * _ke )
|
||||
{
|
||||
#ifdef LMMS_BUILD_APPLE
|
||||
const int k = _ke->nativeVirtualKey();
|
||||
@@ -379,12 +379,12 @@ int pianoView::getKeyFromKeyEvent( QKeyEvent * _ke )
|
||||
/*! \brief Register a change to this piano display view
|
||||
*
|
||||
*/
|
||||
void pianoView::modelChanged( void )
|
||||
void PianoView::modelChanged( void )
|
||||
{
|
||||
m_piano = castModel<piano>();
|
||||
m_piano = castModel<Piano>();
|
||||
if( m_piano != NULL )
|
||||
{
|
||||
connect( m_piano->m_instrumentTrack->baseNoteModel(),
|
||||
connect( m_piano->m_midiEvProc->baseNoteModel(),
|
||||
SIGNAL( dataChanged() ), this, SLOT( update() ) );
|
||||
}
|
||||
|
||||
@@ -413,13 +413,14 @@ void pianoView::modelChanged( void )
|
||||
*
|
||||
* \param _p The point that the mouse was pressed.
|
||||
*/
|
||||
int pianoView::getKeyFromMouse( const QPoint & _p ) const
|
||||
int PianoView::getKeyFromMouse( const QPoint & _p ) const
|
||||
{
|
||||
int key_num = (int)( (float) _p.x() / (float) PW_WHITE_KEY_WIDTH );
|
||||
|
||||
for( int i = 0; i <= key_num; ++i )
|
||||
{
|
||||
if( KEY_ORDER[( m_startKey+i ) % KeysPerOctave] == BlackKey )
|
||||
if( KEY_ORDER[( m_startKey+i ) % KeysPerOctave] ==
|
||||
Piano::BlackKey )
|
||||
{
|
||||
++key_num;
|
||||
}
|
||||
@@ -432,8 +433,8 @@ int pianoView::getKeyFromMouse( const QPoint & _p ) const
|
||||
{
|
||||
// then do extra checking whether the mouse-cursor is over
|
||||
// a black key
|
||||
if( key_num > 0 && KEY_ORDER[( key_num - 1 ) % KeysPerOctave] ==
|
||||
BlackKey &&
|
||||
if( key_num > 0 && KEY_ORDER[(key_num-1 ) % KeysPerOctave] ==
|
||||
Piano::BlackKey &&
|
||||
_p.x() % PW_WHITE_KEY_WIDTH <=
|
||||
( PW_WHITE_KEY_WIDTH / 2 ) -
|
||||
( PW_BLACK_KEY_WIDTH / 2 ) )
|
||||
@@ -442,7 +443,7 @@ int pianoView::getKeyFromMouse( const QPoint & _p ) const
|
||||
}
|
||||
if( key_num < KeysPerOctave * NumOctaves - 1 &&
|
||||
KEY_ORDER[( key_num + 1 ) % KeysPerOctave] ==
|
||||
BlackKey &&
|
||||
Piano::BlackKey &&
|
||||
_p.x() % PW_WHITE_KEY_WIDTH >=
|
||||
( PW_WHITE_KEY_WIDTH -
|
||||
PW_BLACK_KEY_WIDTH / 2 ) )
|
||||
@@ -465,7 +466,7 @@ int pianoView::getKeyFromMouse( const QPoint & _p ) const
|
||||
*
|
||||
* \param _new_pos the new key position.
|
||||
*/
|
||||
void pianoView::pianoScrolled( int _new_pos )
|
||||
void PianoView::pianoScrolled( int _new_pos )
|
||||
{
|
||||
m_startKey = WhiteKeys[_new_pos % WhiteKeysPerOctave]+
|
||||
( _new_pos / WhiteKeysPerOctave ) * KeysPerOctave;
|
||||
@@ -481,7 +482,7 @@ void pianoView::pianoScrolled( int _new_pos )
|
||||
* \param _me the ContextMenuEvent to handle.
|
||||
* \todo Is this right, or does this create the context menu?
|
||||
*/
|
||||
void pianoView::contextMenuEvent( QContextMenuEvent * _me )
|
||||
void PianoView::contextMenuEvent( QContextMenuEvent * _me )
|
||||
{
|
||||
if( _me->pos().y() > PIANO_BASE || m_piano == NULL )
|
||||
{
|
||||
@@ -490,7 +491,7 @@ void pianoView::contextMenuEvent( QContextMenuEvent * _me )
|
||||
}
|
||||
|
||||
captionMenu contextMenu( tr( "Base note" ) );
|
||||
automatableModelView amv( m_piano->m_instrumentTrack->baseNoteModel(),
|
||||
automatableModelView amv( m_piano->m_midiEvProc->baseNoteModel(),
|
||||
&contextMenu );
|
||||
amv.addDefaultActions( &contextMenu );
|
||||
contextMenu.exec( QCursor::pos() );
|
||||
@@ -517,7 +518,7 @@ void pianoView::contextMenuEvent( QContextMenuEvent * _me )
|
||||
*
|
||||
* \param _me the mouse click to handle.
|
||||
*/
|
||||
void pianoView::mousePressEvent( QMouseEvent * _me )
|
||||
void PianoView::mousePressEvent( QMouseEvent * _me )
|
||||
{
|
||||
if( _me->button() == Qt::LeftButton && m_piano != NULL )
|
||||
{
|
||||
@@ -528,26 +529,26 @@ void pianoView::mousePressEvent( QMouseEvent * _me )
|
||||
int y_diff = _me->pos().y() - PIANO_BASE;
|
||||
int velocity = (int)( ( float ) y_diff /
|
||||
( ( KEY_ORDER[key_num % KeysPerOctave] ==
|
||||
WhiteKey ) ?
|
||||
Piano::WhiteKey ) ?
|
||||
PW_WHITE_KEY_HEIGHT : PW_BLACK_KEY_HEIGHT ) *
|
||||
(float) MidiMaxVelocity );
|
||||
if( y_diff < 0 )
|
||||
{
|
||||
velocity = 0;
|
||||
}
|
||||
else if( y_diff > ( ( KEY_ORDER[key_num %
|
||||
KeysPerOctave] ==
|
||||
WhiteKey ) ?
|
||||
else if( y_diff >
|
||||
( ( KEY_ORDER[key_num % KeysPerOctave] ==
|
||||
Piano::WhiteKey ) ?
|
||||
PW_WHITE_KEY_HEIGHT : PW_BLACK_KEY_HEIGHT ) )
|
||||
{
|
||||
velocity = MidiMaxVelocity;
|
||||
}
|
||||
// set note on
|
||||
m_piano->m_instrumentTrack->processInEvent(
|
||||
m_piano->m_midiEvProc->processInEvent(
|
||||
midiEvent( MidiNoteOn, 0, key_num,
|
||||
velocity ),
|
||||
midiTime() );
|
||||
m_piano->m_pressedKeys[key_num] = TRUE;
|
||||
m_piano->m_pressedKeys[key_num] = true;
|
||||
m_lastKey = key_num;
|
||||
}
|
||||
else
|
||||
@@ -556,14 +557,14 @@ void pianoView::mousePressEvent( QMouseEvent * _me )
|
||||
{
|
||||
new stringPairDrag( "automatable_model",
|
||||
QString::number( m_piano->
|
||||
m_instrumentTrack->
|
||||
m_midiEvProc->
|
||||
baseNoteModel()->id() ),
|
||||
QPixmap(), this );
|
||||
_me->accept();
|
||||
}
|
||||
else
|
||||
{
|
||||
m_piano->m_instrumentTrack->
|
||||
m_piano->m_midiEvProc->
|
||||
baseNoteModel()->
|
||||
setInitValue( (float) key_num );
|
||||
}
|
||||
@@ -585,16 +586,16 @@ void pianoView::mousePressEvent( QMouseEvent * _me )
|
||||
*
|
||||
* \param _me the mousePressEvent to handle.
|
||||
*/
|
||||
void pianoView::mouseReleaseEvent( QMouseEvent * )
|
||||
void PianoView::mouseReleaseEvent( QMouseEvent * )
|
||||
{
|
||||
if( m_lastKey != -1 )
|
||||
{
|
||||
if( m_piano != NULL )
|
||||
{
|
||||
m_piano->m_instrumentTrack->processInEvent(
|
||||
m_piano->m_midiEvProc->processInEvent(
|
||||
midiEvent( MidiNoteOff, 0, m_lastKey, 0 ),
|
||||
midiTime() );
|
||||
m_piano->m_pressedKeys[m_lastKey] = FALSE;
|
||||
m_piano->m_pressedKeys[m_lastKey] = false;
|
||||
}
|
||||
|
||||
// and let the user see that he released a key... :)
|
||||
@@ -621,7 +622,7 @@ void pianoView::mouseReleaseEvent( QMouseEvent * )
|
||||
* reduce or remove the duplication between this, the mousePressEvent()
|
||||
* and mouseReleaseEvent() methods.
|
||||
*/
|
||||
void pianoView::mouseMoveEvent( QMouseEvent * _me )
|
||||
void PianoView::mouseMoveEvent( QMouseEvent * _me )
|
||||
{
|
||||
if( m_piano == NULL )
|
||||
{
|
||||
@@ -631,7 +632,7 @@ void pianoView::mouseMoveEvent( QMouseEvent * _me )
|
||||
int key_num = getKeyFromMouse( _me->pos() );
|
||||
int y_diff = _me->pos().y() - PIANO_BASE;
|
||||
int velocity = (int)( (float) y_diff /
|
||||
( ( KEY_ORDER[key_num % KeysPerOctave] == WhiteKey ) ?
|
||||
( ( KEY_ORDER[key_num % KeysPerOctave] == Piano::WhiteKey ) ?
|
||||
PW_WHITE_KEY_HEIGHT : PW_BLACK_KEY_HEIGHT ) *
|
||||
(float) MidiMaxVelocity );
|
||||
// maybe the user moved the mouse-cursor above or under the
|
||||
@@ -642,7 +643,7 @@ void pianoView::mouseMoveEvent( QMouseEvent * _me )
|
||||
velocity = 0;
|
||||
}
|
||||
else if( y_diff >
|
||||
( ( KEY_ORDER[key_num % KeysPerOctave] == WhiteKey ) ?
|
||||
( ( KEY_ORDER[key_num % KeysPerOctave] == Piano::WhiteKey ) ?
|
||||
PW_WHITE_KEY_HEIGHT : PW_BLACK_KEY_HEIGHT ) )
|
||||
{
|
||||
velocity = MidiMaxVelocity;
|
||||
@@ -654,26 +655,26 @@ void pianoView::mouseMoveEvent( QMouseEvent * _me )
|
||||
{
|
||||
if( m_lastKey != -1 )
|
||||
{
|
||||
m_piano->m_instrumentTrack->processInEvent(
|
||||
m_piano->m_midiEvProc->processInEvent(
|
||||
midiEvent( MidiNoteOff, 0, m_lastKey, 0 ),
|
||||
midiTime() );
|
||||
m_piano->m_pressedKeys[m_lastKey] = FALSE;
|
||||
m_piano->m_pressedKeys[m_lastKey] = false;
|
||||
m_lastKey = -1;
|
||||
}
|
||||
if( _me->buttons() & Qt::LeftButton )
|
||||
{
|
||||
if( _me->pos().y() > PIANO_BASE )
|
||||
{
|
||||
m_piano->m_instrumentTrack->processInEvent(
|
||||
m_piano->m_midiEvProc->processInEvent(
|
||||
midiEvent( MidiNoteOn, 0, key_num,
|
||||
velocity ),
|
||||
midiTime() );
|
||||
m_piano->m_pressedKeys[key_num] = TRUE;
|
||||
m_piano->m_pressedKeys[key_num] = true;
|
||||
m_lastKey = key_num;
|
||||
}
|
||||
else
|
||||
{
|
||||
m_piano->m_instrumentTrack->
|
||||
m_piano->m_midiEvProc->
|
||||
baseNoteModel()->
|
||||
setInitValue( (float) key_num );
|
||||
}
|
||||
@@ -681,9 +682,9 @@ void pianoView::mouseMoveEvent( QMouseEvent * _me )
|
||||
// and let the user see that he pressed a key... :)
|
||||
update();
|
||||
}
|
||||
else if( m_piano->m_pressedKeys[key_num] == TRUE )
|
||||
else if( m_piano->m_pressedKeys[key_num] == true )
|
||||
{
|
||||
m_piano->m_instrumentTrack->processInEvent(
|
||||
m_piano->m_midiEvProc->processInEvent(
|
||||
midiEvent( MidiKeyPressure, 0, key_num,
|
||||
velocity ),
|
||||
midiTime() );
|
||||
@@ -702,12 +703,12 @@ void pianoView::mouseMoveEvent( QMouseEvent * _me )
|
||||
*
|
||||
* \param _ke the KeyEvent to handle.
|
||||
*/
|
||||
void pianoView::keyPressEvent( QKeyEvent * _ke )
|
||||
void PianoView::keyPressEvent( QKeyEvent * _ke )
|
||||
{
|
||||
const int key_num = getKeyFromKeyEvent( _ke ) +
|
||||
( DefaultOctave - 1 ) * KeysPerOctave;
|
||||
|
||||
if( _ke->isAutoRepeat() == FALSE && key_num > -1 )
|
||||
if( _ke->isAutoRepeat() == false && key_num > -1 )
|
||||
{
|
||||
if( m_piano != NULL )
|
||||
{
|
||||
@@ -730,11 +731,11 @@ void pianoView::keyPressEvent( QKeyEvent * _ke )
|
||||
*
|
||||
* \param _ke the KeyEvent to handle.
|
||||
*/
|
||||
void pianoView::keyReleaseEvent( QKeyEvent * _ke )
|
||||
void PianoView::keyReleaseEvent( QKeyEvent * _ke )
|
||||
{
|
||||
const int key_num = getKeyFromKeyEvent( _ke ) +
|
||||
( DefaultOctave - 1 ) * KeysPerOctave;
|
||||
if( _ke->isAutoRepeat() == FALSE && key_num > -1 )
|
||||
if( _ke->isAutoRepeat() == false && key_num > -1 )
|
||||
{
|
||||
if( m_piano != NULL )
|
||||
{
|
||||
@@ -757,7 +758,7 @@ void pianoView::keyReleaseEvent( QKeyEvent * _ke )
|
||||
*
|
||||
* \todo Is there supposed to be a parameter given here?
|
||||
*/
|
||||
void pianoView::focusOutEvent( QFocusEvent * )
|
||||
void PianoView::focusOutEvent( QFocusEvent * )
|
||||
{
|
||||
if( m_piano == NULL )
|
||||
{
|
||||
@@ -781,12 +782,12 @@ void pianoView::focusOutEvent( QFocusEvent * )
|
||||
// hang otherwise
|
||||
for( int i = 0; i < KeysPerOctave * NumOctaves; ++i )
|
||||
{
|
||||
if( m_piano->m_pressedKeys[i] == TRUE )
|
||||
if( m_piano->m_pressedKeys[i] == true )
|
||||
{
|
||||
m_piano->m_instrumentTrack->processInEvent(
|
||||
m_piano->m_midiEvProc->processInEvent(
|
||||
midiEvent( MidiNoteOff, 0, i, 0 ),
|
||||
midiTime() );
|
||||
m_piano->m_pressedKeys[i] = FALSE;
|
||||
m_piano->m_pressedKeys[i] = false;
|
||||
}
|
||||
}
|
||||
update();
|
||||
@@ -809,7 +810,7 @@ void pianoView::focusOutEvent( QFocusEvent * )
|
||||
* \todo is this description of what the method does correct?
|
||||
* \todo replace the final subtract with initialising x to width/2.
|
||||
*/
|
||||
int pianoView::getKeyX( int _key_num ) const
|
||||
int PianoView::getKeyX( int _key_num ) const
|
||||
{
|
||||
int k = m_startKey;
|
||||
if( _key_num < m_startKey )
|
||||
@@ -822,7 +823,7 @@ int pianoView::getKeyX( int _key_num ) const
|
||||
|
||||
while( k <= _key_num )
|
||||
{
|
||||
if( KEY_ORDER[k % KeysPerOctave] == WhiteKey )
|
||||
if( KEY_ORDER[k % KeysPerOctave] == Piano::WhiteKey )
|
||||
{
|
||||
++white_cnt;
|
||||
if( white_cnt > 1 )
|
||||
@@ -858,7 +859,7 @@ int pianoView::getKeyX( int _key_num ) const
|
||||
*
|
||||
* \todo Is there supposed to be a parameter given here?
|
||||
*/
|
||||
void pianoView::paintEvent( QPaintEvent * )
|
||||
void PianoView::paintEvent( QPaintEvent * )
|
||||
{
|
||||
QPainter p( this );
|
||||
|
||||
@@ -882,11 +883,11 @@ void pianoView::paintEvent( QPaintEvent * )
|
||||
p.setPen( Qt::white );
|
||||
|
||||
const int base_key = ( m_piano != NULL ) ?
|
||||
m_piano->m_instrumentTrack->baseNoteModel()->value() : 0;
|
||||
m_piano->m_midiEvProc->baseNoteModel()->value() : 0;
|
||||
g.setColorAt( 0, QColor( 0, 96, 0 ) );
|
||||
g.setColorAt( 0.1, QColor( 64, 255, 64 ) );
|
||||
g.setColorAt( 1, QColor( 0, 96, 0 ) );
|
||||
if( KEY_ORDER[base_key % KeysPerOctave] == WhiteKey )
|
||||
if( KEY_ORDER[base_key % KeysPerOctave] == Piano::WhiteKey )
|
||||
{
|
||||
p.fillRect( QRect( getKeyX( base_key ), 1, PW_WHITE_KEY_WIDTH-1,
|
||||
PIANO_BASE-2 ), g );
|
||||
@@ -903,14 +904,14 @@ void pianoView::paintEvent( QPaintEvent * )
|
||||
// draw all white keys...
|
||||
for( int x = 0; x < width(); )
|
||||
{
|
||||
while( KEY_ORDER[cur_key%KeysPerOctave] != WhiteKey )
|
||||
while( KEY_ORDER[cur_key%KeysPerOctave] != Piano::WhiteKey )
|
||||
{
|
||||
++cur_key;
|
||||
}
|
||||
|
||||
// draw pressed or not pressed key, depending on state of
|
||||
// current key
|
||||
if( m_piano && m_piano->m_pressedKeys[cur_key] == TRUE )
|
||||
if( m_piano && m_piano->m_pressedKeys[cur_key] == true )
|
||||
{
|
||||
p.drawPixmap( x, PIANO_BASE, *s_whiteKeyPressedPm );
|
||||
}
|
||||
@@ -939,9 +940,9 @@ void pianoView::paintEvent( QPaintEvent * )
|
||||
|
||||
int s_key = m_startKey;
|
||||
if( s_key > 0 &&
|
||||
KEY_ORDER[(Keys)( --s_key ) % KeysPerOctave] == BlackKey )
|
||||
KEY_ORDER[(Keys)(--s_key) % KeysPerOctave] == Piano::BlackKey )
|
||||
{
|
||||
if( m_piano && m_piano->m_pressedKeys[s_key] == TRUE )
|
||||
if( m_piano && m_piano->m_pressedKeys[s_key] == true )
|
||||
{
|
||||
p.drawPixmap( 0 - PW_WHITE_KEY_WIDTH / 2, PIANO_BASE,
|
||||
*s_blackKeyPressedPm );
|
||||
@@ -956,11 +957,11 @@ void pianoView::paintEvent( QPaintEvent * )
|
||||
// now draw all black keys...
|
||||
for( int x = 0; x < width(); )
|
||||
{
|
||||
if( KEY_ORDER[cur_key%KeysPerOctave] == BlackKey )
|
||||
if( KEY_ORDER[cur_key%KeysPerOctave] == Piano::BlackKey )
|
||||
{
|
||||
// draw pressed or not pressed key, depending on
|
||||
// state of current key
|
||||
if( m_piano && m_piano->m_pressedKeys[cur_key] == TRUE )
|
||||
if( m_piano && m_piano->m_pressedKeys[cur_key] == true )
|
||||
{
|
||||
p.drawPixmap( x + PW_WHITE_KEY_WIDTH / 2,
|
||||
PIANO_BASE,
|
||||
@@ -991,8 +992,5 @@ void pianoView::paintEvent( QPaintEvent * )
|
||||
|
||||
|
||||
|
||||
|
||||
#include "moc_piano.cxx"
|
||||
|
||||
|
||||
#endif
|
||||
|
||||
@@ -904,7 +904,7 @@ void pianoRoll::keyPressEvent( QKeyEvent * _ke )
|
||||
{
|
||||
if( validPattern() && _ke->modifiers() == Qt::NoModifier )
|
||||
{
|
||||
const int key_num = pianoView::getKeyFromKeyEvent( _ke ) +
|
||||
const int key_num = PianoView::getKeyFromKeyEvent( _ke ) +
|
||||
( DefaultOctave - 1 ) * KeysPerOctave;
|
||||
|
||||
if( _ke->isAutoRepeat() == false && key_num > -1 )
|
||||
@@ -1210,7 +1210,7 @@ void pianoRoll::keyReleaseEvent( QKeyEvent * _ke )
|
||||
{
|
||||
if( validPattern() && _ke->modifiers() == Qt::NoModifier )
|
||||
{
|
||||
const int key_num = pianoView::getKeyFromKeyEvent( _ke ) +
|
||||
const int key_num = PianoView::getKeyFromKeyEvent( _ke ) +
|
||||
( DefaultOctave - 1 ) * KeysPerOctave;
|
||||
|
||||
if( _ke->isAutoRepeat() == false && key_num > -1 )
|
||||
|
||||
@@ -92,13 +92,11 @@ const int INSTRUMENT_WINDOW_CACHE_SIZE = 8;
|
||||
// #### IT:
|
||||
instrumentTrack::instrumentTrack( trackContainer * _tc ) :
|
||||
track( InstrumentTrack, _tc ),
|
||||
midiEventProcessor(),
|
||||
MidiEventProcessor(),
|
||||
m_audioPort( tr( "unnamed_track" ) ),
|
||||
m_midiPort( tr( "unnamed_track" ), engine::getMixer()->getMidiClient(),
|
||||
this, this ),
|
||||
m_notes(),
|
||||
m_baseNoteModel( 0, 0, KeysPerOctave * NumOctaves - 1, this,
|
||||
tr( "Base note" ) ),
|
||||
m_volumeModel( DefaultVolume, MinVolume, MaxVolume, 0.1f, this,
|
||||
tr( "Volume" ) ),
|
||||
m_panningModel( DefaultPanning, PanningLeft, PanningRight, 0.1f,
|
||||
@@ -112,8 +110,7 @@ instrumentTrack::instrumentTrack( trackContainer * _tc ) :
|
||||
m_chordCreator( this ),
|
||||
m_piano( this )
|
||||
{
|
||||
m_baseNoteModel.setInitValue( DefaultKey );
|
||||
connect( &m_baseNoteModel, SIGNAL( dataChanged() ),
|
||||
connect( baseNoteModel(), SIGNAL( dataChanged() ),
|
||||
this, SLOT( updateBaseNote() ) );
|
||||
connect( &m_pitchModel, SIGNAL( dataChanged() ),
|
||||
this, SLOT( updatePitch() ) );
|
||||
@@ -537,7 +534,7 @@ void instrumentTrack::updatePitchRange( void )
|
||||
|
||||
int instrumentTrack::masterKey( int _midi_key ) const
|
||||
{
|
||||
int key = m_baseNoteModel.value() - engine::getSong()->masterPitch();
|
||||
int key = baseNoteModel()->value() - engine::getSong()->masterPitch();
|
||||
return tLimit<int>( _midi_key - ( key - DefaultKey ), 0, NumKeys );
|
||||
}
|
||||
|
||||
@@ -703,7 +700,7 @@ void instrumentTrack::saveTrackSpecificSettings( QDomDocument & _doc,
|
||||
m_pitchRangeModel.saveSettings( _doc, _this, "pitchrange" );
|
||||
|
||||
m_effectChannelModel.saveSettings( _doc, _this, "fxch" );
|
||||
m_baseNoteModel.saveSettings( _doc, _this, "basenote" );
|
||||
baseNoteModel()->saveSettings( _doc, _this, "basenote" );
|
||||
|
||||
if( m_instrument != NULL )
|
||||
{
|
||||
@@ -751,14 +748,14 @@ void instrumentTrack::loadTrackSpecificSettings( const QDomElement & _this )
|
||||
if( _this.hasAttribute( "baseoct" ) )
|
||||
{
|
||||
// TODO: move this compat code to mmp.cpp -> upgrade()
|
||||
m_baseNoteModel.setInitValue( _this.
|
||||
baseNoteModel()->setInitValue( _this.
|
||||
attribute( "baseoct" ).toInt()
|
||||
* KeysPerOctave
|
||||
+ _this.attribute( "basetone" ).toInt() );
|
||||
}
|
||||
else
|
||||
{
|
||||
m_baseNoteModel.loadSettings( _this, "basenote" );
|
||||
baseNoteModel()->loadSettings( _this, "basenote" );
|
||||
}
|
||||
|
||||
// clear effect-chain just in case we load an old preset without FX-data
|
||||
@@ -1265,7 +1262,7 @@ instrumentTrackWindow::instrumentTrackWindow( instrumentTrackView * _itv ) :
|
||||
m_tabWidget->addTab( m_midiView, tr( "MIDI" ), 4 );
|
||||
|
||||
// setup piano-widget
|
||||
m_pianoView= new pianoView( this );
|
||||
m_pianoView= new PianoView( this );
|
||||
m_pianoView->setFixedSize( INSTRUMENT_WIDTH, PIANO_HEIGHT );
|
||||
|
||||
vlayout->addWidget( m_generalSettingsWidget );
|
||||
|
||||
Reference in New Issue
Block a user