Author Topic: Mantel Clock with hourly chime song without extra files  (Read 5803 times)

0 Members and 1 Guest are viewing this topic.

This topic contains a post which is marked as Best Answer. Press here if you would like to see it.

Offline SierraKen

  • Forum Resident
  • Posts: 1454
    • View Profile
Mantel Clock with hourly chime song without extra files
« on: December 16, 2020, 10:23:23 pm »
I need some input on this one folks. I believe the chimes sound good, they use a code example that's on the Wiki pages that I experimented with. I also found a common song that many clocks chime every hour and then found a conversion table for Hz (frequency) and notes. I had to change the Hz a bit but kept it relative to each other when experimenting. I also added a way to listen to the hourly chime song at anytime by just pressing the Space Bar. Tell me what you think. Is the color OK? Do the chimes sound good? This is my first clock that plays a song with chimes as well as the hour chimes every hour. No extra files are used. Also thanks to Dav who told me how to use _ICON _DISPLAY. :)

Edit: The name of this clock has changed from Grandfather Clock to Mantel Clock because it looks more like a Mantel Clock.

Code: QB64: [Select]
  1. SCREEN _NEWIMAGE(800, 600, 32)
  2. _TITLE "Mantle Clock - Press Space Bar to play hour chimes at anytime."
  3.     _LIMIT 50
  4.     a = _KEYHIT
  5.     IF a = 27 THEN END
  6.     IF a = 32 THEN song = 1: a = 0: _DELAY 1
  7.     CX = 400: CY = 300: R = 300: C = _RGB32(0, 78, 0)
  8.     fillCircle CX, CY, R, C
  9.     LINE (100, 300)-(700, 600), C, BF
  10.     CX = 400: CY = 300: R = 200: C = _RGB32(183, 139, 100)
  11.     fillCircle CX, CY, R, C
  12.     FOR lines = .25 TO 10 STEP .1
  13.         CIRCLE (400, 300), 250 + lines, _RGB32(0, 55, 0), 2 * _PI, _PI
  14.     NEXT lines
  15.     LINE (140, 300)-(150, 760), _RGB32(0, 55, 0), BF
  16.     LINE (650, 300)-(660, 760), _RGB32(0, 55, 0), BF
  17.  
  18.     FOR sc = 1 TO 60
  19.         ss = (60 - sc) * 6 + 180
  20.         x2 = INT(SIN(ss / 180 * 3.141592) * 140) + 400
  21.         y2 = INT(COS(ss / 180 * 3.141592) * 140) + 300
  22.         CIRCLE (x2, y2), 3, _RGB32(230, 230, 230)
  23.         n2 = (60 - sc) * 6 + 180
  24.         x3 = INT(SIN(n2 / 180 * 3.141592) * 160) + 390
  25.         y3 = INT(COS(n2 / 180 * 3.141592) * 160) + 295
  26.         COLOR _RGB32(0, 0, 0), _RGB32(183, 139, 100)
  27.         IF sc = 5 THEN _PRINTSTRING (x3, y3), "I"
  28.         IF sc = 10 THEN _PRINTSTRING (x3, y3), "II"
  29.         IF sc = 15 THEN _PRINTSTRING (x3, y3), "III"
  30.         IF sc = 20 THEN _PRINTSTRING (x3, y3), "IV"
  31.         IF sc = 25 THEN _PRINTSTRING (x3, y3), "V"
  32.         IF sc = 30 THEN _PRINTSTRING (x3, y3), "VI"
  33.         IF sc = 35 THEN _PRINTSTRING (x3, y3), "VII"
  34.         IF sc = 40 THEN _PRINTSTRING (x3, y3), "VIII"
  35.         IF sc = 45 THEN _PRINTSTRING (x3, y3), "IX"
  36.         IF sc = 50 THEN _PRINTSTRING (x3, y3), "X"
  37.         IF sc = 55 THEN _PRINTSTRING (x3, y3), "XI"
  38.         IF sc = 60 THEN _PRINTSTRING (x3, y3), "XII"
  39.     NEXT sc
  40.     COLOR , _RGB32(0, 0, 0)
  41.     clock song
  42.     CX = 400: CY = 300: R = 10: C = _RGB32(0, 0, 0)
  43.     fillCircle CX, CY, R, C
  44.     _DISPLAY
  45.     CLS
  46.  
  47. 'from Steve Gold standard
  48. SUB fillCircle (CX AS INTEGER, CY AS INTEGER, R AS INTEGER, C AS _UNSIGNED LONG)
  49.     DIM Radius AS INTEGER, RadiusError AS INTEGER
  50.     DIM X AS INTEGER, Y AS INTEGER
  51.     Radius = ABS(R): RadiusError = -Radius: X = Radius: Y = 0
  52.     IF Radius = 0 THEN PSET (CX, CY), C: EXIT SUB
  53.     LINE (CX - X, CY)-(CX + X, CY), C, BF
  54.     WHILE X > Y
  55.         RadiusError = RadiusError + Y * 2 + 1
  56.         IF RadiusError >= 0 THEN
  57.             IF X <> Y + 1 THEN
  58.                 LINE (CX - Y, CY - X)-(CX + Y, CY - X), C, BF
  59.                 LINE (CX - Y, CY + X)-(CX + Y, CY + X), C, BF
  60.             END IF
  61.             X = X - 1
  62.             RadiusError = RadiusError - X * 2
  63.         END IF
  64.         Y = Y + 1
  65.         LINE (CX - X, CY - Y)-(CX + X, CY - Y), C, BF
  66.         LINE (CX - X, CY + Y)-(CX + X, CY + Y), C, BF
  67.     WEND
  68.  
  69. SUB clock (song)
  70.     hours = TIMER \ 3600
  71.     minutes = TIMER \ 60 - hours * 60
  72.     seconds = (TIMER - hours * 3600 - minutes * 60)
  73.     ho$ = LEFT$(TIME$, 2): hou = VAL(ho$)
  74.     min$ = MID$(TIME$, 4, 2): minu = VAL(min$)
  75.     seco$ = RIGHT$(TIME$, 2): secon = VAL(seco$)
  76.     'Seconds
  77.     s = (60 - seconds) * 6 + 180
  78.     x = INT(SIN(s / 180 * 3.141592) * 120) + 400
  79.     y = INT(COS(s / 180 * 3.141592) * 120) + 300
  80.     FOR b = -5 TO 5 STEP .1
  81.         LINE (400 + b, 300)-(x, y), _RGB32(255, 255, 128)
  82.         LINE (400, 300 + b)-(x, y), _RGB32(255, 255, 128)
  83.     NEXT b
  84.     'Minutes
  85.     m = 180 - minutes * 6
  86.     xx = INT(SIN(m / 180 * 3.141592) * 120) + 400
  87.     yy = INT(COS(m / 180 * 3.141592) * 120) + 300
  88.     FOR b = -5 TO 5 STEP .1
  89.         LINE (400 + b, 300)-(xx, yy), _RGB32(0, 0, 0)
  90.         LINE (400, 300 + b)-(xx, yy), _RGB32(0, 0, 0)
  91.     NEXT b
  92.     'Hours
  93.     h = 360 - hours * 30 + 180
  94.     xxx = INT(SIN(h / 180 * 3.141592) * 90) + 400
  95.     yyy = INT(COS(h / 180 * 3.141592) * 90) + 300
  96.     FOR b = -5 TO 5 STEP .1
  97.         LINE (400 + b, 300)-(xxx, yyy), _RGB32(0, 0, 0)
  98.         LINE (400, 300 + b)-(xxx, yyy), _RGB32(0, 0, 0)
  99.     NEXT b
  100.     'Chimes
  101.     IF (minu = 0 AND secon = 0) OR song = 1 THEN
  102.         song = 0
  103.         'note frequencies
  104.         E = 332
  105.         C = 315
  106.         D = 323
  107.         G = 348
  108.  
  109.         FOR notes = 1 TO 16
  110.             IF notes = 1 THEN note = E
  111.             IF notes = 2 THEN note = C
  112.             IF notes = 3 THEN note = D
  113.             IF notes = 4 THEN note = G
  114.             IF notes = 5 THEN note = G
  115.             IF notes = 6 THEN note = D
  116.             IF notes = 7 THEN note = E
  117.             IF notes = 8 THEN note = C
  118.             IF notes = 9 THEN note = E
  119.             IF notes = 10 THEN note = D
  120.             IF notes = 11 THEN note = C
  121.             IF notes = 12 THEN note = G
  122.             IF notes = 13 THEN note = G
  123.             IF notes = 14 THEN note = D
  124.             IF notes = 15 THEN note = E
  125.             IF notes = 16 THEN note = C
  126.             DO
  127.                 'queue some sound
  128.                 DO WHILE _SNDRAWLEN < 0.5 'you may wish to adjust this
  129.                     sample = SIN(ttt * note * ATN(1) * 8) '340Hz sine wave (ttt * 440 * 2p)
  130.                     sample = sample * EXP(-ttt * 3) 'fade out eliminates clicks after sound
  131.                     _SNDRAW sample
  132.                     ttt = ttt + 1 / _SNDRATE 'sound card sample frequency determines time
  133.                 LOOP
  134.                 'do other stuff, but it may interrupt sound
  135.             LOOP WHILE ttt < 1 'play for 1 second
  136.             DO WHILE _SNDRAWLEN > 0 'Finish any left over queued sound!
  137.             LOOP
  138.             ttt = 0
  139.         NEXT notes
  140.         hour2 = hou
  141.         IF hour2 > 12 THEN hour2 = hour2 - 12
  142.         IF hour2 = 0 THEN hour2 = 12
  143.         FOR chimes = 1 TO hour2
  144.             ttt = 0
  145.             DO
  146.                 'queue some sound
  147.                 DO WHILE _SNDRAWLEN < 0.1 'you may wish to adjust this
  148.                     sample = SIN(ttt * 240 * ATN(1) * 8) '340Hz sine wave (ttt * 440 * 2p)
  149.                     sample = sample * EXP(-ttt * 3) 'fade out eliminates clicks after sound
  150.                     _SNDRAW sample
  151.                     ttt = ttt + 1 / _SNDRATE 'sound card sample frequency determines time
  152.                 LOOP
  153.                 'do other stuff, but it may interrupt sound
  154.             LOOP WHILE ttt < 2 'play for 2 seconds
  155.             DO WHILE _SNDRAWLEN > 0 'Finish any left over queued sound!
  156.             LOOP
  157.         NEXT chimes
  158.     END IF
  159.     two:
  160.  

