Newsgroups: rec.arts.int-fiction
Path: nntp.gmd.de!Dortmund.Germany.EU.net!Germany.EU.net!howland.reston.ans.net!spool.mu.edu!news.cs.indiana.edu!shulick@apricot.ucs.indiana.edu
From: "Sam Hulick" <shulick@apricot.ucs.indiana.edu>
Subject: GiftWare: An Inform CD-player
Message-ID: <1995Sep7.004054.1077@news.cs.indiana.edu>
Organization: Vallen Software
Date: Thu, 7 Sep 1995 00:40:44 -0500
Lines: 308


Hopefully that subject caught your attention.. :)

If you all object to me posting little neat snippits of code, tell me
and I will stop.  Otherwise, I will continue posting neat little things I
come up with.  This is a Discman (a small portable CD-player, just in
case this is unclear to Brits :) I never know if our dialect is
sometimes hard to grasp..anyway!).  This is a pretty in-depth CD
player.. does just about everything except that search forward/back.  It
opens, closes, plays, stops, pauses, and skips to previous/next tracks.
It's pretty damn smart, actually.  Anyway, this is free.  You can copy
it directly from here and use it in your game for all I care.  Just
enjoy it. :)  But if you use it, please e-mail me if you can.  I just
like to know who is using this code, so I know that stuff I post here is
liked and used by people.  Thanks.

Of course, if any of the expert Inform programmers have any tips for me,
those would be very welcome.

---cut here---
! An Inform Discman
! (portable CD-player)

Switches xv5;

Constant Story "A GOOD EAR";
Constant Headline "^A Byproduct of Boredom, by Sam Hulick^Freely \
                    distributable.^";
Release 2;
Serial "950906";

Global track = 1;
Global pos = 1;

Include "parser";
Include "verblib";

Attribute disc alias visited;
Property albumptr alias door_to; ! album pointer

! These are just very short examples, but you could lengthen them.
Array oboesong table [;
   "A single oboe fades in, holding a single wavering note.^"
   "A flute joins in, creating a beautiful counterpoint as the oboe \
    descends and the flute takes over the oboe's wavering manner.^"
   "The two instruments slow their tempos and finish with a soft ending.^"
];

Array pianosong table [;
   "The piano piece begins with a few simple--yet beautiful--chords.^"
   "A tempo builds, slowly, and the motif developed thus far begins to \
    embellish.^"
   "Suddenly the tempo quickens, and the notes sound off in a flurry, \
    up and down the scales like some musical roller coaster.^"
   "The piece ends suddenly with a conclusive chord.^"
];

! Some more tracks on another CD...
Array eggboy table [;
   "~Humpty Dumpty sat on a wall,~^"
   "~Humpty Dumpty had a great fall.~^"
   "~And all the king's horses and all the king's men,~^"
   "~Couldn't put Humpty together again.~^"
];

Array lillamb table [;
   "~Mary had a little lamb,~^"
   "~Little lamb,~^" "~Little lamb,~^"
   "~Mary had a little lamb, whose fleece was white as snow.~^"
];

Array farmer table [;
   "~Old MacDonald had a dungeon, E-I-E-I-O...~  Wait, something is \
    a bit wrong here.^"
   "~And in that dungeon he had a grue, E-I-E-I-O,~^"
   "~With a 'gnash gnash' here and a 'claw claw' there,~^"
   "~Here a 'gnash' there a 'claw' everywhere a 'claw claw',~^"
   "~Old MacDonald had a dungeon, E-I-E-I-O.~^"
];

!  2 songs on the CD, 3 on the other.
Array album --> 2 oboesong pianosong;
Array kidstuff --> 3 eggboy lillamb farmer;

Object yerroom "Your Room"
 with  description "A complete mess, with piles of papers in the \
                    corner, dirt spots on the walls, and various \
                    junkfood lying around in greasy boxes."
 has   light;

Nearby discman "Sony(TM) Discman"
 with  name "player" "discman" "sony" "cd-player",
       daemon [ c;
          c = child(self);
          if (pos > ((c.albumptr)-->track)-->0)
          {
             track++;
             pos = 1;
             if (track > (c.albumptr)-->0)
             {
                track = 1;
                StopDaemon(self);
                give self ~general;
                "The end of the CD is reached, and the Discman stops.";
             }
             "There is a pause between songs...";
          }
          print (string) ((c.albumptr)-->track)-->pos;
          pos++;
       ],
       description [;
          print "Brand spankin' new from the department store down\
                 town.  It has several buttons on it, labelled: \
                 PLAY, PAUSE, STOP, OPEN, PREV, NEXT.  The CD player \
                 is hooked up to your huge speakers.  There is also \
                 a LCD display on the Discman.  The player \
                 is currently ";
          if (self hasnt open) "closed.";
          else
          {
             whichCD();
             rtrue;
          }
       ],
       describe [;
          print "^Your new Sony(TM) Discman is here.  It's ";
          if (self hasnt open) "closed.";
          else
          {
             whichCD();
             rtrue;
          }
       ],
       before [;
        Take: "It's all wired to your speakers, leave it be.";
        Open: "Try pressing the button labelled OPEN.";
        Receive: if (inp1 hasnt disc) "Didn't mommy ever tell you to \
                                       not put things where they don't \
                                       belong?";
                 if (children(self) ~= 0) "Only one CD will fit at a time.";
       ],
       after [;
        Close: track = 1; pos = 1;
       ],
       add_to_scope openbutton playbutton stopbutton pausebutton
                    prevbutton nextbutton lcd
 has   static container openable;

