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 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481
|
/****************************************************************************************/
/* */
/* 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 <string.h>
#include <math.h>
#include <gdk/gdkkeysyms.h>
#include "page.h"
#include "system.h"
#include "mainwindow.h"
#include "clipboard.h"
#include "staff.h"
#include "deletesystemcommand.h"
#include "appendsystemcommand.h"
#include "movesystemcommand.h"
#include "removepagecommand.h"
#include "insertfreeplaceablecommand.h"
#include "getsystemfromnextpagecmmand.h"
#include "commandhistory.h"
#include "commandlist.h"
#include "chordorrest.h"
#include "volumesign.h"
#include "temposign.h"
#include "scoreinfodialog.h"
#include "slurpoint.h"
#include "slur.h"
#include "linepoint.h"
#include "crescendo.h"
#include "linesdialog.h"
#include "octavation.h"
#include "acceleration.h"
#include "freesign.h"
#include "freechord.h"
#include "freespacer.h"
#include "pangocairotext.h"
#include "freechordname.h"
#define X_POS_INVERS(p) ((leftx + (p) / current_scale) / zoom_factor - m_xpos)
#define Y_POS_INVERS(p) ((topy + (p) / current_scale) / zoom_factor)
#define X_POS_INVERS_PAGE_REL(p) (((leftx + (p) / current_scale) / zoom_factor - getContentXpos()))
#define X_POS(p) (((p) + m_xpos) * zoom_factor - leftx)
#define Y_POS(p) ((p) * zoom_factor - topy)
#define X_POS_PAGE_REL(p) (((p) + getContentXpos()) * zoom_factor - leftx)
#define DEFAULT_SYSTEM_DIST (2 * 5 * LINE_DIST)
NedPage::NedPage(NedMainWindow *main_window, double width, double height, int nr, unsigned int start_measure_number, bool start) :
m_systems(NULL), m_xpos(nr * (width + DEFAULT_BORDER)),
m_width(width), m_height(height), default_border(DEFAULT_BORDER), m_page_number(nr), m_main_window(main_window)
{
int i;
double system_pos = TOP_BOTTOM_BORDER;
NedSystem *system;
if (start) {
i = 0;
m_system_diff = 100.0;
m_systems = g_list_append(m_systems, system = new NedSystem(this, system_pos,
m_width - 2 * (LEFT_RIGHT_BORDER - DEFAULT_BORDER), i, start_measure_number, TRUE));
placeStaffs(0);
/*
do {
m_systems = g_list_append(m_systems, system = new NedSystem(this, system_pos,
m_width - 2 * (LEFT_RIGHT_BORDER - DEFAULT_BORDER), i, start_measure_number, TRUE));
system_pos += system->getHeight() + DEFAULT_SYSTEM_DIST;
i++;
placeStaffs(0);
}
while (m_system_diff > MIN_SYSTEM_Y_DIST);
if (g_list_length(m_systems) > 1) {
lptr = g_list_last(m_systems);
delete ((NedSystem *) lptr->data);
m_systems = g_list_delete_link(m_systems, lptr);
placeStaffs(0);
}
*/
}
}
NedPage::~NedPage() {
GList *lptr;
for (lptr = g_list_first(m_systems); lptr; lptr = g_list_next(lptr)) {
delete ((NedSystem *) lptr->data);
}
g_list_free(m_systems);
m_systems = NULL;
}
NedPage *NedPage::clone(struct addr_ref_str **addrlist, struct addr_ref_str **slurlist, NedMainWindow *p_main_window, bool *staves) {
GList *lptr;
NedPage *page = new NedPage(p_main_window, m_width, m_height, m_page_number, ((NedSystem *)g_list_first(m_systems)->data)->getNumberOfFirstMeasure(), false);
for (lptr = g_list_first(m_systems); lptr; lptr = g_list_next(lptr)) {
page->m_systems = g_list_append(page->m_systems, ((NedSystem *) lptr->data)->clone(addrlist, slurlist, page, staves));
}
return page;
}
void NedPage::adjust_pointers(struct addr_ref_str *addrlist, struct addr_ref_str *slurlist) {
GList *lptr;
for (lptr = g_list_first(m_systems); lptr; lptr = g_list_next(lptr)) {
((NedSystem *) lptr->data)->adjust_pointers(addrlist, slurlist);
}
}
#ifdef XXX
void NedPage::removeAllBeams() {
GList *lptr;
for (lptr = g_list_first(m_systems); lptr; lptr = g_list_next(lptr)) {
((NedSystem *) lptr->data)->removeAllBeams();
}
}
#endif
double NedPage::getTopPos() {return (2 * default_border + m_height) * m_main_window->getCurrentZoomFactor();}
double NedPage::getLeftPos() {return (( m_xpos + 2*default_border + m_width)) * m_main_window->getCurrentZoomFactor();}
NedSystem *NedPage::appendSystem() {
int system_nr;
NedSystem *system;
system_nr = g_list_length(m_systems);
m_systems = g_list_append(m_systems, system = new NedSystem(this, 0,
m_width - 2 * (LEFT_RIGHT_BORDER - DEFAULT_BORDER), system_nr, 1, TRUE));
placeStaffs(0);
return system;
}
void NedPage::insertSystem(NedSystem *system) {
m_systems = g_list_prepend(m_systems, system);
system->changePageInfo(this);
}
void NedPage::removeSystem(NedSystem *system) {
GList *lptr;
int system_nr;
if ((lptr = g_list_find(m_systems, system)) == NULL) {
NedResource::Abort("NedPage::removeSystem");
}
m_systems = g_list_delete_link(m_systems, lptr);
for (system_nr = 0, lptr = g_list_first(m_systems); lptr; system_nr++, lptr = g_list_next(lptr)) {
((NedSystem *) lptr->data)->setSystemNumber(system_nr);
}
}
void NedPage::appendSystem(NedCommandList *command_list) {
NedAppendSystemCommand *append_sys_cmd = new NedAppendSystemCommand(this);
append_sys_cmd->execute();
command_list->addCommand(append_sys_cmd);
}
bool NedPage::isPageOverflow() {
if (g_list_length(m_systems) < 2) return false;
do_place_staffs(0.0);
return m_system_diff <= MIN_SYSTEM_Y_DIST;
}
unsigned int NedPage::getNumberOfLastMeasure() {
GList *lptr;
lptr = g_list_last(m_systems);
if (lptr == NULL) {
NedResource::Abort("NedPage::getNumberOfLastMeasure");
}
return ((NedSystem *) g_list_last(m_systems)->data)->getNumberOfLastMeasure();
}
int NedPage::getSorting(NedStaff *this_staff, NedSystem *this_system, NedStaff *other_staff, NedSystem *other_system) {
int pos0, pos1;
if (this_staff->getStaffNumber() != other_staff->getStaffNumber()) {
return SORTING_NONE;
}
if ((pos0 = g_list_index(m_systems, this_system)) < 0) {
NedResource::Warning("NedPage::getSorting: didn't foind system 0");
return SORTING_NONE;
}
if ((pos1 = g_list_index(m_systems, other_system)) < 0) {
NedResource::Warning("dNedPage::getSorting: idn't foind system 1");
return SORTING_NONE;
}
if (pos0 + 1 == pos1) {
return SORTING_GREAT;
}
if (pos1 + 1 == pos0) {
return SORTING_LESS;
}
return SORTING_NONE;
}
bool NedPage::isFirst(NedSystem *system) {
GList *lptr;
if ((lptr = g_list_find(m_systems, system)) == NULL) {
NedResource::Abort("NedPage::isFirst");
}
return (lptr == g_list_first(m_systems));
}
bool NedPage::isLast(NedSystem *system) {
GList *lptr;
if ((lptr = g_list_find(m_systems, system)) == NULL) {
NedResource::Abort("NedPage::isLast");
}
return (lptr == g_list_last(m_systems));
}
NedSystem *NedPage::getLastSystem() {
return (NedSystem *) g_list_last(m_systems)->data;
}
bool NedPage::find_staff_and_line(int x, int y, NedStaff **last_staff, int *last_line) {
double zoom_factor = m_main_window->getCurrentZoomFactor();
double current_scale = m_main_window->getCurrentScale();
double leftx = m_main_window->getLeftX();
double bottom;
double xl = X_POS_INVERS(x);
double yl2;
if (xl < 0.0 || xl > m_width) return false;
return findLine(x, y, &yl2, last_line, &bottom, last_staff);
}
void NedPage::draw(cairo_t *cr, bool show_measure_numbers, double main_width, double main_height) {
double leftx = m_main_window->getLeftX();
double topy = m_main_window->getTopY();
double zoom_factor = m_main_window->getCurrentZoomFactor();
double scale = m_main_window->getCurrentScale();
ScoreInfo *score_info = NULL;
double xp, yp;
bool first = true;
bool freetext_or_lyrics_present;
cairo_scale(cr, m_main_window->getCurrentScale(), m_main_window->getCurrentScale());
if (!m_main_window->doDrawPostscript()) {
if ((m_xpos * zoom_factor - leftx) * scale > main_width) {cairo_identity_matrix(cr); return;}
if (((m_xpos + (DEFAULT_BORDER + m_width)) * zoom_factor - leftx) * scale < 0) {cairo_identity_matrix(cr); return;}
cairo_set_source_rgb (cr, 0.3, 0.3, 0.3);
cairo_rectangle (cr, m_xpos * zoom_factor - leftx, -topy,
(2 * DEFAULT_BORDER + m_width) * zoom_factor,
(2 * DEFAULT_BORDER + m_height) * zoom_factor);
cairo_fill(cr);
cairo_set_source_rgb (cr, 1.0, 1.0, 1.0);
cairo_rectangle (cr, (m_xpos + DEFAULT_BORDER) * zoom_factor -leftx,
DEFAULT_BORDER * zoom_factor - topy,
m_width * zoom_factor, m_height * zoom_factor);
cairo_fill(cr);
cairo_set_source_rgb (cr, 0.0, 0.0, 0.0);
xp = m_xpos;
}
else {
cairo_set_source_rgb (cr, 1.0, 1.0, 1.0);
cairo_rectangle (cr, (DEFAULT_BORDER) * zoom_factor,
DEFAULT_BORDER * zoom_factor,
m_width * zoom_factor, m_height * zoom_factor);
cairo_fill(cr);
cairo_set_source_rgb (cr, 0.0, 0.0, 0.0);
xp = 0.0;
}
if (m_page_number == 0) {
cairo_identity_matrix(cr);
yp = 0.0;
score_info = getMainWindow()->getScoreInfo();
if (m_main_window->getScoreInfo()->title != NULL) {
score_info->title->draw(cr, ((xp + DEFAULT_BORDER + (m_width - score_info->title_extends.width) / 2.0) * zoom_factor -leftx ) * scale,
(STAFF_TOP_DIST + score_info->title_extends.height) * zoom_factor - topy, zoom_factor, scale);
yp += score_info->title_extends.height + 4.0 * SCORE_INFO_EXTRA_DIST;
}
if (m_main_window->getScoreInfo()->subject != NULL) {
score_info->subject->draw(cr, ((xp + DEFAULT_BORDER + (m_width - score_info->subject_extends.width) / 2.0) * zoom_factor -leftx) * scale,
(STAFF_TOP_DIST + yp + score_info->subject_extends.height) * zoom_factor - topy, zoom_factor, scale);
yp += score_info->subject_extends.height;
}
if (m_main_window->getScoreInfo()->composer != NULL) {
score_info->composer->draw(cr, ((xp + DEFAULT_BORDER + (m_width - score_info->composer_extends.width - DEFAULT_BORDER - LEFT_RIGHT_BORDER)) * zoom_factor -leftx) * scale,
(STAFF_TOP_DIST + yp + score_info->composer_extends.height) * zoom_factor - topy, zoom_factor, scale);
yp += score_info->composer_extends.height + SCORE_INFO_EXTRA_DIST;
}
if (m_main_window->getScoreInfo()->arranger != NULL) {
score_info->arranger->draw(cr, ((xp + DEFAULT_BORDER + (m_width - score_info->arranger_extends.width - DEFAULT_BORDER - LEFT_RIGHT_BORDER)) * zoom_factor -leftx) * scale,
(STAFF_TOP_DIST + yp + score_info->arranger_extends.height) * zoom_factor - topy, zoom_factor, scale);
yp += score_info->arranger_extends.height + SCORE_INFO_EXTRA_DIST;
}
if (m_main_window->getScoreInfo()->copyright != NULL) {
score_info->copyright->draw(cr, ((xp + DEFAULT_BORDER + (m_width - score_info->copyright_extends.width - DEFAULT_BORDER - LEFT_RIGHT_BORDER)) * zoom_factor -leftx) * scale,
(STAFF_TOP_DIST + yp + score_info->copyright_extends.height) * zoom_factor - topy, zoom_factor, scale);
}
cairo_scale(cr, m_main_window->getCurrentScale(), m_main_window->getCurrentScale());
}
GList *lptr;
freetext_or_lyrics_present = false;
for (lptr = g_list_first(m_systems); lptr; lptr = g_list_next(lptr)) {
((NedSystem *) lptr->data)->draw(cr, m_page_number == 0 && first, show_measure_numbers, &freetext_or_lyrics_present);
first = false;
}
cairo_identity_matrix(cr);
if (freetext_or_lyrics_present) {
first = true;
for (lptr = g_list_first(m_systems); lptr; lptr = g_list_next(lptr)) {
((NedSystem *) lptr->data)->drawTexts(cr, m_page_number == 0 && first, scale);
first = false;
}
}
cairo_show_page(cr);
};
int NedPage::getNumberOfStaffs() {
return ((NedSystem *) g_list_first(m_systems)->data)->getNumberOfStaffs();
}
double NedPage::getContentXpos() {
if (m_main_window->doDrawPostscript()) {
return LEFT_RIGHT_BORDER;
}
return m_xpos + LEFT_RIGHT_BORDER;
}
bool NedPage::isLastPage() {
return m_main_window->getLastPage() == this;
}
bool NedPage::isLastSystem(NedSystem *system) {
GList *lptr;
if (m_main_window->getLastPage() != this) return false;
if ((lptr = g_list_last(m_systems)) == NULL) {
NedResource::Abort("NedPage::isLastSystem");
}
return (((NedSystem *) lptr->data) == system);
}
void NedPage::setAndUpdateClefTypeAndKeySig(int *clef_and_key_array, bool first) {
GList *lptr;
double indent = first ? m_main_window->getFirstSystemIndent() : m_main_window->get2ndSystemIndent();
if ((lptr = g_list_first(m_systems)) == NULL) return;
((NedSystem *) lptr->data)->setAndUpdateClefTypeAndKeySig(clef_and_key_array, indent, first);
indent = m_main_window->get2ndSystemIndent();
for (lptr = g_list_next(lptr); lptr; lptr = g_list_next(lptr)) {
((NedSystem *) lptr->data)->setAndUpdateClefTypeAndKeySig(clef_and_key_array, indent, false);
}
}
void NedPage::determineTempoInverse(NedChordOrRest *element, NedSystem* system, double *tempoinverse, bool *found) {
GList *lptr;
for (lptr = g_list_first(m_systems); lptr; lptr = g_list_next(lptr)) {
if ((NedSystem *) lptr->data == system) {
((NedSystem *) lptr->data)->determineTempoInverse(element, element->getMidiTime(), tempoinverse, found);
break;
}
((NedSystem *) lptr->data)->determineTempoInverse(NULL, element->getMidiTime(), tempoinverse, found);
}
}
void NedPage::detectVoices(int staff_nr, unsigned int *voice_mask, NedSystem **last_system, unsigned long long *end_time) {
GList *lptr;
for (lptr = g_list_first(m_systems); lptr; lptr = g_list_next(lptr)) {
((NedSystem *) lptr->data)->detectVoices(staff_nr, voice_mask, last_system, end_time);
}
}
void NedPage::cutEmptyVoices() {
GList *lptr;
for (lptr = g_list_first(m_systems); lptr; lptr = g_list_next(lptr)) {
((NedSystem *) lptr->data)->cutEmptyVoices();
}
}
void NedPage::handleEmptyMeasures() {
GList *lptr;
for (lptr = g_list_first(m_systems); lptr; lptr = g_list_next(lptr)) {
((NedSystem *) lptr->data)->handleEmptyMeasures();
}
}
bool NedPage::hasOnlyRests() {
GList *lptr;
for (lptr = g_list_first(m_systems); lptr; lptr = g_list_next(lptr)) {
if (!((NedSystem *) lptr->data)->hasOnlyRests()) return false;
}
return true;
}
void NedPage::setAllUnpositioned() {
GList *lptr;
for (lptr = g_list_first(m_systems); lptr; lptr = g_list_next(lptr)) {
((NedSystem *) lptr->data)->m_is_positioned = false;
}
}
void NedPage::zoomFreeReplaceables(double zoom, double scale) {
GList *lptr;
for (lptr = g_list_first(m_systems); lptr; lptr = g_list_next(lptr)) {
((NedSystem *) lptr->data)->zoomFreeReplaceables(zoom, scale);
}
}
void NedPage::recomputeFreeReplaceables() {
GList *lptr;
for (lptr = g_list_first(m_systems); lptr; lptr = g_list_next(lptr)) {
((NedSystem *) lptr->data)->recomputeFreeReplaceables();
}
}
void NedPage::testTies() {
GList *lptr;
for (lptr = g_list_first(m_systems); lptr; lptr = g_list_next(lptr)) {
((NedSystem *) lptr->data)->testTies();
}
}
bool NedPage::exportLilyPond(FILE *fp, int staff_nr, int voice_nr, int *last_line, unsigned int *midi_len,
NedSystem *last_system, unsigned long long end_time, bool *in_alternative, NedSlur **lily_slur, unsigned int *lyrics_map,
bool with_break, bool *guitar_chordnames, bool *chordnames, int *breath_script, bool keep_beams) {
GList *lptr;
for (lptr = g_list_first(m_systems); lptr; lptr = g_list_next(lptr)) {
((NedSystem *) lptr->data)->exportLilyPond(fp, staff_nr, voice_nr, last_line, midi_len, last_system,
end_time, in_alternative, lily_slur, lyrics_map, with_break, guitar_chordnames, chordnames, breath_script, keep_beams);
if ((NedSystem *) lptr->data == last_system) return false;
}
return true;
}
bool NedPage::exportLilyGuitarChordnames(FILE *fp, int staff_nr, int *last_line, unsigned int *midi_len,
NedSystem *last_system, unsigned long long end_time, bool *in_alternative, bool with_break) {
GList *lptr;
for (lptr = g_list_first(m_systems); lptr; lptr = g_list_next(lptr)) {
((NedSystem *) lptr->data)->exportLilyGuitarChordnames(fp, staff_nr, last_line, midi_len, last_system, end_time, in_alternative, with_break);
if ((NedSystem *) lptr->data == last_system) return false;
}
return true;
}
bool NedPage::exportLilyFreeChordName(FILE *fp, int staff_nr, int *last_line, unsigned int *midi_len,
NedSystem *last_system, unsigned long long end_time, bool *in_alternative, bool with_break) {
GList *lptr;
for (lptr = g_list_first(m_systems); lptr; lptr = g_list_next(lptr)) {
((NedSystem *) lptr->data)->exportLilyFreeChordName(fp, staff_nr, last_line, midi_len, last_system, end_time, in_alternative, with_break);
if ((NedSystem *) lptr->data == last_system) return false;
}
return true;
}
bool NedPage::exportLilyLyrics(FILE *fp, int staff_nr, int voice_nr, int line_nr, NedSystem *last_system, unsigned long long end_time, int *sil_count) {
GList *lptr;
for (lptr = g_list_first(m_systems); lptr; lptr = g_list_next(lptr)) {
((NedSystem *) lptr->data)->exportLilyLyrics(fp, ((NedSystem *) lptr->data) == last_system, staff_nr, voice_nr, line_nr, end_time, sil_count);
if (((NedSystem *) lptr->data) == last_system) return false;
}
return true;
}
void NedPage::collectLyrics(NedLyricsEditor *leditor, int staff_nr) {
GList *lptr;
for (lptr = g_list_first(m_systems); lptr; lptr = g_list_next(lptr)) {
((NedSystem *) lptr->data)->collectLyrics(leditor, staff_nr);
}
}
void NedPage::setLyrics(NedCommandList *command_list, NedLyricsEditor *leditor, int staff_nr) {
GList *lptr;
for (lptr = g_list_first(m_systems); lptr; lptr = g_list_next(lptr)) {
((NedSystem *) lptr->data)->setLyrics(command_list, leditor, staff_nr);
}
}
void NedPage::copyDataOfWholeStaff(int staff_nr) {
GList *lptr;
for (lptr = g_list_first(m_systems); lptr; lptr = g_list_next(lptr)) {
((NedSystem *) lptr->data)->copyDataOfWholeStaff(staff_nr);
}
}
void NedPage::handleStaffElements() {
GList *lptr;
for (lptr = g_list_first(m_systems); lptr; lptr = g_list_next(lptr)) {
((NedSystem *) lptr->data)->handleStaffElements();
}
}
void NedPage::setInternalPitches() {
GList *lptr;
for (lptr = g_list_first(m_systems); lptr; lptr = g_list_next(lptr)) {
((NedSystem *) lptr->data)->setInternalPitches();
}
}
void NedPage::adjustAccidentals(int staff_nr) {
GList *lptr;
for (lptr = g_list_first(m_systems); lptr; lptr = g_list_next(lptr)) {
((NedSystem *) lptr->data)->adjustAccidentals(staff_nr);
}
}
void NedPage::changeAccidentals(NedCommandList *command_list, int preferred_offs, bool *staff_list, GList *selected_group) {
GList *lptr;
for (lptr = g_list_first(m_systems); lptr; lptr = g_list_next(lptr)) {
((NedSystem *) lptr->data)->changeAccidentals(command_list, preferred_offs, staff_list, selected_group);
}
}
void NedPage::transpose(int pitchdist, bool *staff_list, GList *selected_group) {
GList *lptr;
for (lptr = g_list_first(m_systems); lptr; lptr = g_list_next(lptr)) {
((NedSystem *) lptr->data)->transpose(pitchdist, staff_list, selected_group);
}
}
void NedPage::hideRests(NedCommandList *command_list, bool unhide, int staff_nr, int voice_nr) {
GList *lptr;
for (lptr = g_list_first(m_systems); lptr; lptr = g_list_next(lptr)) {
((NedSystem *) lptr->data)->hideRests(command_list, unhide, staff_nr, voice_nr);
}
}
bool NedPage::shiftNotes(unsigned long long start_time, int linedist, NedSystem *start_system, int staff_number) {
GList *lptr;
if (start_system == 0) {
lptr = g_list_first(m_systems);
}
else {
if ((lptr = g_list_find(m_systems, start_system)) == NULL) {
NedResource::Abort("NedPage::shiftNotes");
}
}
for (; lptr; lptr = g_list_next(lptr)) {
if (!((NedSystem *) lptr->data)->shiftNotes(start_time, linedist, staff_number)) {
return false;
}
}
return true;
}
void NedPage::removeUnneededAccidentals(int staff_nr /* = -1 */) {
GList *lptr;
for (lptr = g_list_first(m_systems); lptr; lptr = g_list_next(lptr)) {
((NedSystem *) lptr->data)->removeUnneededAccidentals(staff_nr);
}
}
void NedPage::prepareReplay(bool with_keysig /* = false */) {
GList *lptr;
for (lptr = g_list_first(m_systems); lptr; lptr = g_list_next(lptr)) {
((NedSystem *) lptr->data)->prepareReplay(with_keysig);
NedResource::increaseSystemStartTime(((NedSystem *) lptr->data)->getSystemEndTime());
}
}
void NedPage::reconfig_paper(double width, double height) {
GList *lptr;
m_xpos = m_page_number * (width + DEFAULT_BORDER) * m_main_window->getCurrentScale();
m_width = width; m_height = height;
for (lptr = g_list_first(m_systems); lptr; lptr = g_list_next(lptr)) {
((NedSystem *) lptr->data)->setWidth(m_width - 2 * (LEFT_RIGHT_BORDER - DEFAULT_BORDER));
}
}
void NedPage::getLinePoints(NedStaff *start_staff, NedStaff *end_staff, GList **staves) {
GList *lptr;
NedStaff *staff;
NedPage *next_page;
int staff_nr = start_staff->getStaffNumber();
int i;
if (start_staff->getPage() != this) {
if ((next_page = m_main_window->getNextPage(this)) == NULL) {
NedResource::Abort("NedPage::getLinePoints: error 1");
}
if ((lptr = g_list_find(next_page->m_systems, start_staff->getSystem())) == NULL) {
NedResource::Abort("NedPage::getLinePoints: error 2");
}
}
else {
if ((lptr = g_list_find(m_systems, start_staff->getSystem())) == NULL) {
NedResource::Abort("NedPage::getLinePoints: error 3");
}
}
for (i = 0; i < 2; i++) {
for (; lptr; lptr = g_list_next(lptr)) {
if ((staff = ((NedSystem *) lptr->data)->getStaff(staff_nr)) == NULL) {
NedResource::Abort("NedPage::getLinePoints: error 4");
}
*staves = g_list_append(*staves, staff);
if (staff == end_staff) return;
}
if ((next_page = end_staff->getPage()) == NULL) {
NedResource::Abort("NedPage::getLinePoints: error 6");
}
if ((lptr = g_list_first(next_page->m_systems)) == NULL) {
NedResource::Abort("NedPage::getLinePoints: error 7");
}
}
NedResource::DbgMsg(DBG_CRITICAL, "gesucht wurde in staff %d\n", staff_nr);
NedResource::Abort("NedPage::getLinePoints: error 8");
}
void NedPage::savePage(FILE *fp) {
GList *lptr;
fprintf(fp, "PAGE %d\n", m_page_number);
for (lptr = g_list_first(m_systems); lptr; lptr = g_list_next(lptr)) {
((NedSystem *) lptr->data)->saveSystem(fp);
}
}
void NedPage::restorePage(FILE *fp) {
int i, system_nr;
char buffer[128];
NedSystem *system;
double system_pos = TOP_BOTTOM_BORDER;
i = 0;
do {
if (!NedResource::readWord(fp, buffer)) {
if (feof(fp)) return;
NedResource::m_error_message = "(1)SYSTEM or PAGE expected";
return;
}
if (strcmp(buffer, "SYSTEM")) {
if (!strcmp(buffer, "PAGE")) {
NedResource::unreadWord(buffer);
return;
}
NedResource::DbgMsg(DBG_CRITICAL, "buffer = %s\n", buffer);
NedResource::m_error_message = "(2)SYSTEM or PAGE expected";
return;
}
if (!NedResource::readInt(fp, &system_nr)) {
NedResource::m_error_message = "SYSTEM number expected";
return;
}
/*
if (system_nr != i) {
NedResource::m_error_message = "bad system_nr";
return;
}
*/
if (!NedResource::readWord(fp, buffer) || strcmp(buffer, ":")) {
NedResource::m_error_message = ": expected";
return;
}
system = new NedSystem(this, system_pos, m_width - 2 * (LEFT_RIGHT_BORDER - DEFAULT_BORDER), system_nr, 0 /* dummy is reset during "renumberMeasures()" at the end of "reposit()" */, FALSE);
m_systems = g_list_append(m_systems, system);
system->restoreSystem(fp);
i++;
system_pos += system->getHeight() + DEFAULT_SYSTEM_DIST;
}
while (NedResource::m_error_message == NULL);
}
bool NedPage::tryChangeLength(NedChordOrRest *chord_or_rest) {
GList *lptr;
for (lptr = g_list_first(m_systems); lptr; lptr = g_list_next(lptr)) {
if (((NedSystem *) lptr->data)->tryChangeLength(chord_or_rest)) {
return TRUE;
}
}
return FALSE;
}
bool NedPage::trySelect(double x, double y, bool only_free_placeables /* = false */) {
double zoom_factor = m_main_window->getCurrentZoomFactor();
double leftx = m_main_window->getLeftX();
double current_scale = m_main_window->getCurrentScale();
double xl = X_POS_INVERS(x);
if (xl < 0.0 || xl > m_width) return false;
GList *lptr;
for (lptr = g_list_first(m_systems); lptr; lptr = g_list_next(lptr)) {
if (((NedSystem *) lptr->data)->trySelect(x, y, only_free_placeables)) {
return true;
}
}
return false;
}
NedChordOrRest *NedPage::findNearestElement(int staff_nr, double x, double y, NedStaff *oldstaff, double *ydist) {
double mindist = 10000000.0;
NedChordOrRest *nearestElement = NULL, *element;
GList *lptr;
for (lptr = g_list_first(m_systems); lptr; lptr = g_list_next(lptr)) {
if ((element = ((NedSystem *) lptr->data)->findNearestElement(staff_nr, x, y, oldstaff, &mindist, ydist)) != NULL) {
nearestElement = element;
}
}
return nearestElement;
}
bool NedPage::findTimeOfMeasure(int meas_num, unsigned long long *meas_time, unsigned long long *system_offs) {
GList *lptr;
for (lptr = g_list_first(m_systems); lptr; lptr = g_list_next(lptr)) {
if (((NedSystem *) lptr->data)->findTimeOfMeasure(meas_num, meas_time)) {
return true;
}
*system_offs += ((NedSystem *) lptr->data)->getSystemEndTime();
}
return false;
}
void NedPage::collectSelectionRectangleElements(NedBbox *sel_rect, GList **sel_group, NedSystem *first_selected_system, NedSystem *last_selected_system,
NedPage *first_selected_page, NedPage *last_selected_page) {
double xp = sel_rect->x - m_xpos;
if (xp + sel_rect->width < 0.0 || m_width < xp) return;
GList *lptr;
xp -= LEFT_RIGHT_BORDER;
for (lptr = g_list_first(m_systems); lptr; lptr = g_list_next(lptr)) {
((NedSystem *) lptr->data)->collectSelectionRectangleElements(xp, sel_rect, sel_group, first_selected_system, last_selected_system,
first_selected_page == this, last_selected_page == this);
}
}
void NedPage::findSelectedFirstsLasts(NedBbox *sel_rect, int *number_of_first_selected_staff, int *number_of_last_selected_staff,
NedSystem **first_selected_system, NedSystem **last_selected_system, NedPage **first_selected_page, NedPage **last_selected_page) {
double xp = sel_rect->x - m_xpos;
if (xp + sel_rect->width < 0.0 || m_width < xp) return;
GList *lptr;
xp -= LEFT_RIGHT_BORDER;
if (*first_selected_page == NULL) {
*first_selected_page = *last_selected_page = this;
}
else {
*last_selected_page = this;
}
for (lptr = g_list_first(m_systems); lptr; lptr = g_list_next(lptr)) {
((NedSystem *) lptr->data)->findSelectedSystems(sel_rect, number_of_first_selected_staff, number_of_last_selected_staff, first_selected_system, last_selected_system);
}
}
void NedPage::findFromTo(GList *clipboard, NedPage **min_page, NedPage **max_page, NedSystem **min_sys, NedSystem **max_sys) {
GList *lptr;
for (lptr = g_list_first(m_systems); lptr; lptr = g_list_next(lptr)) {
if (((NedSystem *) lptr->data)->findFromTo(clipboard, min_sys, max_sys)) {
if (*min_page == NULL) {
*min_page = *max_page = this;
}
else {
*max_page = this;
}
}
}
}
void NedPage::deleteItemsFromTo(NedCommandList *command_list, bool is_first_page, bool is_last_page,
NedSystem *min_sys, NedSystem *max_sys, unsigned long long start_midi, unsigned long long end_midi) {
NedSystem *system;
GList *lptr;
for (lptr = g_list_first(m_systems); lptr; lptr = g_list_next(lptr)) {
system = (NedSystem *) lptr->data;
if (is_first_page && system->getSystemNumber() < min_sys->getSystemNumber()) continue;
if (is_last_page && system->getSystemNumber() > max_sys->getSystemNumber()) break;
system->deleteItemsFromTo(command_list, system == min_sys, system == max_sys, start_midi, end_midi);
}
}
void NedPage::removeNotesFromTo(NedCommandList *command_list, GList *items, bool is_first_page, bool is_last_page,
NedSystem *min_sys, NedSystem *max_sys) {
GList *lptr;
NedSystem *system;
for (lptr = g_list_first(m_systems); lptr; lptr = g_list_next(lptr)) {
system = (NedSystem *) lptr->data;
if (is_first_page && system->getSystemNumber() < min_sys->getSystemNumber()) continue;
if (is_last_page && system->getSystemNumber() > max_sys->getSystemNumber()) break;
system->removeNotesFromTo(command_list, items, system == min_sys, system == max_sys);
}
}
void NedPage::testForPageBackwardTies(NedCommandList *command_list) {
((NedSystem *) g_list_first(m_systems)->data)->testForPageBackwardTies(command_list);
}
void NedPage::checkForElementsToSplit(NedCommandList *command_list, int *measure_number) {
GList *lptr;
for (lptr = g_list_first(m_systems); lptr; lptr = g_list_next(lptr)) {
((NedSystem *) lptr->data)->checkForElementsToSplit(command_list, measure_number);
}
}
NedStaff *NedPage::findStaff(double x, double y, NedMeasure **measure) {
double zoom_factor = m_main_window->getCurrentZoomFactor();
double current_scale = m_main_window->getCurrentScale();
double leftx = m_main_window->getLeftX();
NedStaff *staff;
double xl = X_POS_INVERS(x);
if (xl < 0.0 || xl > m_width) return NULL;
GList *lptr;
for (lptr = g_list_first(m_systems); lptr; lptr = g_list_next(lptr)) {
if ((staff = ((NedSystem *) lptr->data)->findStaff(xl + m_xpos, y, measure)) != NULL) {
return staff;
}
}
return NULL;
}
double NedPage::convertX(double xpos) {
double zoom_factor = m_main_window->getCurrentZoomFactor();
double leftx = m_main_window->getLeftX();
return m_main_window->getCurrentScale() * X_POS_PAGE_REL(xpos);
}
bool NedPage::isXOnPage(double x) {
double zoom_factor = m_main_window->getCurrentZoomFactor();
double current_scale = m_main_window->getCurrentScale();
double leftx = m_main_window->getLeftX();
double xl = X_POS_INVERS(x);
if (xl < 0.0 || xl > m_width) return false;
return true;
}
bool NedPage::tryInsertOrErease(double x, double y, int num_midi_input_notes, int *midi_input_chord /* given if insert from midikeyboard */, NedChordOrRest **newObj /* = NULL */, bool force_rest /* = false */) {
double zoom_factor = m_main_window->getCurrentZoomFactor();
double current_scale = m_main_window->getCurrentScale();
double leftx = m_main_window->getLeftX();
NedChordOrRest *element;
NedChordName *chordname;
double dummy, dummy0;
double topy, xx, yy;
double xx2, yy2;
unsigned int kind, tempo;
NedCommandList *command_list;
NedLinePoint *lp0, *lp1, *lp2;
if (newObj != NULL) {
*newObj = NULL;
}
double xl = X_POS_INVERS(x);
#define LINE_START_X_DIST 2.0
#define SLUR_START_X_DIST 1.0
#define SLUR_START_Y_DIST ( 2 * LINE_DIST )
if (xl < 0.0 || xl > m_width) return FALSE;
GList *lptr;
double mindist, d;
if (midi_input_chord == NULL) { // x, y given
switch(m_main_window->getSpecialType()) {
case TYPE_DYNAMIC:
case TYPE_TEMPO:
topy = m_main_window->getTopY();
xx = X_POS_INVERS_PAGE_REL(x);
yy = Y_POS_INVERS(y);
element = findNearestElement(-1, xx, yy, NULL, &dummy);
command_list = new NedCommandList(m_main_window);
if (m_main_window->getSpecialType() == TYPE_DYNAMIC) {
command_list->addCommand(new NedInsertFreePlaceableCommand(new NedVolumeSign(m_main_window->getSpecialSubTypeInt()), element, xx, yy));
}
else {
kind = (m_main_window->getSpecialSubTypeInt() & 0xffff) * FACTOR;
tempo = ((m_main_window->getSpecialSubTypeInt() >> 16) & 0xffff);
command_list->addCommand(new NedInsertFreePlaceableCommand(new NedTempoSign(kind, tempo), element, xx, yy));
}
command_list->execute();
m_main_window->getCommandHistory()->addCommandList(command_list);
m_main_window->resetSpecialType();
return TRUE;
case TYPE_SIGN:
topy = m_main_window->getTopY();
xx = X_POS_INVERS_PAGE_REL(x);
yy = Y_POS_INVERS(y);
element = findNearestElement(-1, xx, yy, NULL, &dummy);
command_list = new NedCommandList(m_main_window);
command_list->addCommand(new NedInsertFreePlaceableCommand(new NedFreeSign(m_main_window->getSpecialSubTypeInt()), element, xx, yy));
command_list->execute();
m_main_window->getCommandHistory()->addCommandList(command_list);
m_main_window->resetSpecialType();
return TRUE;
case TYPE_GUITAR_CHORD:
topy = m_main_window->getTopY();
xx = X_POS_INVERS_PAGE_REL(x);
yy = Y_POS_INVERS(y);
#define CHOR_NAME_Y_DIST 0.4
#define CHOR_NAME_X_DIST 0.4
element = findNearestElement(-1, xx, yy, NULL, &dummy);
xx2 = element->getXPos() - CHOR_NAME_X_DIST;
yy2 = element->getSystem()->getYPos() + element->getStaff()->getTopPos() - CHOR_NAME_Y_DIST;
command_list = new NedCommandList(m_main_window);
command_list->addCommand(new NedInsertFreePlaceableCommand(new NedFreeChord(m_main_window->getSpecialSubTypeChordInfo().chord_ptr,
m_main_window->getSpecialSubTypeChordInfo().chord_name_num,
m_main_window->getSpecialSubTypeChordInfo().status, m_main_window), element, xx2, yy2));
command_list->execute();
m_main_window->setAllUnpositioned();
m_main_window->reposit(command_list);
m_main_window->getCommandHistory()->addCommandList(command_list);
m_main_window->resetSpecialType();
return TRUE;
case TYPE_SPACER:
topy = m_main_window->getTopY();
xx = X_POS_INVERS_PAGE_REL(x);
yy = Y_POS_INVERS(y);
element = findNearestElement(-1, xx, yy, NULL, &dummy);
command_list = new NedCommandList(m_main_window);
command_list->addCommand(new NedInsertFreePlaceableCommand(new NedFreeSpacer(m_main_window), element, xx, yy));
command_list->execute();
m_main_window->setAllUnpositioned();
m_main_window->reposit(command_list);
m_main_window->getCommandHistory()->addCommandList(command_list);
m_main_window->resetSpecialType();
return TRUE;
case TYPE_CHORDNAME:
topy = m_main_window->getTopY();
xx = X_POS_INVERS_PAGE_REL(x);
yy = Y_POS_INVERS(y);
element = findNearestElement(-1, xx, yy, NULL, &dummy);
xx2 = element->getXPos() - CHOR_NAME_X_DIST;
yy2 = element->getSystem()->getYPos() + element->getStaff()->getTopPos() - m_main_window->getSpecialSubTypeChordNameInfo().ydist;
command_list = new NedCommandList(m_main_window);
command_list->addCommand(new NedInsertFreePlaceableCommand(chordname = new NedChordName(m_main_window->getDrawingArea(),m_main_window->getSpecialSubTypeChordNameInfo().root_name,
m_main_window->getSpecialSubTypeChordNameInfo().up_name,m_main_window->getSpecialSubTypeChordNameInfo().down_name, m_main_window->getSpecialSubTypeChordNameInfo().fontsize), element, xx2, yy2));
chordname->setZoom(zoom_factor, current_scale);
command_list->execute();
m_main_window->setAllUnpositioned();
m_main_window->reposit(command_list);
m_main_window->getCommandHistory()->addCommandList(command_list);
//m_main_window->resetSpecialType();
return TRUE;
case TYPE_FREE_TEXT:
topy = m_main_window->getTopY();
xx = X_POS_INVERS_PAGE_REL(x);
yy = Y_POS_INVERS(y);
element = findNearestElement(-1, xx, yy, NULL, &dummy);
command_list = new NedCommandList(m_main_window);
command_list->addCommand(new NedInsertFreePlaceableCommand(m_main_window->m_freetext, element, xx, yy));
m_main_window->m_freetext->setZoom(zoom_factor, current_scale);
command_list->execute();
m_main_window->m_freetext = NULL;
m_main_window->getCommandHistory()->addCommandList(command_list);
m_main_window->resetSpecialType();
return TRUE;
case TYPE_LINE:
topy = m_main_window->getTopY();
xx = X_POS_INVERS_PAGE_REL(x);
if (xx > m_width / 2.0) xx -= 2 * SLUR_START_X_DIST;
yy = Y_POS_INVERS(y);
command_list = new NedCommandList(m_main_window);
element = findNearestElement(-1, xx, yy, NULL, &dummy);
command_list->addCommand(new NedInsertFreePlaceableCommand(lp0 = new NedLinePoint(NULL, 0), element, xx, yy));
dummy0 = 10000000.0;
element = element->getStaff()->findNearestElement(xx + LINE_START_X_DIST, yy, NULL, &dummy0, &dummy);
command_list->addCommand(new NedInsertFreePlaceableCommand(lp1 = new NedLinePoint(NULL, 1), element, xx + LINE_START_X_DIST, yy));
command_list->execute();
switch (m_main_window->getSpecialSubTypeInt()) {
case LINE_CRESCENDO:
case LINE_DECRESCENDO:
new NedCrescendo(lp0, lp1, m_main_window->getSpecialSubTypeInt() == LINE_DECRESCENDO);
break;
case LINE_OCTAVATION1:
case LINE_OCTAVATION_1:
case LINE_OCTAVATION2:
case LINE_OCTAVATION_2:
new NedOctavation(lp0, lp1, m_main_window->getSpecialSubTypeInt());
break;
}
m_main_window->getCommandHistory()->addCommandList(command_list);
m_main_window->resetSpecialType();
m_main_window->m_selected_free_replaceable = lp0;
return TRUE;
case TYPE_LINE3:
topy = m_main_window->getTopY();
xx = X_POS_INVERS_PAGE_REL(x);
//if (xx > m_width / 2.0) xx -= 3 * SLUR_START_X_DIST;
yy = Y_POS_INVERS(y);
command_list = new NedCommandList(m_main_window);
element = findNearestElement(-1, xx, yy, NULL, &dummy);
command_list->addCommand(new NedInsertFreePlaceableCommand(lp0 = new NedLinePoint(NULL, 0), element, xx, yy));
dummy0 = 10000000.0;
element = element->getStaff()->findNearestElement(xx + LINE_START_X_DIST, yy, NULL, &dummy0, &dummy);
command_list->addCommand(new NedInsertFreePlaceableCommand(lp1 = new NedLinePoint(NULL, 1), element, xx + LINE_START_X_DIST, yy));
dummy0 = 10000000.0;
element = element->getStaff()->findNearestElement(xx + 2 * LINE_START_X_DIST, yy, NULL, &dummy0, &dummy);
command_list->addCommand(new NedInsertFreePlaceableCommand(lp2 = new NedLinePoint(NULL, 1), element, xx + 2 * LINE_START_X_DIST, yy));
command_list->execute();
new NedAcceleration(lp0, lp1, lp2, m_main_window->getSpecialSubTypeInt() == LINE_RITARDANDO);
m_main_window->getCommandHistory()->addCommandList(command_list);
m_main_window->resetSpecialType();
m_main_window->m_selected_free_replaceable = lp0;
return TRUE;
}
}
lptr = g_list_first(m_systems);
NedSystem *nearest_system = (NedSystem *) lptr->data;
mindist = nearest_system->computeMidDist(y);
for (lptr = g_list_next(lptr); lptr; lptr = g_list_next(lptr)) {
if ((d = ((NedSystem *) lptr->data)->computeMidDist(y)) < mindist) {
nearest_system = (NedSystem *) lptr->data;
mindist = d;
}
}
if (nearest_system->tryInsertOrErease(x, y, num_midi_input_notes, midi_input_chord, newObj, force_rest)) {
return true;
}
return false;
}
void NedPage::insertSlur(GdkRectangle *selection_rect) {
double zoom_factor = m_main_window->getCurrentZoomFactor();
double current_scale = m_main_window->getCurrentScale();
double leftx = m_main_window->getLeftX();
double topy, xx, yy, yyy;
double xx0, yy0, xx1, yy1, xx2, yy2;
double xdist, ydist, dist;
double dummy, dummy0;
int dir, l, mid;
NedSlurPoint *sp[3];
GList *lptr;
NedChordOrRest *element, *element0, *element1, *element2;
NedCommandList *command_list = new NedCommandList(m_main_window);
if (NedResource::m_main_clip_board == NULL) {
//printf("Paramater vom Rect\n"); fflush(stdout);
topy = m_main_window->getTopY();
xx = X_POS_INVERS_PAGE_REL(selection_rect->x);
if (xx > m_width / 2.0) xx -= (3 * SLUR_START_X_DIST) / zoom_factor;
yy = Y_POS_INVERS(selection_rect->y);
command_list = new NedCommandList(m_main_window);
element = findNearestElement(-1, xx, yy, NULL, &dummy);
yyy = element->getSystem()->getYPos() + element->getStaff()->getMidPos();
command_list->addCommand(new NedInsertFreePlaceableCommand(sp[0] = new NedSlurPoint(NULL, 0), element, xx, yyy));
dummy0 = 10000000.0;
element1 = element->getStaff()->findNearestElement(xx + SLUR_START_X_DIST, yyy - SLUR_START_Y_DIST, NULL, &dummy0, &dummy);
command_list->addCommand(new NedInsertFreePlaceableCommand(sp[1] = new NedSlurPoint(NULL, 1), element1, xx + SLUR_START_X_DIST, yyy - SLUR_START_Y_DIST));
dummy0 = 10000000.0;
element2 = element->getStaff()->findNearestElement(xx + 2 * SLUR_START_X_DIST, yyy - SLUR_START_Y_DIST / 2, NULL, &dummy0, &dummy);
command_list->addCommand(new NedInsertFreePlaceableCommand(sp[2] = new NedSlurPoint(NULL, 2), element2, xx + 2 * SLUR_START_X_DIST, yyy - SLUR_START_Y_DIST / 2));
}
else {
//printf("Paramater von Elementen\n"); fflush(stdout);
dir = 0;
l = g_list_length(NedResource::m_main_clip_board);
if (l < 2) {
NedResource::Abort("l > 2");
}
mid = l / 2;
lptr = g_list_last(NedResource::m_main_clip_board);
dir += ((NedChordOrRest *) lptr->data)->hasUpDir() ? 1 : -1;
element2 = (NedChordOrRest *) lptr->data;
lptr = g_list_first(NedResource::m_main_clip_board);
dir += ((NedChordOrRest *) lptr->data)->hasUpDir() ? 1 : -1;
element0 = (NedChordOrRest *) lptr->data;
#define SLUR_X_DIST_PROLONG (LINE_DIST * 0.5)
xx2 = element2->getXPos() + element2->getBBox()->width_netto + element2->getBBox()->x + SLUR_X_DIST_PROLONG;
yy2 = element2->getStaff()->getTopPos() + element2->getSystem()->getYPos() + element2->getStemBottom();
lptr = g_list_nth(NedResource::m_main_clip_board, mid);
dir += ((NedChordOrRest *) lptr->data)->hasUpDir() ? 1 : -1;
element1 = (NedChordOrRest *) lptr->data;
/*
xx1 = element1->getXPos();
yy1 = element1->getStaff()->getTopPos() + element1->getSystem()->getYPos() + element1->getStemBottom();
*/
dir = (dir > 0.0) ? 1.0 : -1.0;
#define SLUR_MIDDLE_DIST (LINE_DIST * 1.8)
#define SLUR_Y_DIST_UP (LINE_DIST * 1.0)
#define SLUR_Y_DIST_DOWN (LINE_DIST * 2.0)
xx0 = element0->getXPos() + element2->getBBox()->x - SLUR_X_DIST_PROLONG;
yy0 = element0->getStaff()->getTopPos() + element0->getSystem()->getYPos() + element0->getStemBottom();
yy2 += dir * ((dir > 0) ? SLUR_Y_DIST_DOWN : SLUR_Y_DIST_UP);
yy0 += dir * ((dir > 0) ? SLUR_Y_DIST_DOWN : SLUR_Y_DIST_UP);
command_list->addCommand(new NedInsertFreePlaceableCommand(sp[0] = new NedSlurPoint(NULL, 0), element2, xx2, yy2));
command_list->addCommand(new NedInsertFreePlaceableCommand(sp[2] = new NedSlurPoint(NULL, 0), element0, xx0, yy0));
xdist = xx2 - xx0;
ydist = yy2 - yy0;
xx1 = xx0 + xdist / 2.0;
yy1 = yy0 + ydist / 2.0;
dist = sqrt(xdist * xdist + ydist * ydist);
xdist /= dist;
ydist /= dist;
xx1 -= ydist * dir * SLUR_MIDDLE_DIST;
yy1 += xdist * dir * SLUR_MIDDLE_DIST;
command_list->addCommand(new NedInsertFreePlaceableCommand(sp[1] = new NedSlurPoint(NULL, 0), element1, xx1, yy1));
}
command_list->execute();
new NedSlur(sp);
m_main_window->getCommandHistory()->addCommandList(command_list);
m_main_window->resetSpecialType();
m_main_window->m_selected_free_replaceable = sp[2];
}
bool NedPage::findLine(double x, double y, double *ypos, int *line, double *bottom, NedStaff **staff) {
double zoom_factor = m_main_window->getCurrentZoomFactor();
double leftx = m_main_window->getLeftX();
double current_scale = m_main_window->getCurrentScale();
double xl = X_POS_INVERS(x);
if (xl < 0.0 || xl > m_width) return FALSE;
GList *lptr;
double mindist, d;
lptr = g_list_first(m_systems);
if (lptr == NULL) {
return FALSE; // don't know in which case this happens; concerns mainly MIDI import
}
NedSystem *nearest_system = (NedSystem *) lptr->data;
mindist = nearest_system->computeMidDist(y);
for (lptr = g_list_next(lptr); lptr; lptr = g_list_next(lptr)) {
if ((d = ((NedSystem *) lptr->data)->computeMidDist(y)) < mindist) {
nearest_system = (NedSystem *) lptr->data;
mindist = d;
}
}
if (nearest_system->findLine(x, y, ypos, line, bottom, staff)) {
return TRUE;
}
return FALSE;
}
bool NedPage::findXposInOtherMeasure(guint keyval, double x, double y, double *newx, double *newy) {
double zoom_factor = m_main_window->getCurrentZoomFactor();
double current_scale = m_main_window->getCurrentScale();
double leftx = m_main_window->getLeftX();
NedChordOrRest *element;
NedStaff *staff;
NedSystem *system;
double xl = X_POS_INVERS(x);
*newy = y;
if (xl < 0.0 || xl > m_width) return false;
GList *lptr;
double mindist, d;
lptr = g_list_first(m_systems);
NedSystem *nearest_system = (NedSystem *) lptr->data;
mindist = nearest_system->computeMidDist(y);
for (lptr = g_list_next(lptr); lptr; lptr = g_list_next(lptr)) {
if ((d = ((NedSystem *) lptr->data)->computeMidDist(y)) < mindist) {
nearest_system = (NedSystem *) lptr->data;
mindist = d;
}
}
if (nearest_system->findElement(keyval, x, y, &element, &staff)) {
m_main_window->setVisible(element);
leftx = m_main_window->getLeftX();
*newx = X_POS_PAGE_REL(element->getXPos());
return true;
}
else {
if ((lptr = g_list_find(m_systems, nearest_system)) == NULL) {
NedResource::Abort("NedPage::findXposInOtherMeasure");
}
switch (keyval) {
case GDK_Right: lptr = g_list_next(lptr);
if (lptr == NULL) return false;
system = (NedSystem *) lptr->data;
lptr = system->getFirstChordOrRest(staff->getStaffNumber(), 0, 0, false, false);
if (lptr == NULL) return false;
element = (NedChordOrRest *) lptr->data;
m_main_window->setVisible(element);
*newx = X_POS_PAGE_REL(element->getXPos());
*newy = element->getStaff()->getRealYPosOfLine(-3);
return true;
case GDK_Left: lptr = g_list_previous(lptr);
if (lptr == NULL) return false;
system = (NedSystem *) lptr->data;
lptr = system->getLastChordOrRest(staff->getStaffNumber(), 0, 0, false, false);
if (lptr == NULL) return false;
element = (NedChordOrRest *) lptr->data;
m_main_window->setVisible(element);
*newx = X_POS_PAGE_REL(element->getXPos());
*newy = element->getStaff()->getRealYPosOfLine(-3);
return true;
}
}
return false;
}
void NedPage::renumberSystems() {
int i;
GList *lptr;
for (i = 0, lptr = g_list_first(m_systems); lptr; lptr = g_list_next(lptr), i++) {
((NedSystem *) lptr->data)->setSystemNumber(i);
}
}
void NedPage::resetActiveFlags() {
GList *lptr;
for (lptr = g_list_first(m_systems); lptr; lptr = g_list_next(lptr)) {
((NedSystem *) lptr->data)->resetActiveFlags();
}
}
NedPage *NedPage::getNextPage() {
return m_main_window->getNextPage(this);
}
NedPage *NedPage::getPreviousPage() {
return m_main_window->getPreviousPage(this);
}
bool NedPage::placeStaffs(int pass, NedCommandList *command_list /* = NULL */) {
GList *lptr;
NedPage *other_page;
double offs = STAFF_TOP_DIST;
do_place_staffs(offs);
bool changed = FALSE;
if (m_page_number == 0) {
offs += getMainWindow()->getFirstPageYOffs() / getMainWindow()->getCurrentScale();
}
if (pass == 0) m_ping_pong = false;
do_place_staffs(offs);
if (pass == 0 && m_system_diff < 0) {
if (command_list != NULL && g_list_length(m_systems) > 1) {
lptr = g_list_last(m_systems);
if (m_main_window->getLastPage() && hasOnlyRests()) {
NedDeleteSystemCommand *del_system_command = new NedDeleteSystemCommand((NedSystem *) lptr->data);
del_system_command->execute();
command_list->addCommand(del_system_command);
}
else {
other_page = m_main_window->getNextPage(this, command_list);
NedMoveSystemCommand *move_system_command = new NedMoveSystemCommand(this, (NedSystem *) lptr->data, other_page);
move_system_command->execute(); // the commandlist is not executed
command_list->addCommand(move_system_command);
}
changed = TRUE;
do_place_staffs(offs);
}
}
#define MAX_Y_BORDER 1.0
if (pass == 1 && !isEmpty() && !m_ping_pong && command_list != NULL && m_system_diff > MAX_Y_BORDER) {
other_page = m_main_window->getNextPage(this);
if (other_page == NULL) return FALSE;
if ((lptr = g_list_first(other_page->m_systems)) == NULL) {
NedRemovePageCommand *rem_page_command = new NedRemovePageCommand(m_main_window, other_page);
rem_page_command->execute();
command_list->addCommand(rem_page_command);
return FALSE;
}
NedGetSystemFromNextPageCommand *get_system_from_next_page_command =
new NedGetSystemFromNextPageCommand(lptr, this, other_page);
get_system_from_next_page_command->execute(); // the commandlist is not executed; performs placeStaffs()
if (m_system_diff < MIN_SYSTEM_Y_DIST) {
m_ping_pong = TRUE;
get_system_from_next_page_command->unexecute();
delete get_system_from_next_page_command;
}
else {
command_list->addCommand(get_system_from_next_page_command);
changed = TRUE;
}
if (!isEmpty()) {
do_place_staffs(offs);
}
}
return changed;
}
void NedPage::computeTuplets() {
GList *lptr;
for (lptr = g_list_first(m_systems); lptr; lptr = g_list_next(lptr)) {
((NedSystem *) lptr->data)->computeTuplets();
}
}
int NedPage::getSystemCount() {
return g_list_length(m_systems);
}
void NedPage::do_place_staffs(double offs) {
GList *lptr;
double staffpos = TOP_BOTTOM_BORDER + offs;
for (lptr = g_list_first(m_systems); lptr; lptr = g_list_next(lptr)) {
staffpos = ((NedSystem *) lptr->data)->placeStaffs(staffpos);
}
m_system_diff = m_height - staffpos;
}
NedSystem *NedPage::getNextSystem(NedSystem *system, NedCommandList *command_list /* = NULL */) {
GList *lptr;
NedAppendSystemCommand *app_sys_cmd;
NedSystem *system_on_next_page;
bool append_system_if_necessary = ((m_main_window->getLastPage() == this) && (system == ((NedSystem *) g_list_last(m_systems)->data)));
if (isEmpty()) return NULL;
if ((lptr = g_list_find(m_systems, system)) == NULL) {
printf("gesucht war: 0x%p\n", system); fflush(stdout);
NedResource::Abort("NedPage::getNextSystem");
}
if ((lptr = g_list_next(lptr)) == NULL) {
system_on_next_page = m_main_window->getNextSystem(this, NULL);
if (system_on_next_page == NULL) {
if (command_list != NULL && append_system_if_necessary) {
app_sys_cmd = new NedAppendSystemCommand(this);
app_sys_cmd->execute();
command_list->addCommand(app_sys_cmd);
return app_sys_cmd->getSystem();
}
return NULL;
}
return system_on_next_page;
}
return (NedSystem *) lptr->data;
}
NedSystem *NedPage::getPreviousSystem(NedSystem *system) {
GList *lptr;
if ((lptr = g_list_find(m_systems, system)) == NULL) {
NedResource::Abort("NedPage::getPreviousSystem");
}
if ((lptr = g_list_previous(lptr)) == NULL) {
return NULL;
}
return (NedSystem *) lptr->data;
}
NedSystem *NedPage::getFirstSystem() {
GList *lptr;
if ((lptr = g_list_first(m_systems)) == NULL) {
NedResource::Abort("NedPage::getFirstSystem");
}
return (NedSystem *) lptr->data;
}
void NedPage::appendStaff(NedCommandList *command_list, int p_staff_nr /* = -1 */) {
GList *lptr;
for (lptr = g_list_first(m_systems); lptr; lptr = g_list_next(lptr)) {
((NedSystem *) lptr->data)->appendStaff(command_list, p_staff_nr);
}
}
void NedPage::removeLastStaff() {
GList *lptr;
for (lptr = g_list_first(m_systems); lptr; lptr = g_list_next(lptr)) {
((NedSystem *) lptr->data)->removeLastStaff();
}
}
void NedPage::deleteStaff(int staff_number) {
GList *lptr;
for (lptr = g_list_first(m_systems); lptr; lptr = g_list_next(lptr)) {
((NedSystem *) lptr->data)->deleteStaff(staff_number);
}
}
void NedPage::restoreStaff(int staff_number) {
GList *lptr;
for (lptr = g_list_first(m_systems); lptr; lptr = g_list_next(lptr)) {
((NedSystem *) lptr->data)->restoreStaff(staff_number);
}
}
void NedPage::shiftStaff(int staff_number, int position) {
GList *lptr;
for (lptr = g_list_first(m_systems); lptr; lptr = g_list_next(lptr)) {
((NedSystem *) lptr->data)->shiftStaff(staff_number, position);
}
}
|