GrandfatherClock.jpg
* GrandfatherClock.jpg (Filesize: 71.58 KB, Dimensions: 802x622, Views: 220)
« Last Edit: December 17, 2020, 03:09:34 pm by SierraKen »

Offline Dav

  • Forum Resident
  • Posts: 792
    • View Profile
Re: Grandfather Clock with hourly chime song without extra files
« Reply #1 on: December 16, 2020, 11:07:58 pm »
I like it @SierraKen. Great idea.   I played around with the chime notes, tried to make it sound like my dads old clock.  How do these sound?  I put in 0's to make a pause.  I found a good webpage that list frequencies of notes here.  The color looks good to me.

- Dav

Code: QB64: [Select]
  1.             IF notes = 1 THEN note = 311.13 'D#
  2.             IF notes = 2 THEN note = 246.94 'B
  3.             IF notes = 3 THEN note = 277.18 'C#
  4.             IF notes = 4 THEN note = 185.00 'F#
  5.             IF notes = 5 THEN note = 0
  6.             IF notes = 6 THEN note = 185.00 'F#
  7.             IF notes = 7 THEN note = 277.18 'C#
  8.             IF notes = 8 THEN note = 311.13 'D#
  9.             IF notes = 9 THEN note = 246.94 'B
  10.             IF notes = 10 THEN note = 0
  11.             IF notes = 11 THEN note = 311.13 'D#
  12.             IF notes = 12 THEN note = 277.18 'C3
  13.             IF notes = 13 THEN note = 246.94 'B
  14.             IF notes = 14 THEN note = 185.00 'F#
  15.             IF notes = 15 THEN note = 0
  16.             IF notes = 16 THEN note = 0
  17.  
