#include "post_mus.h"
#include <stdio.h>

barprint (bar) {
    struct bars *barp = barv + bar;
    int	    i, p;
    fprintf (stderr, "Bar %2d ", bar );
    if ( barp->b_end_type ) fprintf( stderr, "(t %d); ", barp->b_end_type );
    fprintf( stderr, "n [%2d,%2d-1], x0 %3d, dx %3d, y [%2d,%2d]; ",
	    barp -> b_first_note, barp -> b_last_note,
	    barp -> b_x_wrt_staff, barp -> b_width,
	    barp -> b_miny, barp -> b_maxy);
    fprintf (stderr, " ns%d", barp -> b_note_start);
    fprintf (stderr, " sq%d", barp -> b_length);
    for (i = 0; i < n_staffs; i++) {
	if (barp -> b_clef[i])
	    fprintf (stderr, " \\c %d %d;", i, barp -> b_clef[i]);
	if (barp -> b_tover[i])
	    fprintf (stderr, " o\"%s\"", barp -> b_tover[i]);
	if (barp -> b_tunder[i])
	    fprintf (stderr, " u\"%s\"", barp -> b_tunder[i]);
    }
    if (barp -> b_key)
	fprintf (stderr, " \\k %d;", barp -> b_key);
    if (barp -> b_n_tsig)
	fprintf (stderr, " \\t %d %d;", barp -> b_n_tsig, barp -> b_d_tsig);
    if (barp -> b_bps)
	fprintf (stderr, " \\n %d;", barp -> b_bps);
    fprintf (stderr, "\n");
}

noteprint (beat) {
    struct notes   *notep = notev + beat;
    fprintf (stderr, "Note %d p (%c,%c%c)%d l %2d(%2d)",
	    beat,
	    notep -> n_pitch,
	    scale[notep -> n_pitch - 'a' + key_now - 8
		+ staffv[0][notep -> n_staff].s_key_offset][0],
	    scale[notep -> n_pitch - 'a' + key_now - 8][1],
	    notep -> n_octv - '0',
	    notep -> n_length, notep -> n_mus_wrt_bar);
    fprintf (stderr, " [x=%d, y=%d(%d:%d)]",
	    notep -> n_x_wrt_bar, notep -> n_y_wrt_staff, notep -> n_miny, notep -> n_maxy);
    if (notep -> n_tover)
	fprintf (stderr, " '%s'(%d)", notep -> n_tover,
		notep -> n_yover);
    if (notep -> n_tunder)
	fprintf (stderr, " \"%s\"(%d)", notep -> n_tunder,
		notep -> n_yunder);
    if (notep -> n_tnote)
	fprintf (stderr, " @%s@", notep -> n_tnote);
    if (notep -> n_tnote)
	fprintf (stderr, " v\"%s\"", notep -> n_tnote);
    if (notep -> stickup > 0)
	fprintf (stderr, " up %d,%d", notep -> n_x_stick,
		notep -> n_y_end_stick);
    else
	if (notep -> stickup < 0)
	    fprintf (stderr, " dn %d,%d", notep -> n_x_stick, notep -> n_y_end_stick);
    if (notep -> n_accid != ' ')
	fprintf (stderr, "[%c]", notep -> n_accid);
    if (notep -> n_dots > 0)
	fprintf (stderr, " dots %d", notep -> n_dots);
    if (notep -> n_hooks > 0)
	fprintf (stderr, " hooks %d", notep -> n_hooks);
    if (notep -> n_beam > 0)
	fprintf (stderr, " \"%c\"", BEAMSTART);
    if (notep -> n_tie_start > 0)
	fprintf (stderr, "\"%c\"", TIESTART);
    if (notep -> n_beam < 0)
	fprintf (stderr, " \"%c\"", BEAMEND);
    if (notep -> n_tie_end > 0)
	fprintf (stderr, " \"%c\"", TIEEND);
    if (notep -> n_tie_height)
	fprintf (stderr, "[%d]", notep -> n_tie_height);
    if (notep -> n_group)
	fprintf (stderr, " gp %d", notep -> n_group);
    fprintf (stderr, " width %d\n", notep -> n_width);
}

stavepr (stave) {
    fprintf (stderr,
	    "stave %d, bars [%d,%d], y %d, y range [%d,%d], s_x_right %d\n",
	    stave,
	    stavev[stave].s_first_bar,
	    stavev[stave].s_last_bar - 1,
	    stavev[stave].s_y_wrt_page,
	    stavev[stave].sv_miny, stavev[stave].sv_maxy,
	    stavev[stave].s_x_right);
}

staffpr (stave, staff) {
    fprintf (stderr,
	    "staff %d, y %d, y range [%d,%d]\n",
	    staff,
	    stavev[stave].s_y_wrt_page + staffv[stave][staff].s_y_wrt_stave,
	    staffv[stave][staff].sf_miny, staffv[stave][staff].sf_maxy);
}

int     ts[NNOTES],
        te[NNOTES];
print_ties (n) {
    int     lbeat;
    struct notes   *beatp;
    if (set_monitor < 2)
	return;
    for (lbeat = 0, beatp = notev; lbeat <= n; lbeat++, beatp++) {
	if (beatp -> n_tie_start != ts[lbeat]) {
	    fprintf (stderr, "Tiestart %d beat %d val %d was %d\n",
		    n,
		    lbeat,
		    beatp -> n_tie_start, ts[lbeat]);
	    ts[lbeat] = beatp -> n_tie_start;
	}
	if (beatp -> n_tie_end != te[lbeat]) {
	    fprintf (stderr, "Tieend %d beat %d val %d was %d\n",
		    n,
		    lbeat,
		    beatp -> n_tie_end, te[lbeat]);
	    te[lbeat] = beatp -> n_tie_end;
	}
    }
}
