~ubuntu-branches/ubuntu/karmic/rosegarden/karmic

« back to all changes in this revision

Viewing changes to src/base/SnapGrid.h

  • Committer: Bazaar Package Importer
  • Author(s): Stefan Ebner
  • Date: 2008-05-02 00:33:44 UTC
  • mfrom: (1.1.7 upstream) (6.1.1 lenny)
  • Revision ID: james.westby@ubuntu.com-20080502003344-67vbfhgqx2yl0ksi
Tags: 1:1.7.0-1ubuntu1
* Merge from Debian unstable. (LP: #225849) Remaining Ubuntu changes:
  - Add usr/share/doc/kde/HTML to rosegarden-data, to provide online
    help documentation.
  - Change fftw3-dev to libfftw3-dev.
  - Update maintainer field as per spec.

Show diffs side-by-side

added added

removed removed

Lines of Context:
4
4
    Rosegarden
5
5
    A sequencer and musical notation editor.
6
6
 
7
 
    This program is Copyright 2000-2007
 
7
    This program is Copyright 2000-2008
8
8
        Guillaume Laurent   <glaurent@telegraph-road.org>,
9
9
        Chris Cannam        <cannam@all-day-breakfast.com>,
10
10
        Richard Bown        <bownie@bownie.com>
24
24
 
25
25
#include "RulerScale.h"
26
26
 
 
27
#include <map>
 
28
 
27
29
namespace Rosegarden {
28
30
 
29
31
/**
39
41
public:
40
42
    /**
41
43
     * Construct a SnapGrid that uses the given RulerScale for
42
 
     * x-coordinate mappings and the given vstep for y-coords.
43
 
     * If vstep is zero, y-coords are not snapped at all.
 
44
     * x-coordinate mappings and the given ysnap for y-coords.
 
45
     * If ysnap is zero, y-coords are not snapped at all.
44
46
     */
45
 
    SnapGrid(RulerScale *rulerScale, int vstep = 0);
 
47
    SnapGrid(RulerScale *rulerScale, int ysnap = 0);
46
48
 
47
49
    static const timeT NoSnap;
48
50
    static const timeT SnapToBar;
86
88
    timeT getSnapTime(timeT t) const;
87
89
 
88
90
    /**
89
 
     * Snap a given x-coordinate to the nearest time on
90
 
     * the grid.  Of course this also does x-to-time
91
 
     * conversion, so it's useful even in NoSnap mode.
92
 
     * If the snap time is greater than the bar duration
93
 
     * at this point, the bar duration will be used instead.
 
91
     * Snap a given x-coordinate to the nearest time on the grid.  Of
 
92
     * course this also does x-to-time conversion, so it's useful even
 
93
     * in NoSnap mode.  If the snap time is greater than the bar
 
94
     * duration at this point, the bar duration will be used instead.
94
95
     *
95
 
     * If d is SnapLeft or SnapRight, a time to the left or
96
 
     * right respectively of the given coordinate will be
97
 
     * returned; otherwise the nearest time on either side
98
 
     * will be returned.
 
96
     * If d is SnapLeft or SnapRight, a time to the left or right
 
97
     * respectively of the given coordinate will be returned;
 
98
     * otherwise the nearest time on either side will be returned.
99
99
     */
100
100
    timeT snapX(double x, SnapDirection d = SnapEither) const;
101
101
 
102
102
    /**
103
 
     * Snap a given time to the nearest time on the grid.
104
 
     * Unlike snapX, this is not useful in NoSnap mode.
105
 
     * If the snap time is greater than the bar duration
106
 
     * at this point, the bar duration will be used instead.
 
103
     * Snap a given time to the nearest time on the grid.  Unlike
 
104
     * snapX, this is not useful in NoSnap mode.  If the snap time is
 
105
     * greater than the bar duration at this point, the bar duration
 
106
     * will be used instead.
107
107
     *
108
 
     * If d is SnapLeft or SnapRight, a time to the left or
109
 
     * right respectively of the given coordinate will be
110
 
     * returned; otherwise the nearest time on either side
111
 
     * will be returned.
 
108
     * If d is SnapLeft or SnapRight, a time to the left or right
 
109
     * respectively of the given coordinate will be returned;
 
110
     * otherwise the nearest time on either side will be returned.
112
111
     */
113
112
    timeT snapTime(timeT t, SnapDirection d = SnapEither) const;
114
113
 
115
114
    /**
116
 
     * Snap a given y-coordinate to the nearest lower
117
 
     * multiple of the vstep.
 
115
     * Snap a given y-coordinate to the nearest lower bin coordinate.
118
116
     */
119
117
    int snapY(int y) const {
120
 
        if (m_vstep == 0) return y;
121
 
        else return y / m_vstep * m_vstep;
122
 
    }
123
 
 
124
 
    /**
125
 
     * Return the vstep bin number for the given y-coordinate.
126
 
     */
127
 
    int getYBin(int y) const {
128
 
        if (m_vstep == 0) return y;
129
 
        else return y / m_vstep;
130
 
    }
131
 
 
132
 
    /**
133
 
     * Return the y-coordinate of the grid line at the start
134
 
     * of the given vstep bin.
135
 
     */
136
 
    int getYBinCoordinate(int bin) const {
137
 
        if (m_vstep == 0) return bin;
138
 
        else return bin * m_vstep;
139
 
    }
140
 
 
 
118
        if (m_ysnap == 0) return y;
 
119
        return getYBinCoordinate(getYBin(y));
 
120
    }
 
121
 
 
122
    /**
 
123
     * Return the bin number for the given y-coordinate.
 
124
     */
 
125
    int getYBin(int y) const;
 
126
 
 
127
    /**
 
128
     * Return the y-coordinate of the grid line at the start of the
 
129
     * given bin.
 
130
     */
 
131
    int getYBinCoordinate(int bin) const;
 
132
 
 
133
    /**
 
134
     * Set the default vertical step.  This is used as the height for
 
135
     * bins that have no specific height multiple set, and the base
 
136
     * height for bins that have a multiple.  Setting the Y snap here
 
137
     * is equivalent to specifying it in the constructor.
 
138
     */
 
139
    void setYSnap(int ysnap) {
 
140
        m_ysnap = ysnap;
 
141
    }
 
142
 
 
143
    /**
 
144
     * Retrieve the default vertical step.
 
145
     */
141
146
    int getYSnap() const {
142
 
        return m_vstep;
 
147
        return m_ysnap;
 
148
    }
 
149
 
 
150
    /**
 
151
     * Set the height multiple for a specific bin.  The bin will be
 
152
     * multiple * ysnap high.  The default is 1 for all bins.
 
153
     */
 
154
    void setBinHeightMultiple(int bin, int multiple) {
 
155
        m_ymultiple[bin] = multiple;
 
156
    }
 
157
    
 
158
    /**
 
159
     * Retrieve the height multiple for a bin.
 
160
     */
 
161
    int getBinHeightMultiple(int bin) {
 
162
        if (m_ymultiple.find(bin) == m_ymultiple.end()) return 1;
 
163
        return m_ymultiple[bin];
143
164
    }
144
165
 
145
166
    RulerScale *getRulerScale() {
153
174
protected:
154
175
    RulerScale *m_rulerScale; // I don't own this
155
176
    timeT m_snapTime;
156
 
    int m_vstep;
 
177
    int m_ysnap;
 
178
    std::map<int, int> m_ymultiple;
157
179
};
158
180
 
159
181
}