« Last Edit: December 16, 2020, 11:11:10 pm by Dav »

Offline SierraKen

  • Forum Resident
  • Posts: 1454
    • View Profile
Re: Mantel Clock with hourly chime song without extra files
« Reply #2 on: December 16, 2020, 11:30:07 pm »
WOW Dav, THANK YOU!!! This is the exact song I was looking for! I added 4 more notes at the end, which are the same sequence as notes  6-9 because it's how I always remembered it. I hope everyone likes it! :))))

Edit: I just removed _ICON _DISPLAY because I believe it was causing the program to crash when I moved the program's window around sometimes.

Code: QB64: [Select]
  1. 'Mantel Clock by SierraKen with help for Westminster Quarters hourly song by Dav on the QB64.org forum.
  2. 'Created on 12-16-2020
  3. SCREEN _NEWIMAGE(800, 600, 32)
  4. _TITLE "Mantel Clock - Press Space Bar to play hour chimes at anytime."
  5.     _LIMIT 50
  6.     a = _KEYHIT
  7.     IF a = 27 THEN END
  8.     IF a = 32 THEN song = 1: a = 0: _DELAY 1
  9.     CX = 400: CY = 300: R = 300: C = _RGB32(0, 78, 0)
  10.     fillCircle CX, CY, R, C
  11.     LINE (100, 300)-(700, 600), C, BF
  12.     CX = 400: CY = 300: R = 200: C = _RGB32(183, 139, 100)
  13.     fillCircle CX, CY, R, C
  14.     FOR lines = .25 TO 10 STEP .1
  15.         CIRCLE (400, 300), 250 + lines, _RGB32(0, 55, 0), 2 * _PI, _PI
  16.     NEXT lines
  17.     LINE (140, 300)-(150, 760), _RGB32(0, 55, 0), BF
  18.     LINE (650, 300)-(660, 760), _RGB32(0, 55, 0), BF
  19.  
  20.     FOR sc = 1 TO 60
  21.         ss = (60 - sc) * 6 + 180
  22.         x2 = INT(SIN(ss / 180 * 3.141592) * 140) + 400
  23.         y2 = INT(COS(ss / 180 * 3.141592) * 140) + 300
  24.         CIRCLE (x2, y2), 3, _RGB32(230, 230, 230)
  25.         n2 = (60 - sc) * 6 + 180
  26.         x3 = INT(SIN(n2 / 180 * 3.141592) * 160) + 390
  27.         y3 = INT(COS(n2 / 180 * 3.141592) * 160) + 295
  28.         COLOR _RGB32(0, 0, 0), _RGB32(183, 139, 100)
  29.         IF sc = 5 THEN _PRINTSTRING (x3, y3), "I"
  30.         IF sc = 10 THEN _PRINTSTRING (x3, y3), "II"
  31.         IF sc = 15 THEN _PRINTSTRING (x3, y3), "III"
  32.         IF sc = 20 THEN _PRINTSTRING (x3, y3), "IV"
  33.         IF sc = 25 THEN _PRINTSTRING (x3, y3), "V"
  34.         IF sc = 30 THEN _PRINTSTRING (x3, y3), "VI"
  35.         IF sc = 35 THEN _PRINTSTRING (x3, y3), "VII"
  36.         IF sc = 40 THEN _PRINTSTRING (x3, y3), "VIII"
  37.         IF sc = 45 THEN _PRINTSTRING (x3, y3), "IX"
  38.         IF sc = 50 THEN _PRINTSTRING (x3, y3), "X"
  39.         IF sc = 55 THEN _PRINTSTRING (x3, y3), "XI"
  40.         IF sc = 60 THEN _PRINTSTRING (x3, y3), "XII"
  41.     NEXT sc
  42.     COLOR , _RGB32(0, 0, 0)
  43.     clock song
  44.     CX = 400: CY = 300: R = 10: C = _RGB32(0, 0, 0)
  45.     fillCircle CX, CY, R, C
  46.     _DISPLAY
  47.     CLS
  48.  
  49. 'from Steve Gold standard
  50. SUB fillCircle (CX AS INTEGER, CY AS INTEGER, R AS INTEGER, C AS _UNSIGNED LONG)
  51.     DIM Radius AS INTEGER, RadiusError AS INTEGER
  52.     DIM X AS INTEGER, Y AS INTEGER
  53.     Radius = ABS(R): RadiusError = -Radius: X = Radius: Y = 0
  54.     IF Radius = 0 THEN PSET (CX, CY), C: EXIT SUB
  55.     LINE (CX - X, CY)-(CX + X, CY), C, BF
  56.     WHILE X > Y
  57.         RadiusError = RadiusError + Y * 2 + 1
  58.         IF RadiusError >= 0 THEN
  59.             IF X <> Y + 1 THEN
  60.                 LINE (CX - Y, CY - X)-(CX + Y, CY - X), C, BF
  61.                 LINE (CX - Y, CY + X)-(CX + Y, CY + X), C, BF
  62.             END IF
  63.             X = X - 1
  64.             RadiusError = RadiusError - X * 2
  65.         END IF
  66.         Y = Y + 1
  67.         LINE (CX - X, CY - Y)-(CX + X, CY - Y), C, BF
  68.         LINE (CX - X, CY + Y)-(CX + X, CY + Y), C, BF
  69.     WEND
  70.  
  71. SUB clock (song)
  72.     hours = TIMER \ 3600
  73.     minutes = TIMER \ 60 - hours * 60
  74.     seconds = (TIMER - hours * 3600 - minutes * 60)
  75.     ho$ = LEFT$(TIME$, 2): hou = VAL(ho$)
  76.     min$ = MID$(TIME$, 4, 2): minu = VAL(min$)
  77.     seco$ = RIGHT$(TIME$, 2): secon = VAL(seco$)
  78.     'Seconds
  79.     s = (60 - seconds) * 6 + 180
  80.     x = INT(SIN(s / 180 * 3.141592) * 120) + 400
  81.     y = INT(COS(s / 180 * 3.141592) * 120) + 300
  82.     FOR b = -5 TO 5 STEP .1
  83.         LINE (400 + b, 300)-(x, y), _RGB32(255, 255, 128)
  84.         LINE (400, 300 + b)-(x, y), _RGB32(255, 255, 128)
  85.     NEXT b
  86.     'Minutes
  87.     m = 180 - minutes * 6
  88.     xx = INT(SIN(m / 180 * 3.141592) * 120) + 400
  89.     yy = INT(COS(m / 180 * 3.141592) * 120) + 300
  90.     FOR b = -5 TO 5 STEP .1
  91.         LINE (400 + b, 300)-(xx, yy), _RGB32(0, 0, 0)
  92.         LINE (400, 300 + b)-(xx, yy), _RGB32(0, 0, 0)
  93.     NEXT b
  94.     'Hours
  95.     h = 360 - hours * 30 + 180
  96.     xxx = INT(SIN(h / 180 * 3.141592) * 90) + 400
  97.     yyy = INT(COS(h / 180 * 3.141592) * 90) + 300
  98.     FOR b = -5 TO 5 STEP .1
  99.         LINE (400 + b, 300)-(xxx, yyy), _RGB32(0, 0, 0)
  100.         LINE (400, 300 + b)-(xxx, yyy), _RGB32(0, 0, 0)
  101.     NEXT b
  102.     'Chimes
  103.     IF (minu = 0 AND secon = 0) OR song = 1 THEN
  104.         song = 0
  105.  
  106.         'note frequencies
  107.         FOR notes = 1 TO 20
  108.             IF notes = 1 THEN note = 311.13 'D#
  109.             IF notes = 2 THEN note = 246.94 'B
  110.             IF notes = 3 THEN note = 277.18 'C#
  111.             IF notes = 4 THEN note = 185.00 'F#
  112.             IF notes = 5 THEN note = 0
  113.             IF notes = 6 THEN note = 185.00 'F#
  114.             IF notes = 7 THEN note = 277.18 'C#
  115.             IF notes = 8 THEN note = 311.13 'D#
  116.             IF notes = 9 THEN note = 246.94 'B
  117.             IF notes = 10 THEN note = 0
  118.             IF notes = 11 THEN note = 311.13 'D#
  119.             IF notes = 12 THEN note = 277.18 'C3
  120.             IF notes = 13 THEN note = 246.94 'B
  121.             IF notes = 14 THEN note = 185.00 'F#
  122.             IF notes = 15 THEN note = 0
  123.             IF notes = 16 THEN note = 185.00 'F#
  124.             IF notes = 17 THEN note = 277.18 'C#
  125.             IF notes = 18 THEN note = 311.13 'D#
  126.             IF notes = 19 THEN note = 246.94 'B
  127.             IF notes = 20 THEN note = 0
  128.  
  129.             DO
  130.                 'queue some sound
  131.                 DO WHILE _SNDRAWLEN < 0.5 'you may wish to adjust this
  132.                     sample = SIN(ttt * note * ATN(1) * 8) '340Hz sine wave (ttt * 440 * 2p)
  133.                     sample = sample * EXP(-ttt * 3) 'fade out eliminates clicks after sound
  134.                     _SNDRAW sample
  135.                     ttt = ttt + 1 / _SNDRATE 'sound card sample frequency determines time
  136.                 LOOP
  137.                 'do other stuff, but it may interrupt sound
  138.             LOOP WHILE ttt < 1 'play for 1 second
  139.             DO WHILE _SNDRAWLEN > 0 'Finish any left over queued sound!
  140.             LOOP
  141.             ttt = 0
  142.         NEXT notes
  143.         hour2 = hou
  144.         IF hour2 > 12 THEN hour2 = hour2 - 12
  145.         IF hour2 = 0 THEN hour2 = 12
  146.         FOR chimes = 1 TO hour2
  147.             ttt = 0
  148.             DO
  149.                 'queue some sound
  150.                 DO WHILE _SNDRAWLEN < 0.1 'you may wish to adjust this
  151.                     sample = SIN(ttt * 240 * ATN(1) * 8) '340Hz sine wave (ttt * 440 * 2p)
  152.                     sample = sample * EXP(-ttt * 3) 'fade out eliminates clicks after sound
  153.                     _SNDRAW sample
  154.                     ttt = ttt + 1 / _SNDRATE 'sound card sample frequency determines time
  155.                 LOOP
  156.                 'do other stuff, but it may interrupt sound
  157.             LOOP WHILE ttt < 2 'play for 2 seconds
  158.             DO WHILE _SNDRAWLEN > 0 'Finish any left over queued sound!
  159.             LOOP
  160.         NEXT chimes
  161.     END IF
  162.     two:
  163.  
