1 //=============================================================================
2 //  MuseScore
3 //  Music Composition & Notation
4 //
5 //  Copyright (C) 2002-2011 Werner Schweer
6 //
7 //  This program is free software; you can redistribute it and/or modify
8 //  it under the terms of the GNU General Public License version 2
9 //  as published by the Free Software Foundation and appearing in
10 //  the file LICENCE.GPL
11 //=============================================================================
12 
13 #ifndef __INPUT_H__
14 #define __INPUT_H__
15 
16 #include "mscore.h"
17 #include "durationtype.h"
18 #include "beam.h"
19 
20 namespace Ms {
21 
22 class Element;
23 class Slur;
24 class ChordRest;
25 class Drumset;
26 class Segment;
27 class Score;
28 class Selection;
29 
30 //---------------------------------------------------------
31 //   NoteEntryMethod
32 //---------------------------------------------------------
33 
34 enum class NoteEntryMethod : char {
35       STEPTIME, REPITCH, RHYTHM, REALTIME_AUTO, REALTIME_MANUAL, TIMEWISE
36       };
37 
38 //---------------------------------------------------------
39 //   InputState
40 //---------------------------------------------------------
41 
42 class InputState {
43       TDuration   _duration    { TDuration::DurationType::V_INVALID };  // currently duration
44       int         _drumNote    { -1 };
45       int         _track       { 0 };
46       int         _prevTrack   { 0 };                       // used for navigation
47       Segment*    _lastSegment { 0 };
48       Segment*    _segment     { 0 };                       // current segment
49       int         _string      { VISUAL_STRING_NONE };      // visual string selected for input (TAB staves only)
50       bool _rest               { false };              // rest mode
51       NoteType _noteType       { NoteType::NORMAL };
52       Beam::Mode _beamMode       { Beam::Mode::AUTO };
53       bool _noteEntryMode      { false };
54       NoteEntryMethod _noteEntryMethod { NoteEntryMethod::STEPTIME };
55       AccidentalType _accidentalType { AccidentalType::NONE };
56       Slur* _slur              { 0     };
57       bool _insertMode         { false };
58 
59       Segment* nextInputPos() const;
60 
61    public:
62       ChordRest* cr() const;
63 
64       Fraction tick() const;
65 
setDuration(const TDuration & d)66       void setDuration(const TDuration& d) { _duration = d;          }
duration()67       TDuration duration() const           { return _duration;       }
68       void setDots(int n);
ticks()69       Fraction ticks() const               { return _duration.ticks(); }
70 
segment()71       Segment* segment() const            { return _segment;        }
72       void setSegment(Segment* s);
73 
lastSegment()74       Segment* lastSegment() const        { return _lastSegment;        }
setLastSegment(Segment * s)75       void setLastSegment(Segment* s)     { _lastSegment = s;           }
76 
77       const Drumset* drumset() const;
78 
drumNote()79       int drumNote() const                { return _drumNote;       }
setDrumNote(int v)80       void setDrumNote(int v)             { _drumNote = v;          }
81 
voice()82       int voice() const                   { return _track == -1 ? 0 : (_track % VOICES); }
track()83       int track() const                   { return _track;          }
setTrack(int v)84       void setTrack(int v)                { _prevTrack = _track; _track = v; }
prevTrack()85       int prevTrack() const               { return _prevTrack;      }
86 
string()87       int string() const                  { return _string;             }
setString(int val)88       void setString(int val)             { _string = val;              }
89 
90       StaffGroup staffGroup() const;
91 
rest()92       bool rest() const                   { return _rest; }
setRest(bool v)93       void setRest(bool v)                { _rest = v; }
94 
noteType()95       NoteType noteType() const           { return _noteType; }
setNoteType(NoteType t)96       void setNoteType(NoteType t)        { _noteType = t; }
97 
beamMode()98       Beam::Mode beamMode() const           { return _beamMode; }
setBeamMode(Beam::Mode m)99       void setBeamMode(Beam::Mode m)        { _beamMode = m; }
100 
noteEntryMode()101       bool noteEntryMode() const          { return _noteEntryMode; }
setNoteEntryMode(bool v)102       void setNoteEntryMode(bool v)       { _noteEntryMode = v; }
103 
noteEntryMethod()104       NoteEntryMethod noteEntryMethod() const               { return _noteEntryMethod; }
setNoteEntryMethod(NoteEntryMethod m)105       void setNoteEntryMethod(NoteEntryMethod m)            { _noteEntryMethod = m; }
usingNoteEntryMethod(NoteEntryMethod m)106       bool usingNoteEntryMethod(NoteEntryMethod m) const    { return m == noteEntryMethod(); }
107 
accidentalType()108       AccidentalType accidentalType() const                 { return _accidentalType; }
setAccidentalType(AccidentalType val)109       void setAccidentalType(AccidentalType val)            { _accidentalType = val;  }
110 
slur()111       Slur* slur() const                  { return _slur; }
setSlur(Slur * s)112       void setSlur(Slur* s)               { _slur = s; }
113 
insertMode()114       bool insertMode() const             { return _insertMode; }
setInsertMode(bool val)115       void setInsertMode(bool val)        { _insertMode = val; }
116 
117       void update(Selection& selection);
118       void moveInputPos(Element* e);
119       void moveToNextInputPos();
120       bool endOfScore() const;
121 
122       // TODO: unify with Selection::cr()?
123       static Note* note(Element*);
124       static ChordRest* chordRest(Element*);
125       };
126 
127 
128 }     // namespace Ms
129 #endif
130 
131