SCORE in Linux/X-Windows using Dosemu

From CCARH Wiki
Revision as of 06:10, 26 November 2011 by Craig (talk | contribs) (→‎Dosemu)
Jump to navigation Jump to search

Versions of SCORE compiled for MS-DOS can be run in X-windows (typically on unix or linux computers, but possibly OS X as well) with DOS emulators.

Dosemu

Dosemu is one of the DOS/Windows emulators in which SCORE can run. First you will have to install dosemu for your particular operating system and configuration. In Gentoo this is easy to do (as root):

  emerge dosemu

On other linux systems, you can try "yum install dosemu", "rpm -Uvh dosemu" or "apt-get install dosemu", or download and compile the source code manually from the dosemu website. Freedos was installed at the same time as dosemu when "emerge dosemu" was run, but you may also need to install that before running dosemu.

Once dosemu is installed, type

  dosemu

This will intialize various files in ~/.dosemu which are needed to run dosemu. Dosemu can be run from a non-X terminal or from X-windows in this setup process. Hopefully you will not get any errors... Here is a screenshot of the dosemu terminal which should appear with a C:\> prompt:

Dosemu-startup.png

To exit from dosemu, type:

  exitemu

You should now have a directory called .dosemu in your home directory. Within this directory is a subdirectory called "drive_c". This directory contains files which dosemu calls the C drive when you are running dosemu. Install the SCORE program in this subdirectory. If you have SCORE installed on the C: drive in DOS/Windows, then you should not need to change the SCORE preference file (SCOR4\LIB\PREF-4.SCR).

Running SCORE in Dosemu

To run SCORE in dosemu with linux, you must use X-windows. Most linux systems are running X-windows by default, so this should not be a problem; otherwise, you would type "startx" at the text-only console. In an X-window terminal, you should now type:

   dosemu

Alternatively, if you have an X-server running, but are using a non-X terminal, type:

   dosemu -X

Then you can run SCORE as usual in DOS:

   cd scor4
   scor4.exe

or

   scor4\scor4.exe

or

   c:\scor4\scor4.exe

After the SCORE splash-screen you should see something like this:

Dosemu-scorestart.png

Now SCORE can be used as usual. Sometimes the mouse cursor does not appear when starting dosemu. Restarting it solves the problem. Here is some example music (PMX 1, PMX2) being edited in SCORE within dosemu:

Dosemu-gounod.png

SCORE in batch mode using dosemu

SCORE can be used in an automatic manner with dosemu. In this case the -I option of dosemu can be used to feed keystrokes to SCORE as if you were typing them.

As an example, suppose that you have a file called mytest.pmx which contains ASCII data for a page of music:

8.  1.0    .000      .00      .00      .00
3.  1.0   1.500
17.  1.0   9.500      .00     1.00
1.  1.0  14.300     1.00    10.00      .00     1.0000
1.  1.0  29.275     2.00    10.00      .00     1.0000
1.  1.0  44.250     3.00    10.00      .00     1.0000
1.  1.0  59.225     4.00    10.00      .00     1.0000
14.  1.0  74.200     1.00
1.  1.0  77.700     5.00    10.00      .00     1.0000
1.  1.0  92.675     6.00    10.00      .00     1.0000
1.  1.0 107.650     7.00    20.00      .00     1.0000
1.  1.0 122.625     8.00    20.00      .00     1.0000
14.  1.0 137.600     1.00
1.  1.0 141.100     9.00    20.00      .00     1.0000
1.  1.0 156.075    10.00    20.00      .00     1.0000
1.  1.0 171.050    11.00    20.00      .00     1.0000
1.  1.0 186.025    12.00    20.00      .00     1.0000
14.  1.0 200.000     1.00     2.00

To create an Encapsulated-PostScript file of this music, you can type this command in the unix terminal:

  LANG=utf-8 dosemu -I 'keystroke "\P1;c:\\scor4\\scor4.exe\r\rre mytest.pmx\rprint\r1 mytest.eps\ry\rg\rexit\ry\rexitemu\r"'

The "LANG=utf-8" may not be necessary, but is used in this case to prevent an error/warning about the character encoding being undefined. The -I option is used to configure dosemu. In this case the -I option is used to pass keystrokes to dosemu. The special characters used in the keystroke string:

  \r = carriage return
  \\ = backspace
  \P1; = feed 100 characters per second to dosemu.  
  \P20; would feed 5 characters per second (useful for debugging)