« Last Edit: December 17, 2020, 03:10:52 pm by SierraKen »

Offline SierraKen

  • Forum Resident
  • Posts: 1454
    • View Profile
Re: Mantle Clock with hourly chime song without extra files
« Reply #3 on: December 16, 2020, 11:37:22 pm »
Everyone can compare the chimes with a real one on this video:


Offline SierraKen

  • Forum Resident
  • Posts: 1454
    • View Profile
Re: Mantle Clock with hourly chime song without extra files
« Reply #4 on: December 16, 2020, 11:49:30 pm »
I just removed _ICON _DISPLAY because I believe it was causing the program to crash when I moved the program's window around a bit sometimes. So please scroll up to the last one (right before the YouTube video) for the edited code.

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: Mantle Clock with hourly chime song without extra files
« Reply #5 on: December 17, 2020, 01:26:27 am »
Nice clock and idea for chimes. The really low notes sound a tad weak but you are making these sounds with QB64 sound commands, that's kinda amazing!

Offline Dav

  • Forum Resident
  • Posts: 792
    • View Profile
Re: Mantle Clock with hourly chime song without extra files
« Reply #6 on: December 17, 2020, 10:43:09 am »
Good job. _SNDRAW is one of those commands I haven't messed with.  I'm gonna look into it.  If it's possible to play two notes at the same time with it, maybe I can use it with the SPLAY project I started instead of using sound files.

