Ay_Emul v2.9 beta 8

Ay_Emul v2.7 official fixes and Ay_Emul v2.8 and v2.9 progress
--------------------------------------------------------------

v2.7 Fix 1 + BASS initial support:

20 April 2003

- SaveAs... and Search for tunes in files for ASC0 files had lost last byte,
  fixed now

15 June 2003

- Short titles can be wrongly displayed after some playlist operations on main
  window (fixed)
- Channels amplification was not selected during autoselecting chip type from
  playlist entry (fixed)
- Visualisation stops if Next or Prev buttons are pressed during pause (fixed)
- Added BASS.DLL v1.8 file types support (MP3, MOD and so on)
- Fixed some time diplaying problems in reverse count mode

v2.7 Fix 2:

28 June 2003

- BASS.DLL v1.8a supported (FFT4096)
- Playlist popup menu appearance error fixed ("system menu" key error)

1 July 2003

- Preamp moved to AY Emulation tabsheet of Mixer window
- Volume control controls global volume of system mixer now

27 July 2003

- VTX's Year member zero value is interpreted as 'no year information'
- VTX header editor allows to enter empty Year value

v2.7 Fix 3:

19 August 2003

- PT3 player: note correction after adding ornament is made as in Pro Tracker
  v3.6x (less than minimum come to minimum and greater than maximim come to
  maximum)

v2.7 Fix 4:

21 August 2003

- Added registering BASS file types in system (associating with Ay_Emul)
- Added volume control response if volume changed by other mixer programs

27 August 2003

- BASS's sound device and BASS.DLL both are freed after reaching end of playlist
  now

28 August 2003

- Added initial support of AudioCDs

v2.8 Beta:

22 October 2003

- Added filter for quality downsampling. It improves soundchip emulation of some
  AY musician's tricks like "Envelope + Ultrasound", etc, and also improves
  beeper sound emulation (Savage.ay, etc)
- Settings are saved in registry in new format
- All settings are saved automatically now, corresponding button is removed
- Default language is English now
- Tools and Mixer windows both are redesigned
- Fixed error of 2.7+ version only: some AY-files was not played correctly due
  wrong initialization of emulated Z80 RAM (see Mickey.ay from Ironfist's
  collection)

23 October 2003

- Skins directory is saved now
- BASS and system volume parameters are saved now too
- AY and YM indicators on main window show right information not only during
  playing now

25 October 2003

- Added 'Uninstall' button to complete removing Ay_Emul data from your system

v2.8 Beta 2:

26 October 2003

- Fixed some errors of previous release

1 November 2003

- BASS v2.0 is supported
- Time seeking after end of AY file started playing of next playlist item even
  if Loop button is on; fixed now
- Fixed some problems with redrawing time in "song length" time displaying mode
- Colors of playing item highlighting slightly changed
- Fixed error of redisplaying shorter titles on main window after editing
  playlist entry

2 November 2003

- Added two new icons by Exocet/JFF^Spaceballs^Industry
- Fixed error of time positioning in FXM (ZXAYAMAD) files
- Added PlayListLoop button to loop playing of all playlist items
- Added PlayListPlayingOrder button to select one of playlist items play modes:
  forward, backward, random orders and play only one item mode
- Playing order can be set by this new button only now

v2.8 Beta 3:

3 November 2003

- WaveOut code slightly changed to avoide deadlocks with bad soundcards drivers

4 November 2003

- Tracker modules loader and time length calculator is improved to avoid
  deadlocks with badly ripped or wrongly detected modules
- SQT detector is improved a little

6 November 2003

- Found STC file with not same patterns lengths (see SAT2.STC), so, STC file
  duration calculation is a little changed now

8 November 2003

- All hotkeys in main window can now works without Alt and Ctrl (1, 2, T, E, P,
  G)

14 November 2003

- Fixed error in filter (thanks to Key-Jee for bug-report and test module)

15 November 2003

- Fixed error of infinite looping playlist if all items has errors (i.e. not
  playable)
- Delete/clear playing item from playlist during vertical scrolling titles on
  main window works rightly now

18 November 2003

- Added several ways of sorting playlist items

19 November 2003

- AY emulation parameters setting is synchronized with playing thread now (for
  more safety AY emulation adjusting during playing)

v2.8 Beta 4:

22 November 2003

