2
2
* piano_roll.cpp - implementation of piano-roll which is used for actual
3
3
* writing of melodies
5
* Copyright (c) 2004-2009 Tobias Doerffel <tobydox/at/users.sourceforge.net>
5
* Copyright (c) 2004-2010 Tobias Doerffel <tobydox/at/users.sourceforge.net>
6
6
* Copyright (c) 2008 Andrew Kelley <superjoe30/at/gmail/dot/com>
8
8
* This file is part of Linux MultiMedia Studio - http://lmms.sourceforge.net
721
721
int middle_y = _y + KEY_LINE_HEIGHT / 2;
722
722
_p.setPen( QColor( 0xFF, 0xDF, 0x20 ) );
724
timeMap & map = _n->detuning()->getAutomationPattern()->getTimeMap();
724
timeMap & map = _n->detuning()->automationPattern()->getTimeMap();
725
725
for( timeMap::ConstIterator it = map.begin(); it != map.end(); ++it )
727
727
Sint32 pos_ticks = it.key();
899
899
if( _ke->isAutoRepeat() == false && key_num > -1 )
901
m_pattern->instrumentTrack()->
902
getPiano()->handleKeyPress( key_num );
901
m_pattern->instrumentTrack()->pianoModel()->
902
handleKeyPress( key_num );
1043
1044
case Qt::Key_C:
1044
1045
if( _ke->modifiers() & Qt::ControlModifier )
1046
1048
copySelectedNotes();
1054
1052
case Qt::Key_X:
1055
1053
if( _ke->modifiers() & Qt::ControlModifier )
1057
1056
cutSelectedNotes();
1065
1060
case Qt::Key_V:
1066
1061
if( _ke->modifiers() & Qt::ControlModifier )
1076
1068
case Qt::Key_A:
1077
1069
if( _ke->modifiers() & Qt::ControlModifier )
1079
1072
m_selectButton->setChecked( true );
1089
1078
case Qt::Key_D:
1090
1079
if( _ke->modifiers() & Qt::ShiftModifier )
1092
1082
m_drawButton->setChecked( true );
1100
1086
case Qt::Key_E:
1101
1087
if( _ke->modifiers() & Qt::ShiftModifier )
1103
1090
m_eraseButton->setChecked( true );
1111
1094
case Qt::Key_S:
1112
1095
if( _ke->modifiers() & Qt::ShiftModifier )
1114
1098
m_selectButton->setChecked( true );
1122
1102
case Qt::Key_T:
1123
1103
if( _ke->modifiers() & Qt::ShiftModifier )
1125
1106
m_detuneButton->setChecked( true );
1133
1110
case Qt::Key_Delete:
1134
1111
deleteSelectedNotes();
1137
1115
case Qt::Key_Space:
1167
1147
if( _ke->modifiers() &
1168
1148
( Qt::ControlModifier | Qt::KeypadModifier ) )
1170
m_noteLenModel.setValue( len );
1150
m_noteLenModel.setValue( len );
1172
1153
else if( _ke->modifiers() & Qt::AltModifier )
1174
m_quantizeModel.setValue( len );
1155
m_quantizeModel.setValue( len );
1179
1161
case Qt::Key_Control:
1180
if( m_editMode != ModeSelect )
1182
m_ctrlMode = m_editMode;
1183
m_editMode = ModeSelect;
1184
QApplication::changeOverrideCursor(
1185
QCursor( Qt::ArrowCursor ) );
1162
m_ctrlMode = m_editMode;
1163
m_editMode = ModeSelect;
1164
QApplication::changeOverrideCursor( Qt::ArrowCursor );
1205
1183
if( _ke->isAutoRepeat() == false && key_num > -1 )
1207
m_pattern->instrumentTrack()->
1208
getPiano()->handleKeyRelease( key_num );
1185
m_pattern->instrumentTrack()->pianoModel()->
1186
handleKeyRelease( key_num );
1211
1190
switch( _ke->key() )
1347
1325
const NoteVector & notes = m_pattern->notes();
1349
1327
// will be our iterator in the following loop
1350
NoteVector::ConstIterator it = notes.begin();
1328
NoteVector::ConstIterator it = notes.begin()+notes.size()-1;
1352
1330
// loop through whole note-vector...
1353
while( it != notes.end() )
1331
for( int i = 0; i < notes.size(); ++i )
1355
1333
midiTime len = ( *it )->length();
1394
1372
note * created_new_note = NULL;
1395
1373
// did it reach end of vector because
1396
1374
// there's no note??
1397
if( it == notes.end() )
1375
if( it == notes.begin()-1 )
1400
pattern::MelodyPattern );
1377
m_pattern->setType( pattern::MelodyPattern );
1402
1379
// then set new note
2014
1988
// loop through vector
2015
1989
bool use_selection = isSelection();
2016
NoteVector::ConstIterator it = notes.begin();
2017
while( it != notes.end() )
1990
NoteVector::ConstIterator it = notes.begin()+notes.size()-1;
1991
for( int i = 0; i < notes.size(); ++i )
2019
if( ( *it )->pos().getTicks() >= ticks_start
2020
&& ( *it )->pos().getTicks() <= ticks_end
2021
&& ( *it )->length().getTicks() > 0
2022
&& ( ( *it )->selected() || ! use_selection ) )
1994
if( n->pos().getTicks() >= ticks_start
1995
&& n->pos().getTicks() <= ticks_end
1996
&& n->length().getTicks() != 0
1997
&& ( n->selected() || ! use_selection ) )
2024
1999
m_pattern->dataChanged();
2026
2001
// play the note so that the user can tell how loud it is
2027
2002
// and where it is panned
2028
testPlayNote( *it );
2030
2005
if( m_noteEditMode == NoteEditVolume )
2032
( *it )->setVolume( vol );
2007
n->setVolume( vol );
2033
2008
m_pattern->instrumentTrack()->processInEvent(
2035
2010
MidiKeyPressure,
2038
2013
vol * 127 / 100),
2041
2016
else if( m_noteEditMode == NoteEditPanning )
2043
( *it )->setPanning( pan );
2018
n->setPanning( pan );
2044
2019
midiEvent evt( MidiMetaEvent, 0,
2045
( *it )->key(), panningToMidi( pan ) );
2020
n->key(), panningToMidi( pan ) );
2046
2021
evt.m_metaEvent = MidiNotePanning;
2047
2022
m_pattern->instrumentTrack()->processInEvent(
2048
2023
evt, midiTime() );
2053
if( ( *it )->isPlaying() )
2028
if( n->isPlaying() )
2055
2030
// mouse not over this note, stop playing it.
2056
2031
m_pattern->instrumentTrack()->processInEvent(
2057
2032
midiEvent( MidiNoteOff, 0,
2058
( *it )->key(), 0 ), midiTime() );
2033
n->key(), 0 ), midiTime() );
2060
( *it )->setIsPlaying( false );
2035
n->setIsPlaying( false );
2077
2052
const NoteVector & notes = m_pattern->notes();
2079
2054
// will be our iterator in the following loop
2080
NoteVector::ConstIterator it = notes.begin();
2055
NoteVector::ConstIterator it = notes.begin()+notes.size()-1;
2082
2057
// loop through whole note-vector...
2083
while( it != notes.end() )
2058
for( int i = 0; i < notes.size(); ++i )
2085
2060
// and check whether the cursor is over an
2086
2061
// existing note
3591
3566
midiTime::ticksPerTact() / m_ppt + m_currentPosition;
3593
3568
// will be our iterator in the following loop
3594
NoteVector::ConstIterator it = notes.begin();
3569
NoteVector::ConstIterator it = notes.begin()+notes.size()-1;
3596
3571
// loop through whole note-vector...
3597
while( it != notes.end() )
3573
for( i = 0; i < notes.size(); ++i )
3599
3575
// and check whether the cursor is over an
3600
3576
// existing note