- Dav

Offline SierraKen

  • Forum Resident
  • Posts: 1454
    • View Profile
Re: Mantle Clock with hourly chime song without extra files
« Reply #7 on: December 17, 2020, 01:56:48 pm »
Thanks B+. Yeah it uses Sound Card sounds. I think built-in ones or something. I'm pretty sure the example I use is from the "ringing bell" example here:

http://www.qb64.org/wiki/SNDRAW

Oh, and at first it does seem a little weak, but if you keep listening to it more and more, it's easier on the ears with the softer sound. For me anyway.
« Last Edit: December 17, 2020, 02:01:56 pm by SierraKen »

Offline SierraKen

  • Forum Resident
  • Posts: 1454
    • View Profile
Re: Mantle Clock with hourly chime song without extra files
« Reply #8 on: December 17, 2020, 02:47:40 pm »
I also just added this to the code above:
'Mantle Clock by SierraKen with help for Westminster Quarters hourly song by Dav on the QB64.org forum.
'Created on 12-16-2020

Offline SierraKen

  • Forum Resident
  • Posts: 1454
    • View Profile
Re: Mantel Clock with hourly chime song without extra files
« Reply #9 on: December 17, 2020, 03:12:28 pm »
I just found out that I have been misspelling this type of mantel. lol So I changed the code again above if you want to fix yours.

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: Mantel Clock with hourly chime song without extra files
« Reply #10 on: December 17, 2020, 05:40:13 pm »
The guy who would catch those things for us hasn't been around lately, I hope he is doing well.