Other useful control characters:

  \F10; = press the F10 key.
  \p15; = wait 150 milliseconds before typing next key.
  \^[   = escape character

The above keystroke string contains the text script necessary to print mytest.pmx into the file mytest.eps:

   c:\score\scor4.exe       # start SCORE
   <enter>                  # skip the splash screen
   re mytest.pmx            # read the macro text
   print                    # go to the print menu
   1 mytest.eps             # save output to mytest.eps
   y                        # overwrite mytest.eps (if it exists)
   g                        # start printing to file
   exit                     # exit from SCORE
   y                        # exit without saving any changes
   exitemu                  # exit dosemu

You can adjust the script as necessary, adding any special characters such as \r for the enter key.

The final result is a file called mytest.eps. This Encapsulated PostScript file can be converted to a pdf file with the command-line program (if it is installed):

  cat mytest.eps | ps2pdf - - > mytest.pdf

Also, here is an example of converting the EPS file into a PNG image:

   cat mytest.eps | pstopnm -dpi=300 | convert - -trim -resize '40%' mytest.png

which results in this image:

Dosemu-mytest.png

To generate an SVG graphic from EPS:

  inkscape `pwd`/mytest.eps -l mytest.svg --vacuum-defs --port-text-to-path

which generates this image:

Dosemu-mytest.svg

The options to inkscape used for this conversion from EPS into SVG:

  • `pwd`/mytest.eps → Inkscape (v0.48) cannot read EPS files unless they are given with absolute path names. Pwd is the unix command which displays the present working directory.
  • -l → Set the output type to plain SVG (as opposed to Inkscape SVG).
  • --vacuum-defs → remove unnecessary code from SVG data.
  • --port-text-to-path → convert text characters into outlines. This is needed for portable display of text since necessary fonts may not be availble on client browsers.

The above image is automatically converted into a PNG file in mediawiki (click twice on the image to see the raw SVG image). Here is a raw display of the same SVG graphic directly on this webpage (which will not display on Internet Explorer browsers) with a size carefully chosen to minimize anti-aliasing:

<htmlet>svgexample</htmlet>


Script for converting MUS or PMX data into EPS files

Here is a short PERL script which converts PMX files or MUS files into EPS files, with multiple PMX/MUS files given as an argument:

#!/usr/bin/perl
use strict;

my $file;
foreach $file (@ARGV) {
   my $basename = $file;
   $basename =~ s/\.[^.]*//;
   my $extension = $file;
   $extension =~ s/^$basename\.//;
   if (-r $file) {
      print "Processing file $file\n";
      createEPS($basename, $extension);
   }
}

sub createEPS {
   my ($base, $ext) = @_;
   my $keystrokes = "\\P4;";        # set keypress speed
   # run the SCORE program.  The extra \r is to skip the splash screen:
   $keystrokes .= "c:\\\\scor4\\\\scor4.exe\\r\\r";
   $keystrokes .= "\\p10;";          # pause 
   if ($ext =~ /mus/i) {
      $keystrokes .= "g";            # Get binary data
   } else {
      $keystrokes .= "re";           # REad ASCII data
   }
   $keystrokes .= " $base.$ext\\r";  # the file to read
   $keystrokes .= "\\p50;";          # pause 
   $keystrokes .= "print\\r";        # go to print menu
   $keystrokes .= "\\p50;";          # pause (necessary pause)
   $keystrokes .= "1 $base.eps\\r";  # set the print output file
   $keystrokes .= "y\\r";            # answer yes to possible overwrite question
   $keystrokes .= "\\F6;\\r";        # print the file
   $keystrokes .= "\\p200;";         # pause 
   $keystrokes .= "exit\\r";         # exit from SCORE
   $keystrokes .= "y\\r";            # don't save file
   $keystrokes .= "exitemu\\r";      # exit from dosemu
   if (-r "$base.$ext") {
      `LANG=X dosemu -X -I 'keystroke "$keystrokes"'`;
   }
}

Faster script for converting MUS into EPS files

The previous script prints directly in SCOR4 which allows the flexibility of automating any commands. However, pauses in the keystroke typing rate is necessary to accommodate switching between the graphics and text screens. The following script uses the SCORLAS4 program. This special-purpose program only prints binary SCORE data files (which end with .mus).

An advantage of printing by this method is that it can be done faster, since the keystrokes do not need to be buffered in any way. A disadvantage is that it only prints binary SCORE data files. So ASCII numeric data with possible macro instructions cannot be printed with this method.

#!/usr/bin/perl
use strict;

my $file;
foreach $file (@ARGV) {
   my $basename = $file;
   $basename =~ s/\.[^.]*//;
   my $extension = $file;
   $extension =~ s/^$basename\.//;
   if ((-r $file) && ($extension =~ /mus/i)) {
      print "Processing file $file\n";
      createEPS($basename, $extension);
   }
}

sub createEPS {
   my ($base, $ext) = @_;
   my $keystrokes = "\\P1;";         # set keypress speed
   # run the SCORLAS4 program:
   $keystrokes .= "c:\\\\scor4\\\\scorlas4.exe\\r";
   $keystrokes .= "1\\r";            # 1 = print file
   $keystrokes .= "\\r";             # print single page
   $keystrokes .= "$base.$ext 1\\r"; # input filename and count
   $keystrokes .= "\\r";             # continue
   $keystrokes .= "1 $base.eps\\r";  # set the print output file
   $keystrokes .= "y\\r";            # answer yes to possible overwrite question
   $keystrokes .= "\\F6;";           # print the file
   $keystrokes .= "n\\r";            # don't print another page
   $keystrokes .= "exitemu\\r";      # exit from dosemu
   if (-r "$base.$ext") {
      `LANG=X dosemu -X -I 'keystroke "$keystrokes"'`;
   }
}