1 /* This file is part of the KDE project
2  * Copyright 2009 Marijn Kruisselbrink <mkruisselbrink@kde.org>
3  *
4  * This library is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU Library General Public
6  * License as published by the Free Software Foundation; either
7  * version 2 of the License, or (at your option) any later version.
8  *
9  * This library is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12  * Library General Public License for more details.
13  *
14  * You should have received a copy of the GNU Library General Public License
15  * along with this library; see the file COPYING.LIB.  If not, write to
16  * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
17  * Boston, MA 02110-1301, USA.
18  */
19 #include "MusicCursor.h"
20 
21 #include "core/Part.h"
22 #include "core/Sheet.h"
23 #include "core/Staff.h"
24 #include "core/Voice.h"
25 #include "core/VoiceBar.h"
26 
27 using namespace MusicCore;
28 
MusicCursor(Sheet * sheet,QObject * parent)29 MusicCursor::MusicCursor(Sheet* sheet, QObject* parent)
30     : QObject(parent)
31     , m_sheet(sheet)
32     , m_staff(sheet->part(0)->staff(0))
33     , m_voice(0)
34     , m_bar(0)
35     , m_element(0)
36     , m_line(0)
37 {
38 }
39 
moveRight()40 void MusicCursor::moveRight()
41 {
42     m_element++;
43     if (m_element > m_staff->part()->voice(m_voice)->bar(m_sheet->bar(m_bar))->elementCount()) {
44         if (m_bar < m_sheet->barCount()-1) {
45             m_bar++;
46             m_element = 0;
47         }
48     }
49 }
50 
moveLeft()51 void MusicCursor::moveLeft()
52 {
53     m_element--;
54     if (m_element < 0) {
55         if (m_bar == 0) {
56             m_element = 0;
57         } else {
58             m_bar--;
59             m_element = m_staff->part()->voice(m_voice)->bar(m_sheet->bar(m_bar))->elementCount();
60         }
61     }
62 }
63 
moveUp()64 void MusicCursor::moveUp()
65 {
66     m_line++;
67 }
68 
moveDown()69 void MusicCursor::moveDown()
70 {
71     m_line--;
72 }
73 
setVoice(int voice)74 void MusicCursor::setVoice(int voice)
75 {
76     m_voice = voice;
77 }
78 
voiceBar() const79 VoiceBar* MusicCursor::voiceBar() const
80 {
81     return m_staff->part()->voice(m_voice)->bar(m_sheet->bar(m_bar));
82 }
83