summaryrefslogtreecommitdiffstats
path: root/src/gui/editors/guitar/NoteSymbols.h
blob: fa52a45602b47e1462be2f86ee14c9a0283dd5a7 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
/* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */

/*
    Rosegarden
    A MIDI and audio sequencer and musical notation editor.

    This program is Copyright 2000-2008
        Guillaume Laurent   <glaurent@telegraph-road.org>,
        Chris Cannam        <cannam@all-day-breakfast.com>,
        Richard Bown        <richard.bown@ferventsoftware.com>

    The moral rights of Guillaume Laurent, Chris Cannam, and Richard
    Bown to claim authorship of this work have been asserted.

    This file contains code from 
    Other copyrights also apply to some parts of this work.  Please
    see the AUTHORS file and individual file headers for details.

    This program is free software; you can redistribute it and/or
    modify it under the terms of the GNU General Public License as
    published by the Free Software Foundation; either version 2 of the
    License, or (at your option) any later version.  See the file
    COPYING included with this distribution for more information.
*/


#ifndef _RG_SYMBOLS_H_
#define _RG_SYMBOLS_H_

#include <utility>

#include <tqbrush.h>
#include <tqpainter.h>

namespace Rosegarden
{

/**
 *----------------------------------------
 * Finding X position on guitar chord pixmap
 *----------------------------------------
 *
 * Originally x = position * scale + FC::BORDER + FC::CIRCBORD + FC::FRETTEXT
 *
 * The last three can be condense into on term called XBorder
 *      XBorder = FC::BORDER + FC::CIRCBORD + FC::FRETTEXT
 *             = 5 + 2 + 10 (see fingers.h)
 *             = 17
 *
 * The drawable guitar chord space on the x-axis:
 *      XGuitarChord = pixmap width - XBorder
 *                = width - 17
 *
 * The guitar chord x-axis is broken up into colums which represent the drawable
 * space for a guitar chord component (e.g. note, barre)
 *      Column Width = XGuitarChord / number of strings
 *
 * Therefore a new x can be calculated from the position and the column width
 *      x = (position * Column Width) + XBorder
 *
 *-------------------------------------------
 * Finding Y position on guitar chord pixmap
 *-------------------------------------------
 *
 * Originally y = (FC::BORDER * scale) + (2 * FC::SPACER) + (fret * scale) + FC::CIRCBORD
 *
 * As with the x-axis the equation can be separated into the position plus the border. In
 * this case YBorder
 *      YBorder = (FC::BORDER*scale) + (2*FC::SPACER) + FC::CIRCBORD
 *              = 17 (If we want to use the same border as the x-axis)
 *
 * The drawable guitar chord space on the y-axis:
 *      YGuitarChord = pixmap height - YBorder
 *
 * The guitar chord y-axis is broken up into rows which represent the drawable
 * space for a guitar chord component (e.g. note, barre)
 *      Row Height = YGuitarChord / number of frets
 *
 * Therefore a new y can be calculated from the fret position and the row height
 *      y = fret * Row Height
 **/

namespace Guitar
{

class Fingering;


class NoteSymbols
{
private:
    typedef std::pair<unsigned int, unsigned int> posPair;

    static float const LEFT_BORDER_PERCENTAGE;
    static float const RIGHT_BORDER_PERCENTAGE;
    static float const GUITAR_CHORD_WIDTH_PERCENTAGE;
    static float const TOP_BORDER_PERCENTAGE;
    static float const BOTTOM_BORDER_PERCENTAGE;
    static float const GUITAR_CHORD_HEIGHT_PERCENTAGE;
    static int   const TOP_GUITAR_CHORD_MARGIN;
    static int   const FRET_PEN_WIDTH;
    static int   const STRING_PEN_WIDTH;
    
public:

    NoteSymbols(unsigned int nbOfStrings, unsigned int nbOfFrets) :
        m_nbOfStrings(nbOfStrings), 
        m_nbOfFrets(nbOfFrets) {};

    //! Display a mute symbol in the TQPainter object
    void
    drawMuteSymbol ( TQPainter* p,
                     unsigned int position ) const;

    /* This code borrowed from KGuitar 0.5 */
    //! Display a open symbol in the TQPainter object (KGuitar)
    void drawOpenSymbol ( TQPainter* p,
                          unsigned int position ) const;

    /* This code borrowed from KGuitar 0.5 */
    //! Display a note symbol in the TQPainter object (KGuitar)
    void drawNoteSymbol ( TQPainter* p,
                          unsigned int stringNb,
                          int fretNb,
                          bool transient = false ) const;

    /* This code borrowed from KGuitar 0.5 */
    /**
     * Display a bar symbol in the TQPainter object (KGuitar)
     * The code from the KGuitar project was modified to display a bar. This feature was not
     * available in that project
     */
    void drawBarreSymbol ( TQPainter* p,
                           int fretNb,
                           unsigned int start,
                           unsigned int end ) const;

    void drawFretNumber ( TQPainter* p,
                          unsigned int fret_num ) const;

    void drawFrets ( TQPainter* p ) const;

    void drawStrings ( TQPainter* p ) const;

    unsigned int getTopBorder ( unsigned int imgHeight ) const;

    unsigned int getBottomBorder ( unsigned int imgHeight ) const;

    unsigned int getLeftBorder ( unsigned int imgWidth ) const;

    unsigned int getRightBorder ( unsigned int imgWidth ) const;

    unsigned int getGuitarChordWidth ( int imgWidth ) const;

    unsigned int getGuitarChordHeight ( int imgHeight ) const;

    unsigned int getFontPixelSize ( int imgWidth, int imgHeight ) const;
    
    std::pair<bool, unsigned int>
    getStringNumber ( int imgWidth,
                      unsigned int x_pos,
                      unsigned int string_num ) const;

    std::pair<bool, unsigned int>
    getFretNumber ( int imgHeight,
                    unsigned int y_pos,
                    unsigned int maxFretNum ) const;

    TQRect getTransientNoteSymbolRect(TQSize guitarChordSize,
                                     unsigned int stringNb,
                                     int fretNb) const;
    
    static void drawFingeringPixmap(const Fingering& fingering, const NoteSymbols& noteSymbols, TQPainter *p);
    
private:

    posPair
    getX ( int imgWidth, unsigned int stringNb, unsigned int nbOfStrings ) const;

    posPair
    getY ( int imgHeight, unsigned int fretNb, unsigned int nbOfFrets ) const;


    unsigned int m_nbOfStrings;
    unsigned int m_nbOfFrets;

};

} /* namespace Guitar */

}

#endif /* SYMBOLS_H_ */