Nearby pcil "pencil"
 with  name "pencil",
       description "It's just a number two pencil.";

Nearby trcd "Tranquil Sounds CD"
 with  name "cd" "sounds" "tranquil",
       article "your",
       description "A CD with just a couple pieces on it.",
       albumptr album
 has   disc;

Nearby ktunes "Kids' Tunes CD"
 with  name "cd" "kid" "kids" "tunes",
       description "It's a CD with a few kids' tunes on it.",
       albumptr kidstuff
 has   disc;

Class buttonclass
 with before [;
       Take: "The button is part of your Discman.";
       Examine: print "It's the "; PrintShortName(self); ".";
      ],
 has  static;

Object lcd "LCD display"
 with  name "lcd" "display",
       description [;
          if (discman has open) "The display is blank.";
          print "Track ", track; ".";
       ],
       before [;
        Take: "That's part of the CD-player.";
       ];

Object openbutton "OPEN button"
 class buttonclass 
 with  name "open" "button",
       before [;
        Push: if (discman has open) "The CD-player is already open.";

              give discman open;
              itobj = discman;  ! Because people are likely to do 
                           ! something like "push open button" then
                           ! see "The CD-player is now open", so
                           ! they type "put cd in it" or somesuch
              if (discman has general || pausebutton has general)
              {
                 give discman ~general;
                 give pausebutton ~general;
                 StopDaemon(discman);
                 track = 1; pos = 1;
                 print "You interrupted the playing by opening the \
                        Discman.  You watch ", (the) child(discman);
                       " spin and spin until it finally stops.";
              }
              print "The CD-player is now "; whichCD(); rtrue;
       ];

Object playbutton "PLAY button"
 class buttonclass
 with  name "play" "button",
       before [;
        Push: if (discman has open) "Try closing the Discman first.";
              if (children(discman) == 0) "The display on the Discman \
                                           reads ~Error~ for a moment.";
              if (discman has general) "It's already playing, though.";
              if (pausebutton has general) "Press PAUSE to unpause.";
              StartDaemon(discman);
              give discman general;
              "You press the PLAY button.";
       ];

Object stopbutton "STOP button"
 class buttonclass
 with  name "stop" "button",
       before [;
        Push: if (discman has open || discman hasnt general)
                 "Nothing happens.";
              StopDaemon(discman);
              give discman ~general;
              track = 1; pos = 1;
              "The CD stops playing.";
       ];

Object pausebutton "PAUSE button"
 class buttonclass
 with  name "pause" "button",
       before [;
        Push: if (discman hasnt open && self has general)
              {
                 give self ~general;
                 StartDaemon(discman);
                 give discman general;
                 "You unpause the CD-player.";
              }
              if (discman has open || discman hasnt general)
                 "Nothing happens.";
              give self general;
              StopDaemon(discman);
              give discman ~general;
              "You pause the CD-player.";
       ];

Object prevbutton "PREV button"
 class buttonclass
 with  name "prev" "button",
       before [;
        Push: if (discman has open) "Nothing happens.";
              if (track == 1)
              {
                 if (children(discman) ~= 0)
                 {
                    pos = 1;
                    "The track starts over.";
                 }
                 else "Nothing happens.";
              }
              track--;
              pos = 1;
              print "The track number on the display decreases to ",
                    track; ".";
       ];

Object nextbutton "NEXT button"
 class buttonclass
 with  name "next" "button",
       before [ c;
        Push: c = child(discman);
              if (discman has open) "Nothing happens.";
              if (children(discman) ~= 0 && track == (c.albumptr)-->0)
                 "Nothing happens.  You're at the last track.";
              track++;
              pos = 1;
              print "The track number on the display increases to ",
                    track; ".";
       ];

[ Initialise;
   location = yerroom;
   "^^^^^You really have nothing better to do today than to play with \
    your new CD-player.^^";
];

[ whichCD;
   if (children(discman) ~= 0)
   {
      print "open, revealing ", (the) child(discman), ".^";
      rtrue;
   }
   print "open, but empty.^";
];

Include "grammar";
end;

-- 
--- Sam Hulick ------------- shulick@indiana.edu ---------------------
Systems Consultant        | Homepage:
Indiana College Placement |    http://copper.ucs.indiana.edu/~shulick/
  and Assessment Center   | PGP public key available on request
