File: measure.cpp

package info (click to toggle)
nted 1.10.18-13
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, forky, sid, trixie
  • size: 15,300 kB
  • sloc: cpp: 50,840; ansic: 10,195; sh: 4,552; makefile: 207; sed: 16
file content (463 lines) | stat: -rw-r--r-- 20,934 bytes parent folder | download | duplicates (6)
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
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
/****************************************************************************************/
/*											*/
/* 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.	*/
/*											*/
/* This program is distributed in the hope that it will be useful, but WITHOUT ANY	*/
/* WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A	*/
/* PARTICULAR PURPOSE. See the GNU General Public License for more details.		*/
/*											*/
/* You should have received a copy of the GNU General Public License along with this	*/
/* program; (See "COPYING"). If not, If not, see <http://www.gnu.org/licenses/>.        */
/*											*/
/*--------------------------------------------------------------------------------------*/
/*											*/
/*  Copyright   Joerg Anders, TU Chemnitz, Fakultaet fuer Informatik, GERMANY           */
/*		ja@informatik.tu-chemnitz.de						*/
/*											*/
/*											*/
/****************************************************************************************/

#include <math.h>
#include "measure.h"
#include "resource.h"
#include "system.h"
#include "staff.h"
#include "mainwindow.h"

#define X_POS_PAGE_REL(p) ((content_x_pos + (p)) * zoom_factor - leftx)
#define Y_POS_SYS_REL(p) (((p) + sys_y_pos)  * zoom_factor - topy)
#define Y_POS_STAFF_REL(p) (((p) + sys_y_pos + top) * zoom_factor - topy)

#define X_PS_POS(p) ((DEFAULT_BORDER + LEFT_RIGHT_BORDER + (p)) * PS_ZOOM)
#define Y_PS_POS_SYS_REL(p) ((page_height - ((p) + sys_y_pos)) * PS_ZOOM)

NedMeasure::NedMeasure() : m_staff_elements_width(0.0), m_measure_has_only_staff_members(false), m_spread_fac(1.0), m_special_spread(false), m_hide_following(false), m_measure_number(1), m_special_descr(NULL) {
	m_measure_number_str[0] = '1';
	m_measure_number_str[1] = '\0';
}

void NedMeasure::setMeasureNumber(int num, GList *special_measures, bool force /* = false */) {
	GList *lptr;


	if (m_measure_number == num && !force) return;

	m_special_descr = NULL;
	m_measure_number = num;
	sprintf(m_measure_number_str, "%d", num);
	for (lptr = g_list_first(special_measures); lptr; lptr = g_list_next(lptr)) {
		if (((SpecialMeasure *) lptr->data)->measure_number == m_measure_number) {
			m_special_descr = (SpecialMeasure *) lptr->data;
			//NedResource::DbgMsg(DBG_TESTING, "0x%x, type = 0x%x --> c = %d (0x%x)\n", m_special_descr, m_special_descr->type, m_measure_number, &(m_special_descr->measure)); 
			m_hide_following = ((SpecialMeasure *) lptr->data)->hide_following;
			m_special_descr->measure = this;
		}
	}
}

int NedMeasure::getSpecial() {
	if (m_special_descr == NULL) return 0;
	return m_special_descr->type;
}

bool NedMeasure::barRequiresHideFollowing() {
	if (m_special_descr == NULL) return false;
	return (((m_special_descr->type & REP_TYPE_MASK) == END_BAR || (m_special_descr->type & REP_TYPE_MASK) == REPEAT_CLOSE) && m_hide_following);
}

bool NedMeasure::isNearStart(double x) {
	double dist = x - start;
	if (dist < 0.0) dist = -dist;
	return dist < MIN_NEAR_DIST;
	/*
	ret = dist < MIN_NEAR_DIST;
	if (ret) {
		NedResource::DbgMsg(DBG_TESTING, "measure %d, x = %f , start = %f, midi_start = %llu, midi_end = %llu\n",
			m_measure_number, x, start, midi_start / NOTE_4, midi_end / NOTE_4); 
	}
	return ret;
	*/
}

double NedMeasure::shiftXpos(double extra_space_divided, double shift, bool out) {
	start += shift;
	shift = m_position_array.shiftXpos(extra_space_divided, shift, m_measure_number, out);
	shift += extra_space_divided;
	return shift;
}

