Author Topic: I've got a problem...  (Read 2797 times)

0 Members and 1 Guest are viewing this topic.

Offline Prithak

  • Newbie
  • Posts: 56
  • Life itself is a Programming Language!
    • View Profile
    • My Programming Language
I've got a problem...
« on: February 07, 2019, 08:10:06 am »
Here is my code:
Code: QB64: [Select]
  1. SCREEN _NEWIMAGE(500, 600, 32)
  2. r = 100
  3. g = 200
  4. b = 255
  5. red& = _LOADIMAGE("music/red.png")
  6. blue& = _LOADIMAGE("music/blue.png")
  7. orange& = _LOADIMAGE("music/orange.png")
  8. green& = _LOADIMAGE("music/green.png")
  9. DIM location$(12)
  10. DIM type$(12)
  11. DIM h&(12)
  12. DIM pic&(12)
  13. DIM x(12)
  14. DIM y(12)
  15. OPEN "music.txt" FOR INPUT AS #1
  16. FOR i = 1 TO 12
  17.     INPUT #1, location$(i)
  18.     INPUT #1, type$(i)
  19.     IF type$(i) = "pink" THEN pic&(i) = _LOADIMAGE("music/red.png")
  20.     IF type$(i) = "orange" THEN pic&(i) = _LOADIMAGE("music/green.png")
  21.     IF type$(i) = "loop" THEN pic&(i) = _LOADIMAGE("music/blue.png")
  22.     READ x(i), y(i)
  23.     here:
  24.     k$ = UCASE$(INKEY$)
  25.     FOR i = 1 TO 12
  26.         _PUTIMAGE (x(i), y(i))-(x(i) + 90, y(i) + 90), pic&(i)
  27.     NEXT i
  28.     maketiles
  29.  
  30.     IF LEN(k$) THEN
  31.         IF k$ = "Q" THEN k = 10: GOTO there
  32.         IF k$ = "W" THEN k = 11: GOTO there
  33.         IF k$ = "E" THEN k = 12: GOTO there
  34.  
  35.         k = VAL(k$)
  36.         IF k = 7 THEN k = 1: GOTO there
  37.         IF k = 8 THEN k = 2: GOTO there
  38.         IF k = 9 THEN k = 3: GOTO there
  39.         IF k = 1 THEN k = 7
  40.         IF k = 2 THEN k = 8
  41.         IF k = 3 THEN k = 9
  42.         there:
  43.         c = k
  44.         IF type$(k) = "loop" THEN
  45.             IF _SNDPLAYING(l&) = -1 THEN
  46.                 _SNDSTOP l&
  47.                 _SNDCLOSE l&
  48.             END IF
  49.             l& = _SNDOPEN(location$(k), "SYNC")
  50.             _SNDLOOP l&
  51.         ELSEIF type$(k) = "orange" THEN
  52.             IF _SNDPLAYING(l&) = -1 THEN _SNDSTOP l&: _SNDCLOSE l&
  53.             IF _SNDPLAYING(h&) = -1 THEN _SNDSTOP h&: _SNDCLOSE h&
  54.             o& = _SNDOPEN(location$(k), "SYNC")
  55.             _SNDPLAY o&
  56.         ELSE
  57.             IF _SNDPLAYING(h&) = -1 THEN
  58.                 _SNDSTOP h&
  59.                 _SNDCLOSE h&
  60.             END IF
  61.             h& = _SNDOPEN(location$(k), "SYNC")
  62.             _SNDPLAY h&
  63.         END IF
  64.     END IF
  65.     LOCATE 1, 1: PRINT c
  66.     _DISPLAY
  67.     CLS
  68.  
  69. DATA 100,100,200,100,300,100,100,200,200,200,300,200,100,300,200,300,300,300,100,400,200,400,300,400
  70.  
  71. SUB maketiles ()
  72.     FOR i = 100 TO 300 STEP 100
  73.         FOR j = 100 TO 400 STEP 100
  74.             LINE (i, j)-(i + 90, j + 90), _RGB32(255, 255, 255), B
  75.         NEXT j
  76.     NEXT i
  77.  
And I gave the zip file.
Here, once I press a loop tile, and press it again, it keeps on playing it. How can I remove it? (Once the key is hit of the loop bar(blue one), if the music is playing then end it and return back)????
I hope you understand...

BTW, if you wanna play this music try typing this:
7
88 9 8 5 9 88 9 8 5 6 88 9 8 5 9 88 9 8 5 6
33 666 555 999 5555 36 36 36

lol (Only true DBS fans will get this lol)
CLS
IF computer$ = "ON" THEN
me$ = "Happy!"
ELSE
me$ = "Time To Draw!"
END IF
END

Offline Petr

  • Forum Resident
  • Posts: 1720
  • The best code is the DNA of the hops.
    • View Profile
Re: I've got a problem...
« Reply #1 on: February 07, 2019, 08:56:41 am »
Hi Prithak, try _SNDSETPOS, if it solve your problem.

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: I've got a problem...
« Reply #2 on: February 07, 2019, 11:37:12 am »
Prithak, I see trouble in this code snip:
Code: QB64: [Select]
  1. IF LEN(k$) THEN
  2.     IF k$ = "Q" THEN k = 10: GOTO there
  3.     IF k$ = "W" THEN k = 11: GOTO there
  4.     IF k$ = "E" THEN k = 12: GOTO there
  5.  
  6.     k = VAL(k$)
  7.  
  8.     IF k = 7 THEN k = 1: GOTO there
  9.     IF k = 8 THEN k = 2: GOTO there
  10.     IF k = 9 THEN k = 3: GOTO there
  11.     IF k = 1 THEN k = 7
  12.     IF k = 2 THEN k = 8
  13.     IF k = 3 THEN k = 9  
  14.  
  15.  

