MuseScore/libmscore/staff.h

274 lines
10 KiB
C
Raw Normal View History

2012-05-26 14:26:10 +02:00
//=============================================================================
// MuseScore
// Music Composition & Notation
//
// Copyright (C) 2002-2011 Werner Schweer
//
// 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 LICENCE.GPL
//=============================================================================
#ifndef __STAFF_H__
#define __STAFF_H__
/**
\file
Definition of class Staff.
*/
#include "mscore.h"
#include "velo.h"
#include "pitch.h"
#include "cleflist.h"
2014-06-03 15:28:10 +02:00
#include "keylist.h"
2016-12-13 13:16:17 +01:00
#include "stafftypelist.h"
#include "groups.h"
#include "scoreElement.h"
2012-05-26 14:26:10 +02:00
2013-05-13 18:49:17 +02:00
namespace Ms {
class InstrumentTemplate;
2016-11-19 11:51:21 +01:00
class XmlWriter;
2012-05-26 14:26:10 +02:00
class Part;
class Score;
class KeyList;
class StaffType;
class Staff;
struct ClefTypeList;
class Segment;
class Clef;
class TimeSig;
2013-07-16 09:03:47 +02:00
class Ottava;
2017-03-31 13:03:15 +02:00
class BracketItem;
2012-05-26 14:26:10 +02:00
2014-06-20 17:07:22 +02:00
enum class Key;
Implementation of text swing (step1) added swing tab swing settings tab in staff text properties Implemented step 2 of swing implementation using staff texts Added call for updateSwing in stafftextproperties Initial page for dialog changed System flag enabled for swing parameters saving and loading with text specified swing implemented removed extra print statement fixed formatting Added groupbox to make the default behavior to no change in swing fixed indentation in stafftextproperties fixing conflicts in staff.h Removed writing of setSwing to file Removed SwingParameter member from staff and fixed layout of swing tab in dialog fixed the issue with disabled controls Added tests for staff text implementation of swing playback cleaned up the code Swing playback using staff texts implemented, facilitating local control over swing parameters and tests for the same added Cleaned up code Cleaned up code further Swing Playback using staff texts implemented Cleaned up code further Cleaning up code further Using MScore::division in place of 480 as ticks Modified test files according to new usage of MScore::division Removed unwanted printf statements Using strings to write to xml rather than doubles for swingUnit Replaced 240 and 120 in terms of MScore::division in stafftext:write Using TDuration to write to xml Replaced string literals by TDuration for style parameters Replaced "off" with "" in style.cpp Set defaults for unit and ratio in constructors Removed usage of two structs for SwingParameters Changed order of assignments in setSwingParameters Swing playback using staff-texts implemented and tests added
2014-07-24 20:09:49 +02:00
//---------------------------------------------------------
// SwingParameters
//---------------------------------------------------------
struct SwingParameters {
int swingUnit;
int swingRatio;
2014-08-16 11:21:56 +02:00
};
Implementation of text swing (step1) added swing tab swing settings tab in staff text properties Implemented step 2 of swing implementation using staff texts Added call for updateSwing in stafftextproperties Initial page for dialog changed System flag enabled for swing parameters saving and loading with text specified swing implemented removed extra print statement fixed formatting Added groupbox to make the default behavior to no change in swing fixed indentation in stafftextproperties fixing conflicts in staff.h Removed writing of setSwing to file Removed SwingParameter member from staff and fixed layout of swing tab in dialog fixed the issue with disabled controls Added tests for staff text implementation of swing playback cleaned up the code Swing playback using staff texts implemented, facilitating local control over swing parameters and tests for the same added Cleaned up code Cleaned up code further Swing Playback using staff texts implemented Cleaned up code further Cleaning up code further Using MScore::division in place of 480 as ticks Modified test files according to new usage of MScore::division Removed unwanted printf statements Using strings to write to xml rather than doubles for swingUnit Replaced 240 and 120 in terms of MScore::division in stafftext:write Using TDuration to write to xml Replaced string literals by TDuration for style parameters Replaced "off" with "" in style.cpp Set defaults for unit and ratio in constructors Removed usage of two structs for SwingParameters Changed order of assignments in setSwingParameters Swing playback using staff-texts implemented and tests added
2014-07-24 20:09:49 +02:00
2012-05-26 14:26:10 +02:00
//---------------------------------------------------------
// Staff
/// Global staff data not directly related to drawing.
2012-05-26 14:26:10 +02:00
//---------------------------------------------------------
class Staff final : public ScoreElement {
public:
enum class HideMode { AUTO, ALWAYS, NEVER, INSTRUMENT };
2015-08-04 19:53:54 +02:00
private:
2014-08-16 13:32:08 +02:00
Part* _part { 0 };
2012-05-26 14:26:10 +02:00
2013-09-05 16:37:49 +02:00
ClefList clefs;
2014-08-16 11:21:56 +02:00
ClefTypeList _defaultClefType;
2014-06-03 15:28:10 +02:00
KeyList _keys;
2014-07-25 17:13:27 +02:00
std::map<int,TimeSig*> timesigs;
2013-05-06 14:20:31 +02:00
2017-03-31 13:03:15 +02:00
QList <BracketItem*> _brackets;
2017-05-29 14:59:10 +02:00
int _barLineSpan { false }; ///< true - span barline to next staff
2016-10-18 15:41:00 +02:00
int _barLineFrom { 0 }; ///< line of start staff to draw the barline from (0 = staff top line, ...)
2016-12-18 14:31:13 +01:00
int _barLineTo { 0 }; ///< line of end staff to draw the bar line to (0= staff bottom line, ...)
2016-10-18 15:41:00 +02:00
bool _invisible { false };
bool _cutaway { false };
bool _showIfEmpty { false }; ///< show this staff if system is empty and hideEmptyStaves is true
bool _hideSystemBarLine { false }; // no system barline if not preceded by staff with barline
2015-08-04 19:53:54 +02:00
HideMode _hideWhenEmpty { HideMode::AUTO }; // hide empty staves
2015-01-05 17:55:06 +01:00
2016-10-18 15:41:00 +02:00
QColor _color { MScore::defaultColor };
qreal _userDist { 0.0 }; ///< user edited extra distance
2012-09-20 11:35:34 +02:00
2016-12-13 13:16:17 +01:00
StaffTypeList _staffTypeList;
2016-12-18 14:31:13 +01:00
2012-05-26 14:26:10 +02:00
QMap<int,int> _channelList[VOICES];
Implementation of text swing (step1) added swing tab swing settings tab in staff text properties Implemented step 2 of swing implementation using staff texts Added call for updateSwing in stafftextproperties Initial page for dialog changed System flag enabled for swing parameters saving and loading with text specified swing implemented removed extra print statement fixed formatting Added groupbox to make the default behavior to no change in swing fixed indentation in stafftextproperties fixing conflicts in staff.h Removed writing of setSwing to file Removed SwingParameter member from staff and fixed layout of swing tab in dialog fixed the issue with disabled controls Added tests for staff text implementation of swing playback cleaned up the code Swing playback using staff texts implemented, facilitating local control over swing parameters and tests for the same added Cleaned up code Cleaned up code further Swing Playback using staff texts implemented Cleaned up code further Cleaning up code further Using MScore::division in place of 480 as ticks Modified test files according to new usage of MScore::division Removed unwanted printf statements Using strings to write to xml rather than doubles for swingUnit Replaced 240 and 120 in terms of MScore::division in stafftext:write Using TDuration to write to xml Replaced string literals by TDuration for style parameters Replaced "off" with "" in style.cpp Set defaults for unit and ratio in constructors Removed usage of two structs for SwingParameters Changed order of assignments in setSwingParameters Swing playback using staff-texts implemented and tests added
2014-07-24 20:09:49 +02:00
QMap<int,SwingParameters> _swingList;
QMap<int,int> _capoList;
2016-09-16 12:07:37 +02:00
bool _playbackVoice[VOICES] { true, true, true, true };
2012-05-26 14:26:10 +02:00
VeloList _velocities; ///< cached value
PitchList _pitchOffsets; ///< cached value
2017-03-31 13:03:15 +02:00
void fillBrackets(int);
void cleanBrackets();
2012-05-26 14:26:10 +02:00
public:
Staff(Score* score = 0);
void init(const InstrumentTemplate*, const StaffType *staffType, int);
void initFromStaffType(const StaffType* staffType);
void init(const Staff*);
2012-05-26 14:26:10 +02:00
2017-01-18 14:16:33 +01:00
virtual ElementType type() const override { return ElementType::STAFF; }
2016-03-18 09:29:16 +01:00
2014-08-11 15:25:55 +02:00
bool isTop() const;
2012-05-26 14:26:10 +02:00
QString partName() const;
2014-08-11 15:25:55 +02:00
int rstaff() const;
2012-05-26 14:26:10 +02:00
int idx() const;
2013-01-11 18:10:18 +01:00
void read(XmlReader&);
2016-12-23 12:05:18 +01:00
bool readProperties(XmlReader&);
2016-11-19 11:51:21 +01:00
void write(XmlWriter& xml) const;
2012-05-26 14:26:10 +02:00
Part* part() const { return _part; }
void setPart(Part* p) { _part = p; }
2017-03-31 13:03:15 +02:00
BracketType bracketType(int idx) const;
2012-05-26 14:26:10 +02:00
int bracketSpan(int idx) const;
2017-03-31 13:03:15 +02:00
void setBracketType(int idx, BracketType val);
2012-05-26 14:26:10 +02:00
void setBracketSpan(int idx, int val);
2017-03-31 13:03:15 +02:00
void swapBracket(int oldIdx, int newIdx);
void changeBracketColumn(int oldColumn, int newColumn);
2017-03-31 13:03:15 +02:00
void addBracket(BracketItem*);
const QList<BracketItem*>& brackets() const { return _brackets; }
QList<BracketItem*>& brackets() { return _brackets; }
2012-05-26 14:26:10 +02:00
void cleanupBrackets();
2017-03-31 13:03:15 +02:00
int bracketLevels() const;
2012-05-26 14:26:10 +02:00
ClefList& clefList() { return clefs; }
ClefTypeList clefType(const Fraction&) const;
2014-08-16 11:21:56 +02:00
ClefTypeList defaultClefType() const { return _defaultClefType; }
void setDefaultClefType(const ClefTypeList& l) { _defaultClefType = l; }
ClefType clef(const Fraction&) const;
Fraction nextClefTick(const Fraction&) const;
Fraction currentClefTick(const Fraction&) const;
2014-07-25 17:13:27 +02:00
void setClef(Clef*);
void removeClef(const Clef*);
2012-05-26 14:26:10 +02:00
void addTimeSig(TimeSig*);
void removeTimeSig(TimeSig*);
2014-11-27 13:04:03 +01:00
void clearTimeSig();
Fraction timeStretch(const Fraction&) const;
TimeSig* timeSig(const Fraction&) const;
TimeSig* nextTimeSig(const Fraction&) const;
Fraction currentTimeSigTick(const Fraction&) const;
bool isLocalTimeSignature(const Fraction& tick) { return timeStretch(tick) != Fraction(1, 1); }
const Groups& group(const Fraction&) const;
KeyList* keyList() { return &_keys; }
Key key(const Fraction& tick) const { return keySigEvent(tick).key(); }
KeySigEvent keySigEvent(const Fraction&) const;
Fraction nextKeyTick(const Fraction&) const;
Fraction currentKeyTick(const Fraction&) const;
KeySigEvent prevKey(const Fraction&) const;
void setKey(const Fraction&, KeySigEvent);
void removeKey(const Fraction&);
2012-05-26 14:26:10 +02:00
bool show() const;
bool stemless(const Fraction&) const;
2012-05-26 14:26:10 +02:00
bool invisible() const { return _invisible; }
void setInvisible(bool val) { _invisible = val; }
2015-08-04 19:53:54 +02:00
bool cutaway() const { return _cutaway; }
void setCutaway(bool val) { _cutaway = val; }
bool showIfEmpty() const { return _showIfEmpty; }
void setShowIfEmpty(bool val) { _showIfEmpty = val; }
2014-07-31 18:46:41 +02:00
2015-01-05 17:55:06 +01:00
bool hideSystemBarLine() const { return _hideSystemBarLine; }
2015-08-04 19:53:54 +02:00
void setHideSystemBarLine(bool val) { _hideSystemBarLine = val; }
HideMode hideWhenEmpty() const { return _hideWhenEmpty; }
void setHideWhenEmpty(HideMode v) { _hideWhenEmpty = v; }
2015-01-05 17:55:06 +01:00
2017-05-29 14:59:10 +02:00
int barLineSpan() const { return _barLineSpan; }
2012-10-14 00:35:11 +02:00
int barLineFrom() const { return _barLineFrom; }
int barLineTo() const { return _barLineTo; }
2017-05-29 14:59:10 +02:00
void setBarLineSpan(int val) { _barLineSpan = val; }
2012-10-14 00:35:11 +02:00
void setBarLineFrom(int val) { _barLineFrom = val; }
2016-12-23 12:05:18 +01:00
void setBarLineTo(int val) { _barLineTo = val; }
2012-05-26 14:26:10 +02:00
qreal height() const;
int channel(const Fraction&, int voice) const;
void clearChannelList(int voice) { _channelList[voice].clear(); }
void insertIntoChannelList(int voice, const Fraction& tick, int channelId) { _channelList[voice].insert(tick.ticks(), channelId); }
SwingParameters swing(const Fraction&) const;
void clearSwingList() { _swingList.clear(); }
void insertIntoSwingList(const Fraction& tick, SwingParameters sp) { _swingList.insert(tick.ticks(), sp); }
int capo(const Fraction&) const;
void clearCapoList() { _capoList.clear(); }
void insertIntoCapoList(const Fraction& tick, int fretId) { _capoList.insert(tick.ticks(), fretId); }
//==== staff type helper function
const StaffType* staffType(const Fraction&) const;
const StaffType* constStaffType(const Fraction&) const;
StaffType* staffType(const Fraction&);
StaffType* setStaffType(const Fraction&, const StaffType&);
void removeStaffType(const Fraction&);
void staffTypeListChanged(const Fraction&);
bool isPitchedStaff(const Fraction&) const;
bool isTabStaff(const Fraction&) const;
bool isDrumStaff(const Fraction&) const;
int lines(const Fraction&) const;
void setLines(const Fraction&, int lines);
qreal lineDistance(const Fraction&) const;
void setSlashStyle(const Fraction&, bool val);
int middleLine(const Fraction&) const;
int bottomLine(const Fraction&) const;
qreal userMag(const Fraction&) const;
void setUserMag(const Fraction&, qreal m);
qreal mag(const Fraction&) const;
bool small(const Fraction&) const;
void setSmall(const Fraction&, bool val);
qreal spatium(const Fraction&) const;
2016-12-23 12:05:18 +01:00
//===========
2012-05-26 14:26:10 +02:00
VeloList& velocities() { return _velocities; }
2016-02-06 11:41:16 +01:00
PitchList& pitchOffsets() { return _pitchOffsets; }
int pitchOffset(const Fraction& tick) { return _pitchOffsets.pitchOffset(tick.ticks()); }
2014-07-15 12:49:51 +02:00
void updateOttava();
2012-05-26 14:26:10 +02:00
2014-05-21 20:08:37 +02:00
QList<Staff*> staffList() const;
2012-05-26 14:26:10 +02:00
bool primaryStaff() const;
2014-08-01 16:21:39 +02:00
2012-05-26 14:26:10 +02:00
qreal userDist() const { return _userDist; }
void setUserDist(qreal val) { _userDist = val; }
2012-05-26 14:26:10 +02:00
void spatiumChanged(qreal /*oldValue*/, qreal /*newValue*/);
void localSpatiumChanged(double oldVal, double newVal, Fraction tick);
bool genKeySig();
bool showLedgerLines(const Fraction&) const;
QColor color() const { return _color; }
void setColor(const QColor& val) { _color = val; }
void undoSetColor(const QColor& val);
void insertTime(const Fraction&, const Fraction& len);
2018-03-27 15:36:00 +02:00
virtual QVariant getProperty(Pid) const override;
virtual bool setProperty(Pid, const QVariant&) override;
virtual QVariant propertyDefault(Pid) const override;
2016-03-02 13:20:19 +01:00
BracketType innerBracket() const;
2016-09-16 12:07:37 +02:00
bool playbackVoice(int voice) const { return _playbackVoice[voice]; }
void setPlaybackVoice(int voice, bool val) { _playbackVoice[voice] = val; }
#ifndef NDEBUG
void dumpClefs(const char* title) const;
void dumpKeys(const char* title) const;
2015-02-16 12:12:23 +01:00
void dumpTimeSigs(const char*) const;
#else
void dumpClefs(const char*) const {}
void dumpKeys(const char*) const {}
2015-02-16 12:12:23 +01:00
void dumpTimeSigs(const char*) const {}
#endif
2019-10-24 15:49:23 +02:00
void triggerLayout();
void triggerLayout(const Fraction& tick);
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
#endif