From 558ef8bde3fc499f6b2a62c4641a03a5070374a9 Mon Sep 17 00:00:00 2001 From: Martin Pavelek Date: Tue, 17 Dec 2019 21:37:34 +0100 Subject: [PATCH] Extend LMMS note range to match MIDI specification (fixes #1857) --- data/projects/templates/default.mpt | 4 +- include/Note.h | 10 +++-- include/lmms_constants.h | 43 ++++++++++++++++++ plugins/MidiExport/MidiExport.cpp | 6 +-- plugins/MidiImport/MidiImport.cpp | 2 +- src/core/midi/MidiAlsaSeq.cpp | 15 +++---- src/core/midi/MidiApple.cpp | 26 +++++------ src/core/midi/MidiClient.cpp | 31 +++++++------ src/core/midi/MidiWinMM.cpp | 13 +++--- src/gui/PianoView.cpp | 42 +++++++++--------- src/gui/editors/PianoRoll.cpp | 69 +++++++++++++---------------- src/tracks/InstrumentTrack.cpp | 3 +- 12 files changed, 142 insertions(+), 122 deletions(-) diff --git a/data/projects/templates/default.mpt b/data/projects/templates/default.mpt index bebd41fe3bb..680f89c470b 100644 --- a/data/projects/templates/default.mpt +++ b/data/projects/templates/default.mpt @@ -5,7 +5,7 @@ - + @@ -29,7 +29,7 @@ - + diff --git a/include/Note.h b/include/Note.h index 0eae8f6b05c..4673a7b36ec 100644 --- a/include/Note.h +++ b/include/Note.h @@ -55,6 +55,7 @@ enum Keys enum Octaves { + Octave_m1, // MIDI standard starts at C-1 Octave_0, Octave_1, Octave_2, @@ -64,15 +65,16 @@ enum Octaves Octave_6, Octave_7, Octave_8, + Octave_9, // incomplete octave, MIDI only goes up to G9 NumOctaves -} ; - +}; +const int FirstOctave = -1; const int WhiteKeysPerOctave = 7; const int BlackKeysPerOctave = 5; const int KeysPerOctave = WhiteKeysPerOctave + BlackKeysPerOctave; -const int NumKeys = NumOctaves * KeysPerOctave; -const int DefaultKey = DefaultOctave*KeysPerOctave + Key_A; +const int NumKeys = qMin(NumOctaves * KeysPerOctave, 128); // limited to MIDI range +const int DefaultKey = DefaultOctave * KeysPerOctave + Key_A; const float MaxDetuning = 4 * 12.0f; diff --git a/include/lmms_constants.h b/include/lmms_constants.h index befa789dd5c..b775d9895fc 100644 --- a/include/lmms_constants.h +++ b/include/lmms_constants.h @@ -49,4 +49,47 @@ const float F_PI_SQR = (float) LD_PI_SQR; const float F_E = (float) LD_E; const float F_E_R = (float) LD_E_R; +// Frequency ranges (in Hz). +// Arbitrary low limit for logarithmic frequency scale; >1 Hz. +const int LOWEST_LOG_FREQ = 5; + +// Full range is defined by LOWEST_LOG_FREQ and current sample rate. +enum FREQUENCY_RANGES +{ + FRANGE_FULL = 0, + FRANGE_AUDIBLE, + FRANGE_BASS, + FRANGE_MIDS, + FRANGE_HIGH +}; + +const int FRANGE_AUDIBLE_START = 20; +const int FRANGE_AUDIBLE_END = 20000; +const int FRANGE_BASS_START = 20; +const int FRANGE_BASS_END = 300; +const int FRANGE_MIDS_START = 200; +const int FRANGE_MIDS_END = 5000; +const int FRANGE_HIGH_START = 4000; +const int FRANGE_HIGH_END = 20000; + +// Amplitude ranges (in dBFS). +// Reference: full scale sine wave (-1.0 to 1.0) is 0 dB. +// Doubling or halving the amplitude produces 3 dB difference. +enum AMPLITUDE_RANGES +{ + ARANGE_EXTENDED = 0, + ARANGE_AUDIBLE, + ARANGE_LOUD, + ARANGE_SILENT +}; + +const int ARANGE_EXTENDED_START = -80; +const int ARANGE_EXTENDED_END = 20; +const int ARANGE_AUDIBLE_START = -50; +const int ARANGE_AUDIBLE_END = 0; +const int ARANGE_LOUD_START = -30; +const int ARANGE_LOUD_END = 0; +const int ARANGE_SILENT_START = -60; +const int ARANGE_SILENT_END = -10; + #endif diff --git a/plugins/MidiExport/MidiExport.cpp b/plugins/MidiExport/MidiExport.cpp index 1860527c10e..4c4e31c8a98 100644 --- a/plugins/MidiExport/MidiExport.cpp +++ b/plugins/MidiExport/MidiExport.cpp @@ -129,8 +129,7 @@ bool MidiExport::tryExport(const TrackContainer::TrackList &tracks, if (n.nodeName() == "instrumenttrack") { QDomElement it = n.toElement(); - // transpose +12 semitones, workaround for #1857 - base_pitch = (69 - it.attribute("basenote", "57").toInt()); + base_pitch = (69 - it.attribute("basenote", "69").toInt()); if (it.attribute("usemasterpitch", "1").toInt()) { base_pitch += masterPitch; @@ -200,8 +199,7 @@ bool MidiExport::tryExport(const TrackContainer::TrackList &tracks, if (n.nodeName() == "instrumenttrack") { QDomElement it = n.toElement(); - // transpose +12 semitones, workaround for #1857 - base_pitch = (69 - it.attribute("basenote", "57").toInt()); + base_pitch = (69 - it.attribute("basenote", "69").toInt()); if (it.attribute("usemasterpitch", "1").toInt()) { base_pitch += masterPitch; diff --git a/plugins/MidiImport/MidiImport.cpp b/plugins/MidiImport/MidiImport.cpp index e31c2450826..e6f2669217f 100644 --- a/plugins/MidiImport/MidiImport.cpp +++ b/plugins/MidiImport/MidiImport.cpp @@ -427,7 +427,7 @@ bool MidiImport::readSMF( TrackContainer* tc ) int ticks = noteEvt->get_duration() * ticksPerBeat; Note n( (ticks < 1 ? 1 : ticks ), noteEvt->get_start_time() * ticksPerBeat, - noteEvt->get_identifier() - 12, + noteEvt->get_identifier(), noteEvt->get_loud() * (200.f / 127.f)); // Map from MIDI velocity to LMMS volume ch->addNote( n ); diff --git a/src/core/midi/MidiAlsaSeq.cpp b/src/core/midi/MidiAlsaSeq.cpp index e420ebc084c..ee51985b4c6 100644 --- a/src/core/midi/MidiAlsaSeq.cpp +++ b/src/core/midi/MidiAlsaSeq.cpp @@ -176,21 +176,21 @@ void MidiAlsaSeq::processOutEvent( const MidiEvent& event, const MidiTime& time, case MidiNoteOn: snd_seq_ev_set_noteon( &ev, event.channel(), - event.key() + KeysPerOctave, + event.key(), event.velocity() ); break; case MidiNoteOff: snd_seq_ev_set_noteoff( &ev, event.channel(), - event.key() + KeysPerOctave, + event.key(), event.velocity() ); break; case MidiKeyPressure: snd_seq_ev_set_keypress( &ev, event.channel(), - event.key() + KeysPerOctave, + event.key(), event.velocity() ); break; @@ -531,8 +531,7 @@ void MidiAlsaSeq::run() case SND_SEQ_EVENT_NOTEON: dest->processInEvent( MidiEvent( MidiNoteOn, ev->data.note.channel, - ev->data.note.note - - KeysPerOctave, + ev->data.note.note, ev->data.note.velocity, source ), @@ -542,8 +541,7 @@ void MidiAlsaSeq::run() case SND_SEQ_EVENT_NOTEOFF: dest->processInEvent( MidiEvent( MidiNoteOff, ev->data.note.channel, - ev->data.note.note - - KeysPerOctave, + ev->data.note.note, ev->data.note.velocity, source ), @@ -554,8 +552,7 @@ void MidiAlsaSeq::run() dest->processInEvent( MidiEvent( MidiKeyPressure, ev->data.note.channel, - ev->data.note.note - - KeysPerOctave, + ev->data.note.note, ev->data.note.velocity, source ), MidiTime() ); diff --git a/src/core/midi/MidiApple.cpp b/src/core/midi/MidiApple.cpp index f4bc0d4dd97..bc6ef7356e4 100644 --- a/src/core/midi/MidiApple.cpp +++ b/src/core/midi/MidiApple.cpp @@ -318,28 +318,24 @@ void MidiApple::HandleReadCallback( const MIDIPacketList *pktlist, void *srcConn } unsigned char messageChannel = status & 0xF; - const MidiEventTypes cmdtype = static_cast( status & 0xF0 ); + const MidiEventTypes cmdtype = static_cast(status & 0xF0); const int par1 = packet->data[iByte + 1]; const int par2 = packet->data[iByte + 2]; switch (cmdtype) { - case MidiNoteOff: //0x80: - case MidiNoteOn: //0x90: - case MidiKeyPressure: //0xA0: - notifyMidiPortList(m_inputSubs[refName],MidiEvent( cmdtype, messageChannel, par1 - KeysPerOctave, par2 & 0xff, &endPointRef )); + case MidiNoteOff: //0x80: + case MidiNoteOn: //0x90: + case MidiKeyPressure: //0xA0: + case MidiControlChange: //0xB0: + case MidiProgramChange: //0xC0: + case MidiChannelPressure: //0xD0: + notifyMidiPortList(m_inputSubs[refName], MidiEvent(cmdtype, messageChannel, par1, par2 & 0xff, &endPointRef)); break; - - case MidiControlChange: //0xB0: - case MidiProgramChange: //0xC0: - case MidiChannelPressure: //0xD0: - notifyMidiPortList(m_inputSubs[refName],MidiEvent( cmdtype, messageChannel, par1, par2 & 0xff, &endPointRef )); + case MidiPitchBend: //0xE0: + notifyMidiPortList(m_inputSubs[refName], MidiEvent(cmdtype, messageChannel, par1 + par2 * 128, 0, &endPointRef)); break; - - case MidiPitchBend: //0xE0: - notifyMidiPortList(m_inputSubs[refName],MidiEvent( cmdtype, messageChannel, par1 + par2 * 128, 0, &endPointRef )); - break; - case MidiActiveSensing: //0xF0 + case MidiActiveSensing: //0xF0 case 0xF0: break; default: diff --git a/src/core/midi/MidiClient.cpp b/src/core/midi/MidiClient.cpp index 03eec4e388e..bc646e86567 100644 --- a/src/core/midi/MidiClient.cpp +++ b/src/core/midi/MidiClient.cpp @@ -214,30 +214,30 @@ void MidiClientRaw::parseData( const unsigned char c ) * We simply keep the status as it is, just reset the parameter counter. * If another status byte comes in, it will overwrite the status. */ - m_midiParseData.m_midiEvent.setType( static_cast( m_midiParseData.m_status ) ); - m_midiParseData.m_midiEvent.setChannel( m_midiParseData.m_channel ); + m_midiParseData.m_midiEvent.setType(static_cast(m_midiParseData.m_status)); + m_midiParseData.m_midiEvent.setChannel(m_midiParseData.m_channel); m_midiParseData.m_bytes = 0; /* Related to running status! */ - switch( m_midiParseData.m_midiEvent.type() ) + switch(m_midiParseData.m_midiEvent.type()) { case MidiNoteOff: case MidiNoteOn: case MidiKeyPressure: - case MidiProgramChange: case MidiChannelPressure: - m_midiParseData.m_midiEvent.setKey( m_midiParseData.m_buffer[0] - KeysPerOctave ); - m_midiParseData.m_midiEvent.setVelocity( m_midiParseData.m_buffer[1] ); + case MidiProgramChange: + m_midiParseData.m_midiEvent.setKey(m_midiParseData.m_buffer[0]); + m_midiParseData.m_midiEvent.setVelocity(m_midiParseData.m_buffer[1]); break; case MidiControlChange: - m_midiParseData.m_midiEvent.setControllerNumber( m_midiParseData.m_buffer[0] ); - m_midiParseData.m_midiEvent.setControllerValue( m_midiParseData.m_buffer[1] ); + m_midiParseData.m_midiEvent.setControllerNumber(m_midiParseData.m_buffer[0]); + m_midiParseData.m_midiEvent.setControllerValue( m_midiParseData.m_buffer[1]); break; case MidiPitchBend: // Pitch-bend is transmitted with 14-bit precision. // Note: '|' does here the same as '+' (no common bits), // but might be faster - m_midiParseData.m_midiEvent.setPitchBend( ( m_midiParseData.m_buffer[1] * 128 ) | m_midiParseData.m_buffer[0] ); + m_midiParseData.m_midiEvent.setPitchBend((m_midiParseData.m_buffer[1] * 128) | m_midiParseData.m_buffer[0]); break; default: @@ -262,22 +262,21 @@ void MidiClientRaw::processParsedEvent() -void MidiClientRaw::processOutEvent( const MidiEvent& event, const MidiTime & , const MidiPort* port ) +void MidiClientRaw::processOutEvent(const MidiEvent& event, const MidiTime &, const MidiPort* port) { // TODO: also evaluate _time and queue event if necessary - switch( event.type() ) + switch(event.type()) { case MidiNoteOn: case MidiNoteOff: case MidiKeyPressure: - sendByte( event.type() | event.channel() ); - sendByte( event.key() + KeysPerOctave ); - sendByte( event.velocity() ); + sendByte(event.type() | event.channel()); + sendByte(event.key()); + sendByte(event.velocity()); break; default: - qWarning( "MidiClientRaw: unhandled MIDI-event %d\n", - (int) event.type() ); + qWarning("MidiClientRaw: unhandled MIDI-event %d\n", (int)event.type()); break; } } diff --git a/src/core/midi/MidiWinMM.cpp b/src/core/midi/MidiWinMM.cpp index ef60f30153b..3bf9c47c175 100644 --- a/src/core/midi/MidiWinMM.cpp +++ b/src/core/midi/MidiWinMM.cpp @@ -201,28 +201,25 @@ void MidiWinMM::handleInputEvent( HMIDIIN hm, DWORD ev ) } const MidiPortList & l = m_inputSubs[d]; - for( MidiPortList::ConstIterator it = l.begin(); it != l.end(); ++it ) + for (MidiPortList::ConstIterator it = l.begin(); it != l.end(); ++it) { - switch( cmdtype ) + switch(cmdtype) { case MidiNoteOn: case MidiNoteOff: case MidiKeyPressure: - ( *it )->processInEvent( MidiEvent( cmdtype, chan, par1 - KeysPerOctave, par2 & 0xff, &hm ) ); - break; - case MidiControlChange: case MidiProgramChange: case MidiChannelPressure: - ( *it )->processInEvent( MidiEvent( cmdtype, chan, par1, par2 & 0xff, &hm ) ); + (*it)->processInEvent(MidiEvent(cmdtype, chan, par1, par2 & 0xff, &hm)); break; case MidiPitchBend: - ( *it )->processInEvent( MidiEvent( cmdtype, chan, par1 + par2*128, 0, &hm ) ); + (*it)->processInEvent(MidiEvent(cmdtype, chan, par1 + par2 * 128, 0, &hm)); break; default: - qWarning( "MidiWinMM: unhandled input event %d\n", cmdtype ); + qWarning("MidiWinMM: unhandled input event %d\n", cmdtype); break; } } diff --git a/src/gui/PianoView.cpp b/src/gui/PianoView.cpp index c1be922c656..94d1d6ab20b 100644 --- a/src/gui/PianoView.cpp +++ b/src/gui/PianoView.cpp @@ -107,9 +107,9 @@ PianoView::PianoView( QWidget * _parent ) : s_blackKeyPressedPm = new QPixmap( embed::getIconPixmap( "black_key_pressed" ) ); } - setAttribute( Qt::WA_OpaquePaintEvent, true ); - setFocusPolicy( Qt::StrongFocus ); - setMaximumWidth( WhiteKeysPerOctave * NumOctaves * PW_WHITE_KEY_WIDTH ); + setAttribute(Qt::WA_OpaquePaintEvent, true); + setFocusPolicy(Qt::StrongFocus); + setMaximumWidth(WhiteKeysPerOctave * NumKeys * PW_WHITE_KEY_WIDTH / KeysPerOctave); // create scrollbar at the bottom m_pianoScroll = new QScrollBar( Qt::Horizontal, this ); @@ -684,14 +684,13 @@ void PianoView::focusOutEvent( QFocusEvent * ) * After resizing we need to adjust range of scrollbar for not allowing * to scroll too far to the right. * - * \param _event resize-event object (unused) + * \param event resize-event object (unused) */ -void PianoView::resizeEvent( QResizeEvent * _event ) +void PianoView::resizeEvent(QResizeEvent* event) { - QWidget::resizeEvent( _event ); - m_pianoScroll->setRange( 0, WhiteKeysPerOctave * NumOctaves - - (int) ceil( (float) width() / - PW_WHITE_KEY_WIDTH ) ); + QWidget::resizeEvent(event); + m_pianoScroll->setRange(0, WhiteKeysPerOctave * (NumKeys + 1) / KeysPerOctave - + (int)ceil((float)width() / PW_WHITE_KEY_WIDTH)); } @@ -819,13 +818,11 @@ void PianoView::paintEvent( QPaintEvent * ) x += PW_WHITE_KEY_WIDTH; - if( (Keys) (cur_key%KeysPerOctave) == Key_C ) + if ((Keys)(cur_key % KeysPerOctave) == Key_C) { - // label key of note C with "C" and number of current - // octave - p.drawText( x - PW_WHITE_KEY_WIDTH, LABEL_TEXT_SIZE + 2, - QString( "C" ) + QString::number( - cur_key / KeysPerOctave, 10 ) ); + // label key of note C with "C" and number of current octave + p.drawText(x - PW_WHITE_KEY_WIDTH, LABEL_TEXT_SIZE + 2, + QString("C") + QString::number(FirstOctave + cur_key / KeysPerOctave)); } ++cur_key; } @@ -849,19 +846,19 @@ void PianoView::paintEvent( QPaintEvent * ) } // now draw all black keys... - for( int x = 0; x < width(); ) + for (int x = 0; x < width();) { - if( Piano::isBlackKey( cur_key ) ) + if (Piano::isBlackKey(cur_key)) { // draw pressed or not pressed key, depending on // state of current key - if( m_piano && m_piano->isKeyPressed( cur_key ) ) + if (m_piano && m_piano->isKeyPressed(cur_key)) { - p.drawPixmap( x + PW_WHITE_KEY_WIDTH / 2, PIANO_BASE, *s_blackKeyPressedPm ); + p.drawPixmap(x + PW_WHITE_KEY_WIDTH / 2, PIANO_BASE, *s_blackKeyPressedPm); } else { - p.drawPixmap( x + PW_WHITE_KEY_WIDTH / 2, PIANO_BASE, *s_blackKeyPm ); + p.drawPixmap(x + PW_WHITE_KEY_WIDTH / 2, PIANO_BASE, *s_blackKeyPm); } x += PW_WHITE_KEY_WIDTH; white_cnt = 0; @@ -871,12 +868,13 @@ void PianoView::paintEvent( QPaintEvent * ) // simple workaround for increasing x if there were two // white keys (e.g. between E and F) ++white_cnt; - if( white_cnt > 1 ) + if (white_cnt > 1) { x += PW_WHITE_KEY_WIDTH; } } - ++cur_key; + // stop drawing when all keys are drawn, even if an extra black key could fit + if (++cur_key == NumKeys) {break;} } } diff --git a/src/gui/editors/PianoRoll.cpp b/src/gui/editors/PianoRoll.cpp index 5edc5d47c84..12aff16c4c0 100644 --- a/src/gui/editors/PianoRoll.cpp +++ b/src/gui/editors/PianoRoll.cpp @@ -121,11 +121,11 @@ QPixmap * PianoRoll::s_toolOpen = NULL; TextFloat * PianoRoll::s_textFloat = NULL; -static QString s_noteStrings[12] = { "C", "C#", "D", "D#", "E", "F", "F#", "G", "G#", "A", "A#", "B"}; +static QString s_noteStrings[12] = {"C", "C#", "D", "D#", "E", "F", "F#", "G", "G#", "A", "A#", "B"}; -static QString getNoteString( int key ) +static QString getNoteString(int key) { - return s_noteStrings[key % 12] + QString::number( static_cast( key / KeysPerOctave ) ); + return s_noteStrings[key % 12] + QString::number(static_cast(FirstOctave + key / KeysPerOctave)); } @@ -705,11 +705,10 @@ void PianoRoll::setCurrentPattern( Pattern* newPattern ) } } - if( total_notes > 0 ) + if (total_notes > 0) { - central_key = central_key / total_notes - - ( KeysPerOctave * NumOctaves - m_totalKeysToScroll ) / 2; - m_startKey = qBound( 0, central_key, NumOctaves * KeysPerOctave ); + central_key = central_key / total_notes - (NumKeys - m_totalKeysToScroll) / 2; + m_startKey = qBound(0, central_key, NumKeys); } // resizeEvent() does the rest for us (scrolling, range-checking @@ -2915,7 +2914,7 @@ void PianoRoll::paintEvent(QPaintEvent * pe ) int yCorrectionForNoteLabels = 0; int keyCode = key % KeysPerOctave; - switch( keyCode ) + switch (keyCode) { case 0: case 5: @@ -2932,6 +2931,9 @@ void PianoRoll::paintEvent(QPaintEvent * pe ) break; } + // override for the last MIDI key (G9) + if (key == NumKeys - 1) {yCorrectionForNoteLabels = 2;} + if( Piano::isWhiteKey( key ) ) { // Draw note names if activated in the preferences, C notes are always drawn @@ -2939,7 +2941,7 @@ void PianoRoll::paintEvent(QPaintEvent * pe ) { QString noteString = getNoteString( key ); - QPoint textStart( WHITE_KEY_WIDTH - 18, key_line_y ); + QPoint textStart( WHITE_KEY_WIDTH - 20, key_line_y ); textStart += QPoint( 0, yCorrectionForNoteLabels ); p.setPen( textShadow() ); @@ -3447,33 +3449,29 @@ void PianoRoll::paintEvent(QPaintEvent * pe ) // responsible for moving/resizing scrollbars after window-resizing -void PianoRoll::resizeEvent(QResizeEvent * re) +void PianoRoll::resizeEvent(QResizeEvent* re) { - m_leftRightScroll->setGeometry( WHITE_KEY_WIDTH, - height() - - SCROLLBAR_SIZE, - width()-WHITE_KEY_WIDTH, - SCROLLBAR_SIZE ); - m_topBottomScroll->setGeometry( width() - SCROLLBAR_SIZE, PR_TOP_MARGIN, - SCROLLBAR_SIZE, - height() - PR_TOP_MARGIN - - SCROLLBAR_SIZE ); + m_leftRightScroll->setGeometry(WHITE_KEY_WIDTH, + height() - SCROLLBAR_SIZE, + width() - WHITE_KEY_WIDTH, + SCROLLBAR_SIZE); + m_topBottomScroll->setGeometry(width() - SCROLLBAR_SIZE, + PR_TOP_MARGIN, + SCROLLBAR_SIZE, + height() - PR_TOP_MARGIN - SCROLLBAR_SIZE); - int total_pixels = OCTAVE_HEIGHT * NumOctaves - ( height() - - PR_TOP_MARGIN - PR_BOTTOM_MARGIN - - m_notesEditHeight ); - m_totalKeysToScroll = total_pixels * KeysPerOctave / OCTAVE_HEIGHT; + int visible_space = height() - PR_TOP_MARGIN - PR_BOTTOM_MARGIN - m_notesEditHeight; + m_totalKeysToScroll = NumKeys - 1 - visible_space / KEY_LINE_HEIGHT; - m_topBottomScroll->setRange( 0, m_totalKeysToScroll ); + m_topBottomScroll->setRange(0, m_totalKeysToScroll); - if( m_startKey > m_totalKeysToScroll ) + if (m_startKey > m_totalKeysToScroll) { m_startKey = m_totalKeysToScroll; } - m_topBottomScroll->setValue( m_totalKeysToScroll - m_startKey ); + m_topBottomScroll->setValue(m_totalKeysToScroll - m_startKey); - Engine::getSong()->getPlayPos( Song::Mode_PlayPattern - ).m_timeLine->setFixedWidth( width() ); + Engine::getSong()->getPlayPos(Song::Mode_PlayPattern).m_timeLine->setFixedWidth(width()); update(); } @@ -3639,23 +3637,16 @@ void PianoRoll::focusOutEvent( QFocusEvent * ) -int PianoRoll::getKey(int y ) const +int PianoRoll::getKey(int y) const { int key_line_y = keyAreaBottom() - 1; // pressed key on piano - int key_num = ( key_line_y - y ) / KEY_LINE_HEIGHT; + int key_num = (key_line_y - y) / KEY_LINE_HEIGHT; key_num += m_startKey; // some range-checking-stuff - if( key_num < 0 ) - { - key_num = 0; - } - - if( key_num >= KeysPerOctave * NumOctaves ) - { - key_num = KeysPerOctave * NumOctaves - 1; - } + if (key_num < 0) {key_num = 0;} + if (key_num >= NumKeys) {key_num = NumKeys - 1;} return key_num; } diff --git a/src/tracks/InstrumentTrack.cpp b/src/tracks/InstrumentTrack.cpp index 607131be015..119958aef5d 100644 --- a/src/tracks/InstrumentTrack.cpp +++ b/src/tracks/InstrumentTrack.cpp @@ -97,8 +97,7 @@ InstrumentTrack::InstrumentTrack( TrackContainer* tc ) : m_sustainPedalPressed( false ), m_silentBuffersProcessed( false ), m_previewMode( false ), - m_baseNoteModel( 0, 0, KeysPerOctave * NumOctaves - 1, this, - tr( "Base note" ) ), + m_baseNoteModel(0, 0, NumKeys - 1, this, tr("Base note")), m_volumeModel( DefaultVolume, MinVolume, MaxVolume, 0.1f, this, tr( "Volume" ) ), m_panningModel( DefaultPanning, PanningLeft, PanningRight, 0.1f, this, tr( "Panning" ) ), m_audioPort( tr( "unnamed_track" ), true, &m_volumeModel, &m_panningModel, &m_mutedModel ),