Edit: oops, no just a little weird ;-))

« Last Edit: February 07, 2019, 11:45:49 am by bplus »

Offline TempodiBasic

  • Forum Resident
  • Posts: 1792
    • View Profile
Re: I've got a problem...
« Reply #3 on: February 19, 2019, 03:51:01 am »
Hi Prithak
yep a QB64 MusicMaker!
fine idea!

my feedbacks

1. Input must be improved because you can run in an overflow of input from keyboard with error by _soundPlaying():_sndstop():_sndclose() in sequence!  I got this issue both with lines 55,56,57 (type$() = "loop") both with lines 62 or 63  (type$()="orange")

2. try to compact the code of the same area in the same place of the code
here I post your code with my suddivision in different function areas

3. I prefer to use a codeblock like a sub or function with parameter instead of goto and global variables
Here your code with comments
Quote
'INITIALIZATION AREA
SCREEN _NEWIMAGE(500, 600, 32)
r = 100
g = 200
b = 255
red& = _LOADIMAGE("music/red.png")
blue& = _LOADIMAGE("music/blue.png")
orange& = _LOADIMAGE("music/orange.png")
green& = _LOADIMAGE("music/green.png")
'DECLARATION AREA OF VARIABLES AND CONSTANTS
DIM location$(12)
DIM type$(12)
DIM h&(12)
DIM pic&(12)
DIM x(12)
DIM y(12)
' SECOND INITIALIZATION AREA
OPEN "music.txt" FOR INPUT AS #1
FOR i = 1 TO 12
    INPUT #1, location$(i)
    INPUT #1, type$(i)
    IF type$(i) = "pink" THEN pic&(i) = _LOADIMAGE("music/red.png")
    IF type$(i) = "orange" THEN pic&(i) = _LOADIMAGE("music/green.png")
    IF type$(i) = "loop" THEN pic&(i) = _LOADIMAGE("music/blue.png")
    READ x(i), y(i)
NEXT i
CLOSE #1

'MAIN LOOP
DO
    here: ' NO INSTRUCTIONS JUMPS HERE
    ' INPUT MANAGER
    k$ = UCASE$(INKEY$)

    ' GRAPHIC INTERFACE
    FOR i = 1 TO 12
        _PUTIMAGE (x(i), y(i))-(x(i) + 90, y(i) + 90), pic&(i)
    NEXT i
    maketiles
    ' COMMAND ENGINE
    IF LEN(k$) THEN
        IF k$ = "Q" THEN k = 10: GOTO there
        IF k$ = "W" THEN k = 11: GOTO there
        IF k$ = "E" THEN k = 12: GOTO there

        k = VAL(k$)
        IF k = 7 THEN k = 1: GOTO there
        IF k = 8 THEN k = 2: GOTO there
        IF k = 9 THEN k = 3: GOTO there
        IF k = 1 THEN k = 7
        IF k = 2 THEN k = 8
        IF k = 3 THEN k = 9
        'SOUND MAKER AREA
        there: ' A LABEL WITH MANY GOTO? BETTER A SUB/FUNCTION WITH PARAMETER?
        c = k
        IF type$(k) = "loop" THEN
            IF _SNDPLAYING(l&) = -1 THEN
                _SNDSTOP l&
                _SNDCLOSE l&
            END IF
            l& = _SNDOPEN(location$(k), "SYNC")
            _SNDLOOP l&
        ELSEIF type$(k) = "orange" THEN
            IF _SNDPLAYING(l&) = -1 THEN _SNDSTOP l&: _SNDCLOSE l&
            IF _SNDPLAYING(h&) = -1 THEN _SNDSTOP h&: _SNDCLOSE h&
            o& = _SNDOPEN(location$(k), "SYNC")
            _SNDPLAY o&
        ELSE
            IF _SNDPLAYING(h&) = -1 THEN
                _SNDSTOP h&
                _SNDCLOSE h&
            END IF
            h& = _SNDOPEN(location$(k), "SYNC")
            _SNDPLAY h&
        END IF
    END IF
    ' DEBUG AREA
    LOCATE 1, 1: PRINT c
    ' SECOND GRAPHIC AREA
    _DISPLAY
    CLS 'HOW MUCH TIME IS THERE BETWEEN SHOWING OUTPUT AND ERASE OF SCREEN?
LOOP

' DATA SETTINGS
DATA 100,100,200,100,300,100,100,200,200,200,300,200,100,300,200,300,300,300,100,400,200,400,300,400

'SUB OF GRAPHIC AREA
SUB maketiles ()
    FOR i = 100 TO 300 STEP 100
        FOR j = 100 TO 400 STEP 100
            LINE (i, j)-(i + 90, j + 90), _RGB32(255, 255, 255), B
        NEXT j
    NEXT i
END SUB
Programming isn't difficult, only it's  consuming time and coffee