- After moving playlist item playing order was not recalculated (fixed)
- BASS.DLL fix: right playing tracker modules with 'jump' command at the middle
  of last position (thanks to Ian Luck for immediate fixing; see music from
  Aladdin game converted from AMF to S3M)

24 November 2003

- Main window's hotkeys work in playlist now

28 November 2003

- Added new icon from Roman Morozov
- Esc can be used to close playlist now
- Fixed errors of previous release

2 January 2004

- Fixed portamento to first note of pattern in PT2 player (see
  DejaVU#06_14-Epilogue.pt2 by Nik-O)

24 January 2004

- Fix: opening files and playlists with precalculated time length from command
  line updates total time label in playlist now

17 February 2004

- Fix: opening files and playlists with precalculated time length after
  drug'n'droping updates total time label in playlist now

v2.8 Beta 5:

20 February 2004

- Spaces between substrings in Track Descriptor was removed (specially for
  Key-Jee)

8 March 2004

- Fixed EPSG2PSG converter if both PSG's has same name (temp file was not
  renamed)

12 August 2004

- Fixed stupid bug: error message and no running if no CD-drives in system
  (thanks to Slava Kalinin for bug-report), soon will be fixed in v3.0 too
- Play positioning is slightly fixed: no unexpected delays when pressing left
  and right arrows keys to rewind
