home *** CD-ROM | disk | FTP | other *** search
/ Amiga Format 4 / af004.adf / KeyClick / KEYCLICK.DOC < prev    next >
Text File  |  1988-11-13  |  5KB  |  153 lines

  1.  
  2. *****************************************************************************
  3.  
  4.  
  5.  
  6.  
  7.                            Keyclick version 1.1
  8.  
  9.  
  10.      One thing I always missed about the Amiga was an audio click when the
  11.  
  12. keys were pressed.  While the Amiga keyboard has the best feel of any I've
  13.  
  14. typed on, it doesn't have a form of audio feedback, which aids in
  15.  
  16. touch-typing.  Thanks to the multitasking operating system however, the
  17.  
  18. addition of such a feature is relatively painless, both from a user's and a
  19.  
  20. programmer's standpoint.
  21.  
  22.      Upon running the program, a window will be presented which contains
  23.  
  24. two gadgets.  The slider is used for adjusting the volume of the click.  The
  25.  
  26. toggle switch can be "pressed" to turn the sound on or off.  After the
  27.  
  28. program is up and running, an audio click will be produced at each press of
  29.  
  30. a key on the keyboard or a mouse button.  You cannot run more than one key
  31.  
  32. clicker at a time; the second clicker that you run will indicate that a
  33.  
  34. key-clicker is already active in the system.  Simply close the window to
  35.  
  36. end the program.  That's about all you have to know as a user.
  37.  
  38.      For you programmers out there...  This program demonstrates custom
  39.  
  40. input handlers and effectively sharing the complicated audio device; two
  41.  
  42. concepts that can be put to great use.
  43.  
  44.      The center of activity revolves around a custom input handler, which
  45.  
  46. simply signals the waiting task when a key or mouse button event arrives in
  47.  
  48. the input stream.  Once the task is awakened, it sends a command to the
  49.  
  50. audio device to initiate the click and goes back to sleep. Therefore, this
  51.  
  52. program only uses a significant amount of processor time when a key or
  53.  
  54. mouse button is actually pressed.
  55.  
  56.      I had the program set its own priority to fourty (this can be changed
  57.  
  58. by assigning a different value to TASK_PRIORITY, defined at the beginning
  59.  
  60. of the program) for better response.  At lower task priority values, the
  61.  
  62. program tended to be sluggish on occasion (especially in a busy system).
  63.  
  64. The input handler priority (defined by HANDLER_PRIORITY) is set at
  65.  
  66. fifty-one.  This causes events from the input stream to be intercepted
  67.  
  68. before Intuition gets ahold of them.  This is desirable because Intuition
  69.  
  70. "swallows" some of the events.  That is, it removes some of them from the
  71.  
  72. input stream, preventing the custom input handler from notifying the
  73.  
  74. clicker task.
  75.  
  76.      At each stroke of a key, an audio channel is allocated, a sound
  77.  
  78. request is issued to the audio device, and the channel previously allocated
  79.  
  80. is freed.  All of this takes place within the click() routine.  After a
  81.  
  82. channel is allocated (via a call to get_audio_channel()), the io_Unit
  83.  
  84. parameter is checked to see if an allocation actually succeeded.  A zero in
  85.  
  86. this parameter indicates that no channel could be allocated.  If this is
  87.  
  88. the case, the click() routine returns immediately without attempting to ask
  89.  
  90. the audio device to make a click sound.  Any other value in io_Unit denotes
  91.  
  92. which channel has been allocated for use.  The IOAudio structure is
  93.  
  94. prepared for a CMD_WRITE to issue a sound request to the audio device, and
  95.  
  96. is executed with a call to BeginIO().  A WaitIO() call is immediately
  97.  
  98. issued after the BeginIO() so the program waits until completion of the
  99.  
  100. write request.  This is needed to delay freeing the channel until the click
  101.  
  102. sound is completed playing (after WaitIO() returns, a call to
  103.  
  104. free_audio_channel() frees the previously allocated audio channel).
  105.  
  106.      An alternate method of audio manipulation would be to allocate an
  107.  
  108. audio channel at the beginning of the program and set it to the highest
  109.  
  110. possible priority (127) to prevent it from being stolen by other tasks
  111.  
  112. requiring audio channels.  However, this method does not take full
  113.  
  114. advantage of the audio device's sophistication; it must be remembered that
  115.  
  116. in a multitasking environment you have to share resources.  Allocating and
  117.  
  118. "holding on" to an audio channel is very uncooperative (and selfish!).
  119.  
  120.      The in-line assembly language at the end of the C source code is an
  121.  
  122. input handler interface, which is required for the system to "communicate"
  123.  
  124. with the custom input handler.  In other words, it copies the appropriate
  125.  
  126. system registers (A0 and A1) to the stack to conform with the input handler
  127.  
  128. calling convention.  This is absolutely essential if the system is to work
  129.  
  130. correctly with the custom input handler.
  131.  
  132.      I would like to hear your comments on this program.  Feel free to
  133.  
  134. E-Mail me on GEnie (MMD) or Delphi (MOCKO).
  135.  
  136.  
  137.      Note- a simplified version of this program (V1.0) can be found in the
  138. November 1988 issue of Amazing Computing.  The program as it appears in
  139. print statically allocates an audio channel, therefore preventing any other
  140. task in the system from allocating (stealing) it.  This version of the
  141. program dynamically allocates an audio channel at a priority of -90 each
  142. time a key is pressed, and works well with other tasks using the audio
  143. device (at least with my experiences).  This version also adds a toggle
  144. switch to enable the user to prevent the program from clicking if so
  145. desired.  If any problems are encountered in using this program, I'd like
  146. to know so I can upload updated versions. Thank you. -Mike
  147.  
  148.  
  149.  
  150. *****************************************************************************
  151.