Description: Add "$Q" key in header for page numbers that don't reset
  abcm2ps supports a "$P" key in header or footer lines that will output
  the current page number and can be reset using "%%newpage". In my
  books of SCD ball sets, I like to include both the page number inside
  the tune and the page number inside the book on every page, so the
  "$Q" adds another page number that is not changeable by the user.
Author: Anselm Lingnau <lingnau@debian.org>
Last-Update: 2009-12-21

Index: abcm2ps/abc2ps.c
===================================================================
--- abcm2ps.orig/abc2ps.c	2012-06-22 14:26:14.000000000 +0200
+++ abcm2ps/abc2ps.c	2012-06-22 14:27:25.000000000 +0200
@@ -42,6 +42,7 @@
 
 int tunenum;			/* number of current tune */
 int pagenum = 1;		/* current page in output file */
+int pagenum_nr = 1;		/* current page (non-resettable) */
 
 				/* switches modified by command line flags: */
 int quiet;			/* quiet mode */
Index: abcm2ps/abc2ps.h
===================================================================
--- abcm2ps.orig/abc2ps.h	2012-06-22 14:26:14.000000000 +0200
+++ abcm2ps/abc2ps.h	2012-06-22 14:27:25.000000000 +0200
@@ -293,6 +293,7 @@
 extern int outft;		/* last font in the output file */
 extern int tunenum;		/* number of current tune */
 extern int pagenum;		/* current page number */
+extern int pagenum_nr;		/* current page number (non-resettable) */
 extern int nbar;		/* current measure number */
 extern int nbar_rep;		/* last repeat bar number */
 extern int in_page;
Index: abcm2ps/buffer.c
===================================================================
--- abcm2ps.orig/buffer.c	2012-06-22 14:26:14.000000000 +0200
+++ abcm2ps/buffer.c	2012-06-22 14:27:25.000000000 +0200
@@ -299,6 +299,18 @@
 			}
 			d += sprintf(d, "%d", pagenum);
 			break;
+		case 'Q':		/* non-resetting page number */
+			if (p[1] == '0') {
+				p++;
+				if (pagenum_nr & 1)
+					break;
+			} else if (p[1] == '1') {
+				p++;
+				if ((pagenum_nr & 1) == 0)
+					break;
+			}
+			d += sprintf(d, "%d", pagenum_nr);
+			break;
 		case 'T':		/* tune title */
 			q = &info['T' - 'A']->as.text[2];
 			tex_str(q);
@@ -518,6 +530,7 @@
 	if (cfmt.footer != 0)
 		maxy -= headfooter(0, pwidth, pheight);
 	pagenum++;
+	pagenum_nr++;
 	outft = -1;
 }
 
