Difference between revisions of "SCORE in Linux/X-Windows using Dosemu"

From CCARH Wiki
Jump to navigation Jump to search
Line 110: Line 110:
  
 
[[File:dosemu-mytest.svg|500px||center]]
 
[[File:dosemu-mytest.svg|500px||center]]
 +
 +
 +
=== 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:
 
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:
Line 115: Line 118:
 
<pre>
 
<pre>
 
#!/usr/bin/perl
 
#!/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"'`;
 +
  }
 +
}
 
</pre>
 
</pre>

Revision as of 12:53, 25 November 2011

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 a DOS emulator 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 dosemu", "rpm -Uvh dosemu" or "apt-get 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:

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.

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.

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:

  convert mytest.eps mytest.svg

which generates this image:

Dosemu-mytest.svg


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"'`;
   }
}