MuseScore/libmscore/input.cpp

193 lines
5.6 KiB
C++
Raw Normal View History

2012-05-26 14:26:10 +02:00
//=============================================================================
// MuseScore
// Music Composition & Notation
//
// Copyright (C) 2011 Werner Schweer and others
//
// This program is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License version 2
// as published by the Free Software Foundation and appearing in
// the file LICENSE.GPL
//=============================================================================
#include "input.h"
#include "segment.h"
#include "part.h"
#include "staff.h"
#include "score.h"
2013-10-24 12:09:00 +02:00
#include "chord.h"
#include "rest.h"
2013-10-31 08:12:53 +01:00
#include "measure.h"
2012-05-26 14:26:10 +02:00
2013-05-13 18:49:17 +02:00
namespace Ms {
2012-05-26 14:26:10 +02:00
class DrumSet;
//---------------------------------------------------------
// drumset
//---------------------------------------------------------
const Drumset* InputState::drumset() const
2012-05-26 14:26:10 +02:00
{
if (_segment == 0 || _track == -1)
return 0;
return _segment->score()->staff(_track/VOICES)->part()->instrument(_segment->tick())->drumset();
2012-05-26 14:26:10 +02:00
}
//---------------------------------------------------------
// staffGroup
//---------------------------------------------------------
StaffGroup InputState::staffGroup() const
{
if (_segment == 0 || _track == -1)
return StaffGroup::STANDARD;
2016-12-13 13:16:17 +01:00
return _segment->score()->staff(_track/VOICES)->staffType(_segment->tick())->group();
}
2012-05-26 14:26:10 +02:00
//---------------------------------------------------------
// tick
//---------------------------------------------------------
int InputState::tick() const
{
return _segment ? _segment->tick() : 0;
}
//---------------------------------------------------------
// cr
//---------------------------------------------------------
ChordRest* InputState::cr() const
{
2017-12-20 16:49:30 +01:00
return _segment ? toChordRest(_segment->element(_track)) : 0;
2012-05-26 14:26:10 +02:00
}
2013-10-24 12:09:00 +02:00
//---------------------------------------------------------
// update
//---------------------------------------------------------
void InputState::update(Element* e)
{
if (e == 0)
return;
2017-12-20 16:49:30 +01:00
if (e && e->isChord())
e = toChord(e)->upNote();
2013-10-24 12:09:00 +02:00
setDrumNote(-1);
2017-12-20 16:49:30 +01:00
if (e->isNote()) {
Note* note = toNote(e);
2013-10-24 12:09:00 +02:00
Chord* chord = note->chord();
setDuration(chord->durationType());
setRest(false);
setTrack(note->track());
setNoteType(note->noteType());
setBeamMode(chord->beamMode());
}
2017-12-20 16:49:30 +01:00
else if (e->isRest()) {
Rest* rest = toRest(e);
if (rest->durationType().type() == TDuration::DurationType::V_MEASURE)
setDuration(TDuration::DurationType::V_QUARTER);
2013-10-24 12:09:00 +02:00
else
setDuration(rest->durationType());
setRest(true);
setTrack(rest->track());
setBeamMode(rest->beamMode());
2014-05-27 10:35:28 +02:00
setNoteType(NoteType::NORMAL);
2013-10-24 12:09:00 +02:00
}
2017-12-20 16:49:30 +01:00
if (e->isNote() || e->isRest()) {
const Instrument* instr = e->part()->instrument();
if (instr->useDrumset()) {
2017-12-20 16:49:30 +01:00
if (e->isNote())
setDrumNote(toNote(e)->pitch());
2013-10-24 12:09:00 +02:00
else
setDrumNote(-1);
}
}
}
//---------------------------------------------------------
// moveInputPos
//---------------------------------------------------------
void InputState::moveInputPos(Element* e)
{
if (e == 0)
return;
2013-10-31 08:12:53 +01:00
2013-10-24 12:09:00 +02:00
Segment* s;
if (e->isChordRest())
s = toChordRest(e)->segment();
2013-10-24 12:09:00 +02:00
else
s = toSegment(e);
if (s->isSegment()) {
2013-10-31 08:12:53 +01:00
if (s->measure()->isMMRest()) {
Measure* m = s->measure()->mmRestFirst();
2017-03-08 13:12:26 +01:00
s = m->findSegment(SegmentType::ChordRest, m->tick());
2013-10-31 08:12:53 +01:00
}
2013-10-24 12:09:00 +02:00
_lastSegment = _segment;
_segment = s;
}
}
2013-10-31 08:12:53 +01:00
//---------------------------------------------------------
// setSegment
//---------------------------------------------------------
void InputState::setSegment(Segment* s)
{
if (s && s->measure()->isMMRest()) {
Measure* m = s->measure()->mmRestFirst();
2017-03-08 13:12:26 +01:00
s = m->findSegment(SegmentType::ChordRest, m->tick());
2013-10-31 08:12:53 +01:00
}
_segment = s;
_lastSegment = s;
}
2013-10-24 12:09:00 +02:00
//---------------------------------------------------------
// nextInputPos
//---------------------------------------------------------
Segment* InputState::nextInputPos() const
{
Measure* m = _segment->measure();
2017-03-08 13:12:26 +01:00
Segment* s = _segment->next1(SegmentType::ChordRest);
for (; s; s = s->next1(SegmentType::ChordRest)) {
if (s->element(_track) || s->measure() != m) {
if (s->element(_track)) {
if (s->element(_track)->isRest() && toRest(s->element(_track))->isGap())
continue;
}
2013-10-24 12:09:00 +02:00
return s;
}
2013-10-24 12:09:00 +02:00
}
return 0;
}
//---------------------------------------------------------
// moveToNextInputPos
// TODO: special case: note is first note of tie: goto to last note of tie
//---------------------------------------------------------
void InputState::moveToNextInputPos()
{
Segment* s = nextInputPos();
_lastSegment = _segment;
2013-10-29 16:59:04 +01:00
if (s)
_segment = s;
2013-10-24 12:09:00 +02:00
}
//---------------------------------------------------------
// endOfScore
//---------------------------------------------------------
bool InputState::endOfScore() const
{
return (_lastSegment == _segment) && !nextInputPos();
}
2013-05-13 18:49:17 +02:00
}