File indexing completed on 2024-05-12 16:34:15

0001 /* This file is part of the KDE project
0002  * Copyright 2009 Marijn Kruisselbrink <mkruisselbrink@kde.org>
0003  *
0004  * This library is free software; you can redistribute it and/or
0005  * modify it under the terms of the GNU Library General Public
0006  * License as published by the Free Software Foundation; either
0007  * version 2 of the License, or (at your option) any later version.
0008  *
0009  * This library is distributed in the hope that it will be useful,
0010  * but WITHOUT ANY WARRANTY; without even the implied warranty of
0011  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
0012  * Library General Public License for more details.
0013  *
0014  * You should have received a copy of the GNU Library General Public License
0015  * along with this library; see the file COPYING.LIB.  If not, write to
0016  * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
0017  * Boston, MA 02110-1301, USA.
0018  */
0019 #include "MusicCursor.h"
0020 
0021 #include "core/Part.h"
0022 #include "core/Sheet.h"
0023 #include "core/Staff.h"
0024 #include "core/Voice.h"
0025 #include "core/VoiceBar.h"
0026 
0027 using namespace MusicCore;
0028 
0029 MusicCursor::MusicCursor(Sheet* sheet, QObject* parent)
0030     : QObject(parent)
0031     , m_sheet(sheet)
0032     , m_staff(sheet->part(0)->staff(0))
0033     , m_voice(0)
0034     , m_bar(0)
0035     , m_element(0)
0036     , m_line(0)
0037 {
0038 }
0039 
0040 void MusicCursor::moveRight()
0041 {
0042     m_element++;
0043     if (m_element > m_staff->part()->voice(m_voice)->bar(m_sheet->bar(m_bar))->elementCount()) {
0044         if (m_bar < m_sheet->barCount()-1) {
0045             m_bar++;
0046             m_element = 0;
0047         }
0048     }
0049 }
0050 
0051 void MusicCursor::moveLeft()
0052 {
0053     m_element--;
0054     if (m_element < 0) {
0055         if (m_bar == 0) {
0056             m_element = 0;
0057         } else {
0058             m_bar--;
0059             m_element = m_staff->part()->voice(m_voice)->bar(m_sheet->bar(m_bar))->elementCount();
0060         }
0061     }
0062 }
0063 
0064 void MusicCursor::moveUp()
0065 {
0066     m_line++;
0067 }
0068 
0069 void MusicCursor::moveDown()
0070 {
0071     m_line--;
0072 }
0073 
0074 void MusicCursor::setVoice(int voice)
0075 {
0076     m_voice = voice;
0077 }
0078 
0079 VoiceBar* MusicCursor::voiceBar() const
0080 {
0081     return m_staff->part()->voice(m_voice)->bar(m_sheet->bar(m_bar));
0082 }