double NedMeasure::computeAndSetPositions(double start_position, int *num_elements, double *extra_space_for_accidentals, bool *measure_has_only_staff_members /* means keysig */, bool out) {
	
	double timesig_space = (m_special_descr && (m_special_descr->type & TIMESIG_TYPE_MASK)) ? TIME_SIG_WIDTH : 0.0;
	start_position += getNeededSpaceAfter();
	start = start_position;
	start_position += getNeededSpaceBefore();
	start_position = m_position_array.computeAndSetPositions(start_position, num_elements, extra_space_for_accidentals, measure_has_only_staff_members, timesig_space, m_measure_number, m_spread_fac, out);
	m_measure_has_only_staff_members = *measure_has_only_staff_members;
	end = start_position;
	return start_position;
}


bool NedMeasure::nearRepeatElement(double x, double y) {
	int i = 0;
	bool hit = false;
	double staff_border_dist, xx, yy;
	NedStaff *staff;

	for (i = 0; !hit &&(staff = m_system->getStaff(i)) != NULL; i++) {
		staff->convertStaffRel(x, y, &xx, &yy);
		double xdist = xx - start;
		if (xdist < 0.0) xdist = -xdist;
		if (xdist > MIN_NEAR_DIST) continue;
		staff_border_dist = staff->getTopYBorder();
		double repyoffs = staff_border_dist;
		if (staff_border_dist > -MIN_STAFF_BORDER_DIST) repyoffs = -MIN_STAFF_BORDER_DIST;
		repyoffs += SEC_DIST_ABOVE;
		double ydist = yy - (repyoffs + REP_NUM_YPOS - 4 * LINE_DIST);
		if (ydist < 0.0) ydist = - ydist;
		if (ydist > MIN_NEAR_DIST) continue;
		hit = true;
	}
	return hit;
}
	

bool NedMeasure::isNearEnd(double x) {
	double dist = x - end;
	if (dist < 0.0) dist = -dist;
	return dist < MIN_NEAR_DIST;
}

double NedMeasure::getNeededSpaceBefore() {
	if (m_special_descr == NULL) return MEAS_BAR_SPACE;
	switch (m_special_descr->type & TIMESIG_TYPE_MASK) {
		case TIMESIG: return TIME_SIGNATURE_SPACE;
	}
	switch (m_special_descr->type & REP_TYPE_MASK) {
		case REPEAT_OPEN_CLOSE: return REP_THICK_LINE_DIST + REP_DOTS_X_DIST + REP_DOTS_X_EXTRA_DIST;
		case REPEAT_OPEN: return REP_THICK_LINE_DIST + REP_DOTS_X_DIST;
		case REPEAT_CLOSE: return REP_THICK_LINE_DIST + REP_DOTS_X_DIST;
		case DOUBLE_BAR: return REP_DOUBLE_LINE_DIST;
		case END_BAR: return 4 * REP_DOUBLE_LINE_DIST;
	}
	return MEAS_BAR_SPACE;
}

double NedMeasure::getNeededSpaceAfter() {
	if (m_special_descr == NULL) return MEAS_BAR_SPACE;

	switch (m_special_descr->type & REP_TYPE_MASK) {
		case REPEAT_OPEN_CLOSE: return REP_THICK_LINE_DIST + REP_DOTS_X_DIST + REP_DOTS_X_EXTRA_DIST;
		case REPEAT_OPEN: return REP_THICK_LINE_DIST + REP_DOTS_X_DIST + REP_DOTS_X_EXTRA_DIST;
		case REPEAT_CLOSE: return REP_THICK_LINE_DIST + REP_DOTS_X_DIST + REP_DOTS_X_EXTRA_DIST;
		case DOUBLE_BAR: return 3 * REP_DOUBLE_LINE_DIST;
		case END_BAR: return 4 * REP_DOUBLE_LINE_DIST;
	}
	return MEAS_BAR_SPACE;
}