- Added additional syncronization into WaveOut thread
- Visualisation is improved: envelope sound visualized better (different levels
  for different envelope types including "soft" envelopes
- Two extra chars can be added to song name during finding or loading STC-files.
  They are got from extra ModuleSize field of STC-header (for example, Agent-X
  used this ability)

v2.8 Beta 6:

18 September 2004

- PT3 module finder is improved to more stable detect of PT3 modules with modern
  structure (Pro Tracker 3.6x and VT II 1.0)

27 October 2004

- Non-Delphi ScrollBar in playlist window (no need to mask corresponding Delphi
  error)
- You can drug'n'drop folders now (to main and playlist windows)

v2.8 Beta 7:

7 November 2004

- Added sorting by file type into playlist

14 November 2004

- Balance was set to middle by volume control (fixed)

29 December 2004

- Visualisation thread was moved to main one, so, there are no some problems
  in WinXP now. If you was using v3.0 as more stable version, you can back to
  v2.8 now

31 December 2004

- Masked some problems with buggy WM_ENDSESSION handler in Delphi 7 VCL
- Added WindowsXP controls
- Fixed bug with saving states of "Get from list" checkers in Mixer window


1 January 2005

- Added saving playlist visibility before closing application
- The latest BASS.DLL v2.1 is supported
- Removed timelength recalculation when interrupt frequency is changed temporary

v2.8 Beta 8:

6 January 2005

- Fixed FLS-player: ornament must be disabled during selecting envelope

7 January 2005

- Fixed FLS- and FTC-players: checking note range was [0..85] (correct is
  [0..95])

14 January 2005

- Fixed errors of working with system mixer (crytical error, Ay_Emul 2.8 beta 7
  did not work on some computers at all)
- Old bug is fixed: error in PT2-files timelength calculation (not used Tempo
  setting in channel C, see "*ELEPHANT*  BY JAAN_PHT 160896" module as example)
- Added 'Find playlist items' dialog into playlist window (call by F7)

15 January 2005

- Ay_Emul 2.8 beta 7 does not work rightly with command line parameter "/vhide"
  at first startup. Fixed.

v2.8 Beta 9:

6 February 2005

- PT2 note table removed (because of same as PT3 note table #1)

12 February 2005

- PT2 note range checking changed to PT3 standard (original PT2-player has no
  range checking anyway)

10 May 2005

- WMA support added (via BASSWMA.DLL v2.1 by Ian Luck). WMA playback requires
  the Windows Media Format modules to be installed. They come installed with
  Windows Media player, so will already be on most users' systems, but they can
  also be installed separately (WMFDIST.EXE is available at the un4seen.com)

12 May 2005

- WAV converter now uses PreAmp and Quality settings from mixer (thanks to
  T.A.D. 2005 for bug-report)
- Added Ay_Emul v3.0 behaviour during moving "main" and "about" windows

13 May 2005

- Shows number of items in playlist window (specially for Alone Coder)

15 May 2005

- Integrity checking is added into modules finder (specially for T.A.D. 2005)
- Fixed error in PT2.4PF finder (thanks to T.A.D. 2005 for WILD_SEY.tzx test
  file)
- Playlist loop button is used now in "play only current item" mode (specially
  for T.A.D. 2005)
- Fixed error: after drug'n'dropping files to active window, keyboard shortcuts
  not work until mouse click (thanks to T.A.D. 2005 for bug-report)
- Fixed error: waveout buffer access violation (thanks to T.A.D. 2005 for
  bug-report)

16 May 2005

- Added playlist color setup (specially for MadCat!)
- Corrected time length calculator for GTR v1.1 modules (see HYMN.gtr)

v2.8 Beta 10:

18 May 2005

- Fixed error: one position length PT3-files was not detected by module finder
  (thanks to Newart)

21 May 2005

- Fixed error of Beta 9: FLS structure analizer error
- Added 'Select CD(s)' dialog to load whole CD content. Function checks all CD's
  tracks and loads only audiotracks (even if its not available in standard file
  browser). Hold 'Ctrl' during clicking 'Open' or 'Add items' buttons (or use
  'Ctrl+L' and 'Ctrl+Insert')

13 June 2005

- YM2 samples are supported now (thanks to Arnaud Carre for sources and to
  Key-Jee for comments)

16 June 2005

- Command line analizer can expand filenames relatively to current directory
  path (specially for SMT), so, you don't need to specify full path now
- Added new command line key "/add" to add files from command line to the end of
  current playlist (specially for TAD and SMT). The key works only if Ay_Emul
  was started before

v2.8 Beta 11:

20 August 2005

- Fixed error in GTR loader and saver (thanks to TAD for CC#4 intro GTR-music)

10 September 2005

- Added PSM (compiled Pro Sound Maker modules) support

11 September 2005

- Show playing item number in playlist down right corner (specially for TAD)
- Integrity checker in modules finder is improved
- SQT finder is improved
- Tray icon reaction changed to single left click

15 September 2005

- Added TRD catalog analizer (works after loading TRD in playlist, specially for
  SMT)

16 September 2005

- Added SCL and Hobeta headers analizers (work after loading it in playlist,
  thanks to SMT for idea)
- Added deafult filename in "Save as.." dialog (specially for TAD), autoselects
  among original file name (from disk image file), song title or source file
  name

17 September 2005

- After loading TRD, SCL or Hobeta into playlist, AY_Emul extracts author and
  title strings from corresponding playing routine of ASC and STP modules
- 'Save as...' from playlist inserts title string to STP and ASC modules (if it
  was extracted from playing routine during loading into playlist)

18 September 2005

- Added PSC v1.00-1.03 support
- AY-files without file extension '.AY' was not detected (fixed)
- ESC key is used to close 'About' window now (specially for TAD)

20 September 2005

- Added YM5- and YM6-files integrity checker before loading to avoid problems
  during playing (thanks to Nikolay Amosov for test file
  JASON_BROOKE_OUTRUN_GAME_TUN2.YM)
- Added YM5- and YM6-files sample number range checker (thanks to Nikolay Amosov
  for test file MODU_ATTACK.YM)

24 September 2005

- Added new command line key "/adp" to add files from command line to the end of
  current playlist and start playing first ot them (specially for TAD)
- AY frequency range is up to 3.5 MHz now (specially for Vyacheslav Strunov and
  others)

v2.8 Beta 12:

8 October 2005

- ZXS-files registration removed from 'Tools' box

26 October 2005

- From one of last versions STP finder didn't work fine with initialized
  STP-modules (fixed)
- STP_InitId (header byte +9) after "Save As..." was equal to 0 for wrongly
  "uninitialized" STP-modules (fixed now). All modules are playable in Ay_Emul,
  but original ZX Spectrum STP player does not initialize them correctly and
  fails. All STP-modules ripped in Tools dialog has correct STP_InitId value
  anyway

4 November 2005

- Added Pro Tracker 3.x Utility modules support (with converting to snandard
  PT3)
- Only previous version error: after saving ASC0 files from playlist '.asc'
  extension was not appended (fixed)
- Changed 'Save As...' autofilename behavior (specially for TAD). Now, if
  original filename was not found, it uses source filename with appended
  hexadecimal index (playlist position number)

9 November 2005

- Shadow file inside of created YM6-file has '.ym' extension now (specially for
  T.A.D. 2005)

v2.8 Beta 13:

22 November 2005

- PT2 and PT3 searcher recalculates NumberOfPositions value before playing or
  saving (already was realized in Tools' PT2/3 searcher). Thanks to TAD for test
  module Square Head title.sna5.pt2

8 February 2006

- Added MIDI-files full support: MID and RMI files type 0, 1 and 2 (2 is
  accepted but not tested), notes visualization, seek bar, loop, text extractor
  and so on. Ay_Emul does not emulate MIDI devices (MIDI device installed on
  system is required). Thanks to Tom Grandgent for TMIDI source code
- FXM finder was removed (all existing FXMs extracted already, so no need to
  keep unstable FXM-files finder in Ay_Emul)
- Error of two previous versions was fixed: during saving playlists or
  converting modules Ay_Emul did not ask for overwrite permission

9 February 2006

- Upgrade BASS and BASSWMA support to v2.2
- Added 'Hanning window' option into 'BASS.DLL v2.2' tab of Mixer window
  (uncheck to decrease CPU usage)
- Loop button works now with all files playing by BASS

v2.8 Beta 14:

12 February 2006

- Added XMIDI-files support (including right looping). Thanks to Cless for The
  System Shock Random Generator source code
- MIDI playing engine is more stable now (fixed some bugs, added more smarter
  TAG-extractor, loading XMI and type 2 MID-files tracks into playlist as
  different entries)

13 February 2006

- Added amplitude visualization for MIDI-music

14 February 2006

- Redesigned file registration tab in Tools dialog
- Fixed some errors in code working with system registry

15 February 2006

- New format of AYL-playlist files: "FormatSpec" tag is a tune/sequence number
  for AY, AYM, XMI and MID (Type 2) files. Previous versions used "Offset" for
  an AY-files (still supported for compatibility)
- New command line feature: you can specify tune number for files containing
  more than one music. To add and play all music in file do as usually:

			Ay_Emul FileName1.ay FileName2.xmi

  To load and play only selected tunes of file use addition ":N" (N is tune
  number: 0 is 1st, 1 is 2nd and so on):

    Ay_Emul FileName1.ay:2 "Name2 With Spaces.xmi:0" "Its valid too.aym":3

- FormatSpec is placed on "List's item adjusting" dialog and marked as
  "Specific". For AY-files "Offset" must be either 0 or valid offset to desired
  song
- Added 'Seek to first "Note On" MIDI-event' option to skip silence at start of
  MIDI-files: if silence is greater than 0.5 of second, seek bar thumb "jumps"
  to 20 ms before first note start playing

16 February 2006

- Improved 'Autosaving last folder' option: saves paths of "fixed" drives only
  (i.e. hard disks and so on)

v2.8:

18 February 2006

- Previous version error fix: PSG/EPSG-files loader error
- Removed ZX-files seeking prescan, all required calculations before starting
  seeking now

v2.9 Beta 1:

3 April 2006

- Fixed some errors in mixer window interface
- Linear interpolation is used after filtering now (instead of average level).
  This method is better for "hi" frequencies emulation (close to SampleRate/2)
- Main window volume control is slightly more "non-linear" now

4 April 2006

- PT3-player bug is fixed (amplitude vibrato was not reseted during
  initialization)

20 August 2006

- New FIR-filter control: number of points is automatically calculated now. In
  case of too many points its number is truncated and averager is added instead
  of linear interpolation. User can only enable/disable filter in 'for quality'
  mode, current resampler mode are shown in bottom of 'Optimization' group of
  of 'Mixer' window.

21 August 2006

- At start-up MIDI and WaveOut devices are set by its name (not by number) now.
  Useful for systems with not fixed number of devices.

27 August 2006

- In 'Save As...' file name addition '_0' is removed if saving from *.sna,
  *.trd, etc for first playlist item (specially for TAD).
- Fixed previous version error: if several files was opening at on time in
  explorer, Ay_Emul started and stopped playing first of them (thanks to TAD for
  bug-report).
- You can call any ZX-modules editor now from 'Playlist' window, just specify
  path in 'Tools' dialog (for example 'C:\VT\VT.exe'). Thanks to Karbofos for
  idea.
- Fixed error in 'Reregister' function of 'Tools' dialog: non-Ay_Emul
  associations are not "killed" now (thank to TAD for bug-report).

2 September 2006

- All ZX trackers players initialization are fixed: all variables are set to
  zero before playing.
- Added default sample #1 for PT2-files (not used on ZX, but can be useful).

18 September 2006

- Bugfix: since Ay_Emul supports MIDI-files 'open file' dialog filter doesn't
  work right (last masks like *.trd, *.sna, etc are lost), this was Microsoft
  bug. Now using experimental code to access to open dialog's list box.

19 September 2006

- Optimization for perfomance was removed.
- 'Escape' button now can be used for minimizing Ay_Emul.

24 September 2006

- Open directory dialog is changed to shell's standard folder browser (thanks to
  TAD and other, who point me to limitations of old dialog).

v2.9 Beta 2:

28 September 2006

- Added tracker info during converting from PSM to VTX.
- Fixed some problems with folder browser.

06 January 2007

- Fixed Z80 emulation: OUT (C),0 command added.

29 April 2007

- Added 1.xx and 2.xx commands interpetation for PT 3.7+ modules.

1 May 2007

- One more standard STC string ID is added to STC title analizer.

7 May 2007

- AY emulation is redesigned to play Turbo Sound (2xAY) music.
- Any of two tracker modules (except FXM) can be played simultaneously now via
  special file format, which can be generated from Windows/DOS command line:

    copy/b Module1.pt3+Module2.sqt+ID ModuleTS.pt3

  where ID is 16 bytes length identifier file of next structure:
    +0 Str4 'PT3!' (PT3 type marker)
    +4 Word Module1FileSize
    +6 Str4 'SQT!' (SQT type marker)
    +A Word Module2FileSize
    +C Str4 '02TS' (TS marker)
- New playlist version is designed to store info about TS modules.

8 May 2007

- Added support of PT 3.7+ modules saved in TS mode.
- Experemental code for standard open dialog is removed (see change at 18
  September 2006) because not works in Win9x/Me/Vista. So, old problems come
  back (last masks in 'All Supported Types' filter are ignored). Will trying
  to write own Open Dialog.

9 May 2007

- All playlist operations like 'Convert to WAV...' work with all selected items
  now (specially for ASiC).

v2.9 Beta 3:

11 August 2007

- Fixed error of beta 2: wrong playing after forward seeking in AY-files (thanks
  to TAD for bug-report).
- Track descriptor default string "Silent now..." changed to "no song
  playing..." (thanks to Equinox).

12 August 2007

- Added BASS.DLL and BASSWMA.DLL v2.3 support.
- Added FFT8192 for BASS spectre visualisation.

15 August 2007

- Numpad 5 key can be used as Play/Pause button now (specially for TAD).
- Fixed error: wrong looping of YM2-files (see WINGS7.YM, thanks to TAD for bug-
  report).
- Specially for TAD playlist pop-up menu is remixed.
- Playlist improvement: use Space key to toggle current playlist item selection
  and Ctrl with cursor keys to move invisible cursor without selection changing.

v2.9 Beta 4:

20 June 2008

- Added UTF8ToANSI converter to OGG-tags extractor to fix non english strings
  displaying.
- 'All Files' is a default mask in OpenDialog now.

21 June 2008

- Added BASS.DLL and BASSWMA.DLL v2.4 support.
- Added FFT256 for BASS spectre visualisation.
- Playlist item is redrawn now if source file is not found during "save as...".
- Messages from other Ay_Emul instances is ignored now if exucuted any of modal
  dialogs (for safe playlist operations completion). Speccially for Newart.

22 June 2008

- Added APE and FLAC audio streams support via BASS_APE.DLL and BASSFLAC.DLL.

v2.9 Beta 5:

25 June 2008

- Added CUE sheet support for BASS streamed files.

27 June 2008

- Added OGG-tagged CUE-sheets in FLAC and OGG streams.

13 July 2008

- Long file names from Open File Dialog are converted to short if contain
  non-ANSI characters.
- Long file names from Open Folder Dialog are converted to short if contain
  non-ANSI characters.
- Long file names in Drag'n'Drop operations are converted to short if contain
  non-ANSI characters.
- Long file names in Command Line are converted to short if contain non-ANSI
  characters.

v2.9 beta 6 (experimental):

Legend: D2L - Delphi To Lazarus (conversion bug-fix or new feature)

1 November 2008

- D2L: Source is autoconverted from Delphi project to Lazarus one
- Added WV (WavePack) files support via basswv.dll
- D2L: No sound build for Linux (only AY related formats are supported)
- D2L: Version 1.6 of AYL playlist files to point UTF8 encoding
- D2L: Controls are Unicode now if running in Windows XP or Linux

v2.9 beta 7 (experimental):

2 November 2008

- D2L: Added AnsiToUTF8 for strings extractor in TRD/SCL image loader
- D2L: Added UTF8ToAnsi in ASC/STP 'SaveAs' for strings extracted from TRD/SCL

4 November 2008

- D2L: Added AnsiToUTF8 for AYS-skin v2.0 strings
- D2L: Shows exceptions of Free Pascal now
- Correct startup with default skin if user skin can not be loaded
- D2L: Corrected VTX/YM6 header editor
- D2L: Added UTF8ToAnsi for VTX/YM6 converter
- D2L: Unpacked YM-files loader bug fixed
- D2L: For ZX-formats only latin chars was allowed in filename (fixed)

5 November 2008

- D2L: Added support for Unicode file names during saving modules and playlist,
  converting to WAV/VTX/YM6/ZXAY and opening in external module editor
- D2L: ANSI or short filenames are saved in M3U now
- D2L TODO: AYSTATUS.TXT user defined filename can be only ANSI (as in Delphi)
- D2L TODO: 'Searching for tunes in files' work folder name can be only ANSI (as
  in Delphi)
- D2L: Russian messages in 'Searching for tunes in files' converted to UTF-8

8 November 2008

- Audio streams TAG-extractor is totally rewriten, the most tags and encodings
  are supported now (ID3v1, ID3v2, OGG, APEv1, APEv2, WMA, UTF-8, UTF-16)

9 November 2008

- Fixed error in MIDI text CRLF line splitter
- MOD messages, instrument and sample names are extracted to Comment of playlist
  item now
- D2L: application button could become hidden on system taskbar in mimize to
  tray mode, fixed

10 November 2008

- D2L: could not load M3U's with non-latin chars in filename (fixed)

12 November 2008

- D2L: converting to WAV/ZXAY/PSG/VTX/YM6 could not be aborted, fixed in
  Win32-version for the moment
- D2L: searching for tunes during opening unknown type files shown progress
  window non modally, fixed in Win32-version

13 November 2008

- BASS' FLAC, APE and WV DLLs wasn't unloaded after stopping playing, fixed

14 November 2008

- D2L: Russian description of associated file type was stored in UTF-8 in
  registry (fixed)
- D2L: MIDI, WAVE and MIXER devices names are converted to UTF-8 to correct
  show non-latin chars
- Fixed old error of manual selecting volume control

15 November 2008

- In "Always on Tray" mode mouse clicking on tray icon allows to minimize
  Ay_Emul (specially for TAD) or bring it to front if main window is overlapped
  by other non Ay_Emul windows

16 November 2008

- D2L: Strange bug in Windows 98 is "fixed": Tools window crashes Ay_Emul
  immediately after appearing. I really don't know, what's the problem (maybe
  LCL bug), but after some code rearranging all work now

22 November 2008

- D2L: Yet another Lazarus bug is found in Windows 98 mode: after starting/
  stopping playing manual sample rate entering field is corrupted with wrong
  values. I've replaced disabling/enabling SampleRate group with disabling/
  enabling its controls and all work now
- D2L: fixed finder and sorter of playlist in Windows 98 mode
- D2L: fixed AY Emulator Start menu link removing and link icon changing

v2.9 beta 8:

30 November 2008

- D2L: Couldn't load AYL-files with non-latin chars in filename. Fixed.

25 January 2009

- D2L: could not load M3U's items with non-latin chars in path (fixed)

27 January 2009

- Fixed error for multi-monitor systems: if main display is righter or lower
  Ay_Emul main window could be moved to 2nd display, but could not be moved
  back (thank to kay27 for bug-report and beta-testing).

2 February 2009

- D2L: if closing on OS shutdown or user logoff, current playlist and settings
  was not saved. Fixed.

8 February 2009

- Removed scroll repaint optimization: next string is recalculated and
  repainted each time before showing (thanks to TAD for describing error cases).
