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

From CCARH Wiki
Jump to navigation Jump to search
Line 9: Line 9:
 
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):
 
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
 
   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 [http://sourceforge.net/projects/dosemu dosemu website].  [http://www.freedos.org/ 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.
+
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 [http://sourceforge.net/projects/dosemu dosemu website].  [http://www.freedos.org/ 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, particularly if you are installing manually.
  
 
Once dosemu is installed, type
 
Once dosemu is installed, type

Revision as of 23:06, 27 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. This page describes how to run SCORE 4 with dosemu using freedos.

Getting started

Installing and setting up 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, particularly if you are installing manually.

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 if you are located in the C:\ directory:

   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

Useful dosemu commands

exitemu

To exit from dosemu, as mentioned above, type:

  exitemu

unix

A useful command within dosemu is unix.com which has the the ability to run unix commands within dosemu. Prefix any unix command with the word "unix" to run the arguments on the operating system which is running dosemu as if they were a command:

  unix uname -a
     Linux hostname 2.6.32-gentoo-r7 #1 SMP Mon Jul 12 05:51:36 PDT 2010 i686 Intel(R) 
     Core(TM)2 Duo CPU E6750 @ 2.66GHz GenuineIntel GNU/Linux

Useful dosemu options

-t option

Dosemu will start up in X-windows mode by default if an X-windows server can be found. Use the -t option to force it to open in terminal mode.


-dumb option

To run a single dos The -dumb option will suppress startup text until the provided command has been started, and then exit after the command has finished. For example, to display a list of files in the default startup directory (the C:\ drive), type this command in a unix terminal:

   dosemu -dumb dir

Dosemu configuration

The dosemu configuration file is found in /etc/dosemu/dosemu.conf. Useful settings are given below:

Keyboard layout

By default the keyboard layout variable is set to "auto". This may cause problems if you are running dosemu without X-windows. In this case, dosemu asks you to press Template:Keypress:enter so that it can identify the type of keyboard. This feature is not useful for batch processing in dosemu. This need to press Template:Keypress:enter can be removed by setting the $_layout variable in the configuration file, such as a US keyboard layout:

   $_layout = "us";

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 (run from the ~/.dosemu/drive_c directory (or any subdirectory within) and assuming mytext.pmx is in the same subdirectory):

  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.

For more information on the non-interactive modes of dosemu see: http://www.dosemu.org/docs/HOWTO/x304.html#AEN309

Converting SCORE EPS into PDF, PNG or SVG files

EPS to PDF

The Encapsulated PostScript files generated by SCORE can be converted to a pdf file with the command-line program ps2pdf (if it is installed):

  ps2pdf mytest.eps

which will automatically create mytest.pdf. Or used in a pipeline:

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

EPS to PNG

Here is an example of converting the EPS file into a PNG image using ImageMagick's convert program:

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

which results in this image:

Dosemu-mytest.png

EPS to SVG

To generate an SVG graphic from EPS, the EPS file should be processed in two steps. The first step is optional if the EPS file does not contain text:

  gs -q -dNOPAUSE -dBATCH -dSAVER -dNOCACHE \
     -dOutputDevice=epswrite -sOutputFile=embeddedfonts.eps input.eps

The above GhostScript script will embed fonts into the EPS data file which is written to embeddedfonts.eps. After fonts have been inserted into the EPS file (or there were no fonts to begin with), use this command to create the SVG file:

  inkscape `pwd`/embeddedfonts.eps -T -l output.svg --vacuum-defs 

which generates this image:

Dosemu-mytest.svg

The above image is actually a PNG file, since WikiMedia automatically converts SVG files (vector graphics) into PNG files (bitmap graphics) so that the image can be viewed on any browser. Click on the above image twice to view the raw SVG image in the browser.

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

  • `pwd`/file.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. This is optional.
  • -T → convert text characters into outlines. This is needed for portable display of text since necessary fonts may not be available on client browsers. The gs command above must be used first to embed the fonts in the EPS file for this option to work.

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 older Internet Explorer versions and has scaling problems in recent IE versions) with a size carefully chosen to minimize anti-aliasing:

<htmlet>svgexample</htmlet>

If this page is printed to a 600 dpi printer, then the above raw SVG image will be printed at 600 dpi (even though it is displayed on the screen around 100 dpi).

Conversion scripts

To run any of the following PERL scripts, save the contents of the program to a file. And then on the command-line type the command:

  chmod 0755 program

Where program is the name of the file with the PERL script, and 0755 set the permissions so that anyone can run the program. To run the program, you may have to add "./" (without the quotes) before the command name, such as:

   ./score2eps *.pmx *.mus


score2eps: 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. This automatic method of converting SCORE data into EPS images is not so great because time delays proportional to the amount of data on the page are required (or always use a long delay before starting to print so that music can be drawn on the screen).

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

Here is example PMX data which was converted to EPS with the above script, and then converted to SVG using these two steps:

   gs -q -dNOPAUSE -dBATCH -dSAFER -dNOCACHE \
      -sDEVICE=epswrite -sOutputFile=withfonts.eps input.eps

The above gs (GhostScript) command embeds the fonts used in the input.eps file into the file withfonts.eps. The withfonts.eps file can be converted to the final output.svg image with this command:

   inkscape `pwd`/withfonts.eps -T -l output.svg

Here is the final SVG image (rendered automatically by mediawiki into a PNG file, so click twice on the image below to see the raw SVG file displayed in the browser):

Gou-p1.svg

Compare the above rendering as a PNG image to a direct display of the SVG image below (not viewable on older versions of Internet Explorer, and does not scale well on recent IE versions). The difference will be more noticeable if this page is printed.

<htmlet>gounodsvg</htmlet>

mus2eps: 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 because no graphics need to be displayed, and the video mode remains text. 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"'`;
   }
}

pmx2mus: Converting PMX into MUS files

pmx2pmx: Converting PMX into PMX files