Offline SierraKen

  • Forum Resident
  • Posts: 1454
    • View Profile
Re: Mantel Clock with hourly chime song without extra files
« Reply #11 on: December 17, 2020, 06:32:07 pm »
Here is a YouTube video of the clock chiming at 3pm.


Marked as best answer by SierraKen on December 31, 2020, 07:04:28 pm

Offline SierraKen

  • Forum Resident
  • Posts: 1454
    • View Profile
Re: Mantel Clock with hourly chime song without extra files
« Reply #12 on: January 01, 2021, 12:04:15 am »
Happy New Year Everyone! I just improved this Mantel Clock to make the hour hand move between numbers as the minute hand moves. Here is my gift to all of you to have a GREAT NEW YEAR!

Code: QB64: [Select]
  1. 'Mantel Clock by SierraKen with help for Westminster Quarters hourly song by Dav on the QB64.org forum.
  2. 'Created on 12-31-2020
  3. 'Added: The hour hand moves between hours now.
  4. SCREEN _NEWIMAGE(800, 600, 32)
  5. _TITLE "Mantel Clock - Press Space Bar to play hour chimes at anytime."
  6.     _LIMIT 50
  7.     a = _KEYHIT
  8.     IF a = 27 THEN END
  9.     IF a = 32 THEN song = 1: a = 0: _DELAY 1
  10.     CX = 400: CY = 300: R = 300: C = _RGB32(0, 78, 0)
  11.     fillCircle CX, CY, R, C
  12.     LINE (100, 300)-(700, 600), C, BF
  13.     CX = 400: CY = 300: R = 200: C = _RGB32(183, 139, 100)
  14.     fillCircle CX, CY, R, C
  15.     FOR lines = .25 TO 10 STEP .1
  16.         CIRCLE (400, 300), 250 + lines, _RGB32(0, 55, 0), 2 * _PI, _PI
  17.     NEXT lines
  18.     LINE (140, 300)-(150, 760), _RGB32(0, 55, 0), BF
  19.     LINE (650, 300)-(660, 760), _RGB32(0, 55, 0), BF
  20.  
  21.     FOR sc = 1 TO 60
  22.         ss = (60 - sc) * 6 + 180
  23.         x2 = INT(SIN(ss / 180 * 3.141592) * 140) + 400
  24.         y2 = INT(COS(ss / 180 * 3.141592) * 140) + 300
  25.         CIRCLE (x2, y2), 3, _RGB32(230, 230, 230)
  26.         n2 = (60 - sc) * 6 + 180
  27.         x3 = INT(SIN(n2 / 180 * 3.141592) * 160) + 390
  28.         y3 = INT(COS(n2 / 180 * 3.141592) * 160) + 295
  29.         COLOR _RGB32(0, 0, 0), _RGB32(183, 139, 100)
  30.         IF sc = 5 THEN _PRINTSTRING (x3, y3), "I"
  31.         IF sc = 10 THEN _PRINTSTRING (x3, y3), "II"
  32.         IF sc = 15 THEN _PRINTSTRING (x3, y3), "III"
  33.         IF sc = 20 THEN _PRINTSTRING (x3, y3), "IV"
  34.         IF sc = 25 THEN _PRINTSTRING (x3, y3), "V"
  35.         IF sc = 30 THEN _PRINTSTRING (x3, y3), "VI"
  36.         IF sc = 35 THEN _PRINTSTRING (x3, y3), "VII"
  37.         IF sc = 40 THEN _PRINTSTRING (x3, y3), "VIII"
  38.         IF sc = 45 THEN _PRINTSTRING (x3, y3), "IX"
  39.         IF sc = 50 THEN _PRINTSTRING (x3, y3), "X"
  40.         IF sc = 55 THEN _PRINTSTRING (x3, y3), "XI"
  41.         IF sc = 60 THEN _PRINTSTRING (x3, y3), "XII"
  42.     NEXT sc
  43.     COLOR , _RGB32(0, 0, 0)
  44.     clock song
  45.     CX = 400: CY = 300: R = 10: C = _RGB32(0, 0, 0)
  46.     fillCircle CX, CY, R, C
  47.     _DISPLAY
  48.     CLS
  49.  
  50. 'from Steve Gold standard
  51. SUB fillCircle (CX AS INTEGER, CY AS INTEGER, R AS INTEGER, C AS _UNSIGNED LONG)
  52.     DIM Radius AS INTEGER, RadiusError AS INTEGER
  53.     DIM X AS INTEGER, Y AS INTEGER
  54.     Radius = ABS(R): RadiusError = -Radius: X = Radius: Y = 0
  55.     IF Radius = 0 THEN PSET (CX, CY), C: EXIT SUB
  56.     LINE (CX - X, CY)-(CX + X, CY), C, BF
  57.     WHILE X > Y
  58.         RadiusError = RadiusError + Y * 2 + 1
  59.         IF RadiusError >= 0 THEN
  60.             IF X <> Y + 1 THEN
  61.                 LINE (CX - Y, CY - X)-(CX + Y, CY - X), C, BF
  62.                 LINE (CX - Y, CY + X)-(CX + Y, CY + X), C, BF
  63.             END IF
  64.             X = X - 1
  65.             RadiusError = RadiusError - X * 2
  66.         END IF
  67.         Y = Y + 1
  68.         LINE (CX - X, CY - Y)-(CX + X, CY - Y), C, BF
  69.         LINE (CX - X, CY + Y)-(CX + X, CY + Y), C, BF
  70.     WEND
  71.  
  72. SUB clock (song)
  73.     'hours = TIMER \ 3600
  74.     hours = (TIMER \ 3600)
  75.     minutes = TIMER \ 60 - hours * 60
  76.     seconds = (TIMER - hours * 3600 - minutes * 60)
  77.     hours = hours + (minutes / 60) 'Code added to make hour hand move between numbers.
  78.     ho$ = LEFT$(TIME$, 2): hou = VAL(ho$)
  79.     min$ = MID$(TIME$, 4, 2): minu = VAL(min$)
  80.     seco$ = RIGHT$(TIME$, 2): secon = VAL(seco$)
  81.  
  82.     'Seconds
  83.     s = (60 - seconds) * 6 + 180
  84.     x = INT(SIN(s / 180 * 3.141592) * 120) + 400
  85.     y = INT(COS(s / 180 * 3.141592) * 120) + 300
  86.     FOR b = -5 TO 5 STEP .1
  87.         LINE (400 + b, 300)-(x, y), _RGB32(255, 255, 128)
  88.         LINE (400, 300 + b)-(x, y), _RGB32(255, 255, 128)
  89.     NEXT b
  90.     'Minutes
  91.     m = 180 - minutes * 6
  92.     xx = INT(SIN(m / 180 * 3.141592) * 120) + 400
  93.     yy = INT(COS(m / 180 * 3.141592) * 120) + 300
  94.     FOR b = -5 TO 5 STEP .1
  95.         LINE (400 + b, 300)-(xx, yy), _RGB32(0, 0, 0)
  96.         LINE (400, 300 + b)-(xx, yy), _RGB32(0, 0, 0)
  97.     NEXT b
  98.     'Hours
  99.     h = 360 - hours * 30 + 180
  100.     xxx = INT(SIN(h / 180 * 3.141592) * 90) + 400
  101.     yyy = INT(COS(h / 180 * 3.141592) * 90) + 300
  102.     FOR b = -5 TO 5 STEP .1
  103.         LINE (400 + b, 300)-(xxx, yyy), _RGB32(0, 0, 0)
  104.         LINE (400, 300 + b)-(xxx, yyy), _RGB32(0, 0, 0)
  105.     NEXT b
  106.     'Chimes
  107.     IF (minu = 0 AND secon = 0) OR song = 1 THEN
  108.         song = 0
  109.  
  110.         'note frequencies
  111.         FOR notes = 1 TO 20
  112.             IF notes = 1 THEN note = 311.13 'D#
  113.             IF notes = 2 THEN note = 246.94 'B
  114.             IF notes = 3 THEN note = 277.18 'C#
  115.             IF notes = 4 THEN note = 185.00 'F#
  116.             IF notes = 5 THEN note = 0
  117.             IF notes = 6 THEN note = 185.00 'F#
  118.             IF notes = 7 THEN note = 277.18 'C#
  119.             IF notes = 8 THEN note = 311.13 'D#
  120.             IF notes = 9 THEN note = 246.94 'B
  121.             IF notes = 10 THEN note = 0
  122.             IF notes = 11 THEN note = 311.13 'D#
  123.             IF notes = 12 THEN note = 277.18 'C3
  124.             IF notes = 13 THEN note = 246.94 'B
  125.             IF notes = 14 THEN note = 185.00 'F#
  126.             IF notes = 15 THEN note = 0
  127.             IF notes = 16 THEN note = 185.00 'F#
  128.             IF notes = 17 THEN note = 277.18 'C#
  129.             IF notes = 18 THEN note = 311.13 'D#
  130.             IF notes = 19 THEN note = 246.94 'B
  131.             IF notes = 20 THEN note = 0
  132.  
  133.             DO
  134.                 'queue some sound
  135.                 DO WHILE _SNDRAWLEN < 0.5 'you may wish to adjust this
  136.                     sample = SIN(ttt * note * ATN(1) * 8) '340Hz sine wave (ttt * 440 * 2p)
  137.                     sample = sample * EXP(-ttt * 3) 'fade out eliminates clicks after sound
  138.                     _SNDRAW sample
  139.                     ttt = ttt + 1 / _SNDRATE 'sound card sample frequency determines time
  140.                 LOOP
  141.                 'do other stuff, but it may interrupt sound
  142.             LOOP WHILE ttt < 1 'play for 1 second
  143.             DO WHILE _SNDRAWLEN > 0 'Finish any left over queued sound!
  144.             LOOP
  145.             ttt = 0
  146.         NEXT notes
  147.         hour2 = hou
  148.         IF hour2 > 12 THEN hour2 = hour2 - 12
  149.         IF hour2 = 0 THEN hour2 = 12
  150.         FOR chimes = 1 TO hour2
  151.             ttt = 0
  152.             DO
  153.                 'queue some sound
  154.                 DO WHILE _SNDRAWLEN < 0.1 'you may wish to adjust this
  155.                     sample = SIN(ttt * 240 * ATN(1) * 8) '340Hz sine wave (ttt * 440 * 2p)
  156.                     sample = sample * EXP(-ttt * 3) 'fade out eliminates clicks after sound
  157.                     _SNDRAW sample
  158.                     ttt = ttt + 1 / _SNDRATE 'sound card sample frequency determines time
  159.                 LOOP
  160.                 'do other stuff, but it may interrupt sound
  161.             LOOP WHILE ttt < 2 'play for 2 seconds
  162.             DO WHILE _SNDRAWLEN > 0 'Finish any left over queued sound!
  163.             LOOP
  164.         NEXT chimes
  165.     END IF
  166.     two:
  167.  
Mantel Clock with update.jpg
* Mantel Clock with update.jpg (Filesize: 73.56 KB, Dimensions: 800x626, Views: 147)
« Last Edit: January 01, 2021, 01:23:40 am by SierraKen »

Offline _vince

  • Seasoned Forum Regular
  • Posts: 422
    • View Profile
Re: Mantel Clock with hourly chime song without extra files
« Reply #13 on: January 01, 2021, 04:07:49 am »
I like the art of no extra files, nicely done

Offline SierraKen

  • Forum Resident
  • Posts: 1454
    • View Profile
Re: Mantel Clock with hourly chime song without extra files
« Reply #14 on: January 01, 2021, 12:21:49 pm »
Thanks Vince!