void NedMeasure::draw(cairo_t *cr, int special_position, double xpos, double content_x_pos, double sys_y_pos, double top, double bottom, double bottom_ori, double leftx, double topy,
			double staff_border_dist, double zoom_factor, int zoom_level, bool rep_line_needed, int spec_measure_at_end, bool out) {
	double line_xpos, normal_line_pos = start;
	double repyoffs;
	double line_bottom = bottom;
	bool draw_default_line = true;
	int realtype = 0;
	double sig_xpos = start;

	if (m_special_descr != NULL) {
		realtype = m_special_descr->type & (REP_TYPE_MASK | TIMESIG_TYPE_MASK);
	}

	if (rep_line_needed && special_position != SPECIAL_POSITION_END) {
		cairo_new_path(cr);
		cairo_set_line_width(cr, zoom_factor * MEASURE_LINE_THICK);
		repyoffs = staff_border_dist;
		if (staff_border_dist > -MIN_STAFF_BORDER_DIST) repyoffs = -MIN_STAFF_BORDER_DIST;
		repyoffs += SEC_DIST_ABOVE;
		if (special_position == SPECIAL_POSITION_START) {
			cairo_move_to(cr, X_POS_PAGE_REL(xpos), Y_POS_STAFF_REL(repyoffs));
		}
		else {
			cairo_move_to(cr, X_POS_PAGE_REL(start), Y_POS_STAFF_REL(repyoffs));
		}
		cairo_line_to(cr, X_POS_PAGE_REL(end), Y_POS_STAFF_REL(repyoffs));
		cairo_stroke(cr);
	}

	if (special_position == SPECIAL_POSITION_START) {
		if (m_special_descr == NULL) return;
		if ((m_special_descr->type & REP_TYPE_MASK) == REPEAT_OPEN_CLOSE) {
			realtype = REPEAT_OPEN;
		}
	}
	if (special_position == SPECIAL_POSITION_END) {
		normal_line_pos = xpos;
		if (m_special_descr != NULL) {
			//if ((m_special_descr->type & REP_TYPE_MASK) == REPEAT_OPEN) return;
			if ((m_special_descr->type & REP_TYPE_MASK) == REPEAT_OPEN_CLOSE) {
				realtype = REPEAT_CLOSE;
			}
		}
	}
	if (m_special_descr != NULL) {
		switch (m_special_descr->type & START_TYPE_MASK) {
			case REP1START: if (special_position == SPECIAL_POSITION_END) break;
					line_xpos = (special_position == SPECIAL_POSITION_START) ? xpos : start;
					repyoffs = staff_border_dist;
					if (staff_border_dist > -MIN_STAFF_BORDER_DIST) repyoffs = -MIN_STAFF_BORDER_DIST;
					repyoffs += SEC_DIST_ABOVE;
					cairo_new_path(cr);
					cairo_set_line_width(cr, zoom_factor *  MEASURE_LINE_THICK);
					cairo_move_to(cr, X_POS_PAGE_REL(line_xpos), Y_POS_STAFF_REL(0));
					cairo_line_to(cr, X_POS_PAGE_REL(line_xpos), Y_POS_STAFF_REL(repyoffs));
					if (special_position != SPECIAL_POSITION_END) {
						if (m_special_descr == m_system->getMainWindow()->m_selected_spec_measure) {
							cairo_set_source_rgb(cr, 1.0, 0.0, 0.0);
						}
						cairo_select_font_face(cr, "Sans", CAIRO_FONT_SLANT_ITALIC, CAIRO_FONT_WEIGHT_NORMAL);
						cairo_set_font_size(cr, MEASURE_NUMBER_SIZE * zoom_factor);
						cairo_move_to(cr, X_POS_PAGE_REL(line_xpos + REP_NUM_XPOS), Y_POS_STAFF_REL(repyoffs + REP_NUM_YPOS));
						cairo_show_text(cr, "1.");
#ifdef HAS_SET_SCALED_FONT
						cairo_set_scaled_font (cr, scaled_font);
#else
						cairo_set_font_face(cr, NedResource::getFontFace());
						cairo_set_font_matrix(cr, NedResource::getFontMatrix(zoom_level));
#endif
						if (m_special_descr == m_system->getMainWindow()->m_selected_spec_measure) {
							cairo_set_source_rgb(cr, 0.0, 0.0, 0.0);
						}
					}
					cairo_stroke(cr);
					line_bottom = bottom_ori;
					break;
			case REP2START: if (special_position == SPECIAL_POSITION_END) break;
					line_xpos = (special_position == SPECIAL_POSITION_START) ? xpos : start;
					repyoffs = staff_border_dist;
					if (staff_border_dist > -MIN_STAFF_BORDER_DIST) repyoffs = -MIN_STAFF_BORDER_DIST;
					repyoffs += SEC_DIST_ABOVE;
					cairo_new_path(cr);
					cairo_set_line_width(cr, zoom_factor *  MEASURE_LINE_THICK);
					cairo_move_to(cr, X_POS_PAGE_REL(line_xpos), Y_POS_STAFF_REL(0));
					cairo_line_to(cr, X_POS_PAGE_REL(line_xpos), Y_POS_STAFF_REL(repyoffs));
					if (special_position != SPECIAL_POSITION_END) {
						if (m_special_descr == m_system->getMainWindow()->m_selected_spec_measure) {
							cairo_set_source_rgb(cr, 1.0, 0.0, 0.0);
						}
						cairo_select_font_face(cr, "Sans", CAIRO_FONT_SLANT_ITALIC, CAIRO_FONT_WEIGHT_NORMAL);
						cairo_set_font_size(cr, MEASURE_NUMBER_SIZE * zoom_factor);
						cairo_move_to(cr, X_POS_PAGE_REL(line_xpos + REP_NUM_XPOS), Y_POS_STAFF_REL(repyoffs + REP_NUM_YPOS));
						cairo_show_text(cr, "2.");
#ifdef HAS_SET_SCALED_FONT
						cairo_set_scaled_font (cr, scaled_font);
#else
						cairo_set_font_face(cr, NedResource::getFontFace());
						cairo_set_font_matrix(cr, NedResource::getFontMatrix(zoom_level));
#endif
						if (m_special_descr == m_system->getMainWindow()->m_selected_spec_measure) {
							cairo_set_source_rgb(cr, 0.0, 0.0, 0.0);
						}
					}
					cairo_stroke(cr);
					break;
		}
		switch (m_special_descr->type & END_TYPE_MASK) {
			case REP1END:   if (special_position == SPECIAL_POSITION_START) break;
					repyoffs = staff_border_dist;
					if (staff_border_dist > -MIN_STAFF_BORDER_DIST) repyoffs = -MIN_STAFF_BORDER_DIST;
					repyoffs += SEC_DIST_ABOVE;
					cairo_new_path(cr);
					cairo_set_line_width(cr, zoom_factor *  MEASURE_LINE_THICK);
					cairo_move_to(cr, X_POS_PAGE_REL(start), Y_POS_STAFF_REL(0));
					cairo_line_to(cr, X_POS_PAGE_REL(start), Y_POS_STAFF_REL(repyoffs));
					cairo_stroke(cr);
					break;
			case REP2END:   line_bottom = bottom_ori;
					break;
		}
		if ( special_position == SPECIAL_POSITION_START && ((m_special_descr->type & (START_TYPE_MASK | END_TYPE_MASK)) != 0) && realtype == 0) return;
		if ( special_position == SPECIAL_POSITION_START && ((m_special_descr->type & REP_TYPE_MASK) == REPEAT_CLOSE)) return;
		switch (realtype & REP_TYPE_MASK) {
#define REP_OPEN_START_LINE_DIST 0.2
			case REPEAT_OPEN:
				if (special_position == SPECIAL_POSITION_END) break;
				line_xpos = (special_position == SPECIAL_POSITION_START) ? xpos + REP_OPEN_START_LINE_DIST : start;
				if (special_position == SPECIAL_POSITION_START) {
					normal_line_pos = line_xpos;
				}
				cairo_new_path(cr);
				cairo_set_line_width(cr, zoom_factor * REPEAT_MEASURE_LINE_THICK);
				cairo_move_to(cr, X_POS_PAGE_REL(line_xpos - REP_THICK_LINE_DIST), Y_POS_SYS_REL(top));
				cairo_line_to(cr, X_POS_PAGE_REL(line_xpos - REP_THICK_LINE_DIST), Y_POS_SYS_REL(bottom));
				cairo_stroke(cr);
				cairo_arc(cr, X_POS_PAGE_REL(line_xpos + REP_DOTS_X_DIST), Y_POS_SYS_REL(bottom_ori - REP_DOTS_Y1DIST), zoom_factor * REP_DOTS_RADIUS, 0.0, 2.0 * M_PI);
				cairo_arc(cr, X_POS_PAGE_REL(line_xpos + REP_DOTS_X_DIST), Y_POS_SYS_REL(bottom_ori - REP_DOTS_Y2DIST), zoom_factor * REP_DOTS_RADIUS, 0.0, 2.0 * M_PI);
				cairo_fill(cr);
				sig_xpos += REP_DOTS_X_DIST;
				break;
			case REPEAT_CLOSE:
				if (special_position == SPECIAL_POSITION_END && spec_measure_at_end) break;
				line_xpos = (special_position == SPECIAL_POSITION_END) ? xpos : start;
				cairo_new_path(cr);
				cairo_set_line_width(cr, zoom_factor * REPEAT_MEASURE_LINE_THICK);
				cairo_move_to(cr, X_POS_PAGE_REL(line_xpos), Y_POS_SYS_REL(top));
				cairo_line_to(cr, X_POS_PAGE_REL(line_xpos), Y_POS_SYS_REL(bottom));
				cairo_stroke(cr);
				cairo_new_path(cr);
				cairo_set_line_width(cr, zoom_factor * MEASURE_LINE_THICK);
				cairo_move_to(cr, X_POS_PAGE_REL(line_xpos - REP_THICK_LINE_DIST), Y_POS_SYS_REL(top));
				cairo_line_to(cr, X_POS_PAGE_REL(line_xpos - REP_THICK_LINE_DIST), Y_POS_SYS_REL(bottom));
				cairo_stroke(cr);
				cairo_arc(cr, X_POS_PAGE_REL(line_xpos - REP_THICK_LINE_DIST - REP_DOTS_X_DIST), Y_POS_SYS_REL(bottom_ori - REP_DOTS_Y1DIST), zoom_factor * REP_DOTS_RADIUS, 0.0, 2.0 * M_PI);
				cairo_arc(cr, X_POS_PAGE_REL(line_xpos - REP_THICK_LINE_DIST - REP_DOTS_X_DIST), Y_POS_SYS_REL(bottom_ori - REP_DOTS_Y2DIST), zoom_factor * REP_DOTS_RADIUS, 0.0, 2.0 * M_PI);
				cairo_fill(cr);
				draw_default_line = false;
				break;
			case END_BAR:
				if (special_position == SPECIAL_POSITION_END && spec_measure_at_end) break;
				if (special_position == SPECIAL_POSITION_START) return;
				line_xpos = (special_position == SPECIAL_POSITION_END) ? xpos : start;
				cairo_new_path(cr);
				cairo_set_line_width(cr, zoom_factor * REPEAT_MEASURE_LINE_THICK);
				cairo_move_to(cr, X_POS_PAGE_REL(line_xpos), Y_POS_SYS_REL(top));
				cairo_line_to(cr, X_POS_PAGE_REL(line_xpos), Y_POS_SYS_REL(bottom));
				cairo_stroke(cr);
				cairo_new_path(cr);
				cairo_set_line_width(cr, zoom_factor * MEASURE_LINE_THICK);
				cairo_move_to(cr, X_POS_PAGE_REL(line_xpos - REP_THICK_LINE_DIST), Y_POS_SYS_REL(top));
				cairo_line_to(cr, X_POS_PAGE_REL(line_xpos - REP_THICK_LINE_DIST), Y_POS_SYS_REL(bottom));
				cairo_stroke(cr);
				draw_default_line = false;
				break;
			case DOUBLE_BAR:
				if (special_position == SPECIAL_POSITION_END && spec_measure_at_end) break;
				if (special_position == SPECIAL_POSITION_START) return;
				line_xpos = (special_position == SPECIAL_POSITION_END) ? xpos : start;
				cairo_new_path(cr);
				cairo_set_line_width(cr, zoom_factor * MEASURE_LINE_THICK);
				cairo_move_to(cr, X_POS_PAGE_REL(line_xpos - REP_DOUBLE_LINE_DIST), Y_POS_SYS_REL(top));
				cairo_line_to(cr, X_POS_PAGE_REL(line_xpos - REP_DOUBLE_LINE_DIST), Y_POS_SYS_REL(bottom));
				cairo_stroke(cr);
				break;
			case REPEAT_OPEN_CLOSE:
				if (special_position == SPECIAL_POSITION_END && spec_measure_at_end) break;
				cairo_new_path(cr);
				cairo_set_line_width(cr, zoom_factor * REPEAT_MEASURE_LINE_THICK);
				cairo_move_to(cr, X_POS_PAGE_REL(start), Y_POS_SYS_REL(top));
				cairo_line_to(cr, X_POS_PAGE_REL(start), Y_POS_SYS_REL(bottom));
				cairo_stroke(cr);
				cairo_new_path(cr);
				cairo_set_line_width(cr, zoom_factor * MEASURE_LINE_THICK);
				cairo_move_to(cr, X_POS_PAGE_REL(start + REP_THICK_LINE_DIST), Y_POS_SYS_REL(top));
				cairo_line_to(cr, X_POS_PAGE_REL(start + REP_THICK_LINE_DIST), Y_POS_SYS_REL(bottom));
				cairo_move_to(cr, X_POS_PAGE_REL(start - REP_THICK_LINE_DIST), Y_POS_SYS_REL(top));
				cairo_line_to(cr, X_POS_PAGE_REL(start - REP_THICK_LINE_DIST), Y_POS_SYS_REL(bottom));
				cairo_stroke(cr);
				cairo_new_path(cr);
				cairo_arc(cr, X_POS_PAGE_REL(start + REP_THICK_LINE_DIST + REP_DOTS_X_DIST), Y_POS_SYS_REL(bottom_ori - REP_DOTS_Y1DIST), zoom_factor * REP_DOTS_RADIUS, 0.0, 2.0 * M_PI);
				cairo_arc(cr, X_POS_PAGE_REL(start + REP_THICK_LINE_DIST + REP_DOTS_X_DIST), Y_POS_SYS_REL(bottom_ori - REP_DOTS_Y2DIST), zoom_factor * REP_DOTS_RADIUS, 0.0, 2.0 * M_PI);
				cairo_fill(cr);
				cairo_new_path(cr);
				cairo_arc(cr, X_POS_PAGE_REL(start - REP_THICK_LINE_DIST - REP_DOTS_X_DIST), Y_POS_SYS_REL(bottom_ori - REP_DOTS_Y1DIST), zoom_factor * REP_DOTS_RADIUS, 0.0, 2.0 * M_PI);
				cairo_arc(cr, X_POS_PAGE_REL(start - REP_THICK_LINE_DIST - REP_DOTS_X_DIST), Y_POS_SYS_REL(bottom_ori - REP_DOTS_Y2DIST), zoom_factor * REP_DOTS_RADIUS, 0.0, 2.0 * M_PI);
				cairo_fill(cr);
				sig_xpos += 2 * REP_DOTS_X_DIST;
				//draw_default_line = false;
				break;
		}
		switch (realtype & TIMESIG_TYPE_MASK) {
			case TIMESIG: 
				if (special_position == SPECIAL_POSITION_START) {
					if ((realtype & REP_TYPE_MASK) == 0) return;
					break;
				}
				if (special_position == SPECIAL_POSITION_END && spec_measure_at_end) return;
				cairo_glyph_t glyph[2];
				int n;
				switch (m_special_descr->symbol) {
					case TIME_SYMBOL_COMMON_TIME:
						glyph[0].index = BASE + 56;
						glyph[0].x = X_POS_PAGE_REL(sig_xpos + m_staff_elements_width);
						glyph[0].y = Y_POS_STAFF_REL(5 * LINE_DIST/2.0);
						cairo_show_glyphs(cr, glyph, 1);
						cairo_stroke(cr);
						break;
					case TIME_SYMBOL_CUT_TIME:
						glyph[0].index = BASE + 57;
						glyph[0].x = X_POS_PAGE_REL(sig_xpos + m_staff_elements_width);
						glyph[0].y = Y_POS_STAFF_REL(5 * LINE_DIST/2.0);
						cairo_show_glyphs(cr, glyph, 1);
						cairo_stroke(cr);
						break;
					default:
						cairo_new_path(cr);
						n = m_special_descr->numerator;
						if (n > 9) {
							glyph[0].index = NUMBERBASE + n / 10;
							glyph[0].x =  X_POS_PAGE_REL(sig_xpos + m_staff_elements_width - SIG_HALF);
							glyph[0].y = Y_POS_STAFF_REL(Y_NUMRATOR_POS + 4 * LINE_DIST);
							glyph[1].index = NUMBERBASE + n % 10;
							glyph[1].x =  X_POS_PAGE_REL(sig_xpos + m_staff_elements_width + SIG_HALF);
							glyph[1].y = Y_POS_STAFF_REL(Y_NUMRATOR_POS + 4 * LINE_DIST);
							cairo_show_glyphs(cr, glyph, 2);
						}
						else {
					
							glyph[0].index = NUMBERBASE + n;
							glyph[0].x =  X_POS_PAGE_REL(sig_xpos + m_staff_elements_width);
							glyph[0].y = Y_POS_STAFF_REL(Y_NUMRATOR_POS + 4 * LINE_DIST);
							cairo_show_glyphs(cr, glyph, 1);
						}
						n = m_special_descr->denominator;
						if (n > 9) {
							glyph[0].index = NUMBERBASE + n / 10;
							glyph[0].x =  X_POS_PAGE_REL(sig_xpos + m_staff_elements_width - SIG_HALF);
							glyph[0].y = Y_POS_STAFF_REL(Y_DENOMINATOR_POS + 4 * LINE_DIST);
							glyph[1].index = NUMBERBASE + n % 10;
							glyph[1].x =  X_POS_PAGE_REL(sig_xpos + m_staff_elements_width + SIG_HALF);
							glyph[1].y = Y_POS_STAFF_REL(Y_DENOMINATOR_POS + 4 * LINE_DIST);
							cairo_show_glyphs(cr, glyph, 2);
						}
						else {
							glyph[0].index = NUMBERBASE + n;
							glyph[0].x =  X_POS_PAGE_REL(sig_xpos + m_staff_elements_width);
							glyph[0].y = Y_POS_STAFF_REL(Y_DENOMINATOR_POS + 4 * LINE_DIST);
							cairo_show_glyphs(cr, glyph, 1);
						}
						cairo_stroke(cr);
						break;
					}
				break;
		}
	}
	if ((special_position == SPECIAL_POSITION_END && spec_measure_at_end) || !draw_default_line) return;
	cairo_new_path(cr);
	cairo_set_line_width(cr, zoom_factor * ((special_position == SPECIAL_POSITION_END) ? 2 * MEASURE_LINE_THICK : MEASURE_LINE_THICK));
	cairo_move_to(cr, X_POS_PAGE_REL(normal_line_pos), Y_POS_SYS_REL(top));
	cairo_line_to(cr, X_POS_PAGE_REL(normal_line_pos), Y_POS_SYS_REL(line_bottom));
//#define SHOW_MEAS_NUM
#ifdef SHOW_MEAS_NUM
	cairo_select_font_face(cr, "Sans", CAIRO_FONT_SLANT_ITALIC, CAIRO_FONT_WEIGHT_NORMAL);
	cairo_set_font_size(cr, MEASURE_NUMBER_SIZE * zoom_factor);
	cairo_move_to(cr, X_POS_PAGE_REL(normal_line_pos - MEASURE_NUMBER_X_DIST), Y_POS_SYS_REL(top - MEASURE_NUMBER_Y_DIST));
	cairo_show_text(cr, m_measure_number_str);
#ifdef HAS_SET_SCALED_FONT
	cairo_set_scaled_font (cr, scaled_font);
#else
	cairo_set_font_face(cr, NedResource::getFontFace());
	cairo_set_font_matrix(cr,  NedResource::getFontMatrix(zoom_level));
#endif
#endif
	cairo_stroke(cr);
}

unsigned int NedMeasure::getStoredStaffCount() {return m_position_array.getStoredStaffCount();}

void NedMeasure::setNewStaffCount(int newstaffcount) {
	m_position_array.setNewStaffCount(newstaffcount);
}