Files
lmms/plugins/live_tool/live_tool.cpp
Tobias Doerffel 32a3b7cf23 made live-tool work after M/V-split
git-svn-id: https://lmms.svn.sf.net/svnroot/lmms/branches/lmms-mv@704 0778d3d1-df1d-0410-868b-ea421aaaa00d
2008-02-25 11:37:21 +00:00

213 lines
3.8 KiB
C++

/*
* live_tool.cpp - tool for live performance
*
* Copyright (c) 2006-2007 Javier Serrano Polo <jasp00/at/users.sourceforge.net>
*
* 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 "live_tool.h"
#include <QtGui/QKeyEvent>
#include <QtGui/QLayout>
#include "bb_editor.h"
#include "engine.h"
#include "song.h"
#ifdef Q_WS_X11
#include <X11/Xlib.h>
#endif
#undef SINGLE_SOURCE_COMPILE
#include "embed.cpp"
extern "C"
{
plugin::descriptor live_tool_plugin_descriptor =
{
STRINGIFY_PLUGIN_NAME( PLUGIN_NAME ),
"LiveTool",
QT_TRANSLATE_NOOP( "pluginBrowser",
"Tool for live performance" ),
"Javier Serrano Polo <jasp00/at/users.sourceforge.net>",
0x0100,
plugin::Tool,
new QPixmap( PLUGIN_NAME::getIconPixmap( "logo" ) ),
NULL
} ;
// neccessary for getting instance out of shared lib
plugin * lmms_plugin_main( model * _parent, void * _data )
{
return( new liveTool( _parent ) );
}
}
liveTool::liveTool( model * _parent ) :
tool( &live_tool_plugin_descriptor, _parent )
{
}
liveTool::~liveTool()
{
}
QString liveTool::nodeName( void ) const
{
return( live_tool_plugin_descriptor.name );
}
liveToolView::liveToolView( tool * _tool ) :
toolView( _tool )
{
const QPixmap background = PLUGIN_NAME::getIconPixmap( "artwork" );
setAutoFillBackground( TRUE );
QPalette pal;
pal.setBrush( backgroundRole(), background );
setPalette( pal );
setFixedSize( background.size() );
setWhatsThis( tr(
"This tool is intended to be used in live performances, though "
"you can use it for music production as well.\n"
"The following keys will work only if this window is active.\n"
"The spacebar toggles play and pause in the Song Editor.\n"
"F1-F10 keys mute the first 10 instruments in the "
"Beat+Baseline Editor." ) );
hide();
if( parentWidget() )
{
parentWidget()->hide();
parentWidget()->layout()->setSizeConstraint(
QLayout::SetFixedSize );
}
}
liveToolView::~liveToolView()
{
}
void liveToolView::keyPressEvent( QKeyEvent * _ke )
{
switch( _ke->key() )
{
case Qt::Key_Space:
if( engine::getSong()->playing() )
{
engine::getSong()->pause();
}
else if( engine::getSong()->paused() &&
engine::getSong()->playMode() ==
song::Mode_PlaySong )
{
engine::getSong()->resumeFromPause();
}
else
{
engine::getSong()->play();
}
break;
default:
_ke->ignore();
break;
}
}
void liveToolView::mousePressEvent( QMouseEvent * _me )
{
// MDI window gets focus otherwise
setFocus();
_me->accept();
}
#ifdef Q_WS_X11
bool liveToolView::x11Event( XEvent * _xe )
{
if( _xe->type == KeyPress )
{
unsigned keycode = _xe->xkey.keycode;
// F1 to F10
if( 67 <= keycode && keycode <= 76 )
{
toggleInstrument( keycode - 67 );
return( TRUE );
}
}
return( FALSE );
}
#endif
void liveToolView::toggleInstrument( int _n )
{
if( _n < engine::getBBTrackContainer()->tracks().count() )
{
track * t = engine::getBBTrackContainer()->tracks().at( _n );
t->setMuted( !t->muted() );
}
}
#include "live_tool.moc"