Recent

Author Topic: Pascal and Musical Tones :D  (Read 5571 times)

Thaddy

  • Hero Member
  • *****
  • Posts: 16299
  • Censorship about opinions does not belong here.
Re: Pascal and Musical Tones :D
« Reply #15 on: January 11, 2025, 11:52:17 am »
Fred, while searching for the chordfinder code, that I did not fid yet,


Found it. Windows only. Needs Kol/kol64 and the 3.0.4 compiler.
Both keyboard and fretboard notes can be played with a mouse.
The most common guitar tunings are supported.
Guitar chords can be copied to the clipboard as bitmap.
Also supports a midi external keyboard (two ways), by default uses the MS midi synth.
21 years old and still looking good...
And just 36 kilobyte, yes kilo.
« Last Edit: January 11, 2025, 12:12:12 pm by Thaddy »
If I smell bad code it usually is bad code and that includes my own code.

Fred vS

  • Hero Member
  • *****
  • Posts: 3442
    • StrumPract is the musicians best friend
Re: Pascal and Musical Tones :D
« Reply #16 on: January 11, 2025, 12:20:26 pm »
Hello Thaddy.

Great!

I will try it asap (using wine and after installing fpc 3.0.4).
Write you soon.

Fre;D
I use Lazarus 2.2.0 32/64 and FPC 3.2.2 32/64 on Debian 11 64 bit, Windows 10, Windows 7 32/64, Windows XP 32,  FreeBSD 64.
Widgetset: fpGUI, MSEgui, Win32, GTK2, Qt.

https://github.com/fredvs
https://gitlab.com/fredvs
https://codeberg.org/fredvs

Thaddy

  • Hero Member
  • *****
  • Posts: 16299
  • Censorship about opinions does not belong here.
Re: Pascal and Musical Tones :D
« Reply #17 on: January 11, 2025, 01:03:04 pm »
It runs under wine. I tried that at the time.
I just noticed this is not the fpc version, so just add {$ifdef fpc}{$mode delphi}{$endif} to the units. That is all the difference. For kol you need to define asmmode intel and purepascal.
« Last Edit: January 11, 2025, 01:07:28 pm by Thaddy »
If I smell bad code it usually is bad code and that includes my own code.

Fred vS

  • Hero Member
  • *****
  • Posts: 3442
    • StrumPract is the musicians best friend
Re: Pascal and Musical Tones :D
« Reply #18 on: January 11, 2025, 02:23:30 pm »
It runs under wine. I tried that at the time.
Hum, here on XUbuntu 24.4, no luck, see picture.

I just noticed this is not the fpc version, so just add {$ifdef fpc}{$mode delphi}{$endif} to the units. That is all the difference. For kol you need to define asmmode intel and purepascal.
OK, added {$mode delphi} in all units and used KOL code from there (is it ok?): https://github.com/rofl0r/KOL/
But error at compilation: (in attachment, the KOL.pas that I used).

Quote
fred@fred-IdeaPad:~/thaddy/chordfinder/KOL-master$ wine fpc.exe -B -FUunits /home/fred/thaddy/chordfinder/Chordfinder.dpr
Free Pascal Compiler version 3.2.2 for i386
Copyright (c) 1993-2024 by Florian Klaempfl and others
Target OS: Win32 for i386
Compiling \home\fred\thaddy\chordfinder\Chordfinder.dpr
Compiling KOL.pas
KOL.pas(228,7) Warning: Virtual methods are used without a constructor in "_TObj
"
KOL.pas(275,6) Warning: Destructor should be public
KOL.pas(391,5) Warning: Destructor should be public
KOL.pas(570,5) Warning: Destructor should be public
KOL.pas(703,5) Warning: Destructor should be public
KOL.pas(855,5) Warning: Destructor should be public
KOL.pas(1187,5) Warning: Destructor should be public
KOL.pas(2016,5) Warning: Destructor should be public
KOL.pas(2535,5) Warning: Destructor should be public
KOL.pas(2841,5) Warning: Destructor should be public
KOL.pas(9044,5) Warning: Destructor should be public
KOL.pas(9145,5) Warning: Destructor should be public
KOL.pas(9207,5) Warning: Destructor should be public
KOL.pas(10614,5) Warning: Destructor should be public
KOL.pas(11886,3) Warning: Some fields coming after "aSetBkColor" were not initia
lized
KOL.pas(11935,3) Warning: Some fields coming after "aSetBkColor" were not initia
lized
KOL.pas(12085,3) Warning: Some fields coming after "aSetBkColor" were not initia
lized
KOL.pas(12449,29) Error: OFFSET used without identifier
KOL.pas(12449,29) Error: Invalid constant expression
KOL.pas(12449,41) Error: Assembler syntax error in operand
KOL.pas(12458,29) Error: OFFSET used without identifier
KOL.pas(12458,29) Error: Invalid constant expression
KOL.pas(12458,41) Error: Assembler syntax error in operand
KOL.pas(12468,28) Error: OFFSET used without identifier
KOL.pas(12468,28) Error: Invalid constant expression
KOL.pas(12468,40) Error: Assembler syntax error in operand
KOL.pas(12483,18) Error: Unknown identifier "SYSTEM.LSTRCLR"
KOL.pas(12483,18) Error: Assembler syntax error
KOL.pas(12510,19) Warning: No size specified and unable to determine the size of
 the operands, using DWORD as default
KOL.pas(13104,18) Warning: No size specified and unable to determine the size of
 the operands, using DWORD as default
KOL.pas(13333,19) Warning: Calling an overload function in assembler
KOL.pas(13365,48) Error: Error building record offset
KOL.pas(13369,48) Error: Error building record offset
KOL.pas(13475,30) Warning: Use of +offset(%ebp) for parameters invalid here
KOL.pas(13480,29) Warning: Use of +offset(%ebp) for parameters invalid here
KOL.pas(13583,18) Warning: Calling an overload function in assembler
KOL.pas(13654,19) Warning: Calling an overload function in assembler
KOL.pas(14180,27) Error: OFFSET used without identifier
KOL.pas(14180,27) Error: Invalid constant expression
KOL.pas(14180,35) Error: Assembler syntax error in operand
KOL.pas(14190,25) Error: OFFSET used without identifier
KOL.pas(14190,25) Error: Invalid constant expression
KOL.pas(14190,33) Error: Assembler syntax error in operand
KOL.pas(14623,53) Error: OFFSET used without identifier
KOL.pas(14623,53) Error: Invalid constant expression
KOL.pas(14623,62) Error: Assembler syntax error in operand
KOL.pas(14625,60) Error: OFFSET used without identifier
KOL.pas(14625,60) Error: Invalid constant expression
KOL.pas(14625,76) Error: Assembler syntax error in operand
KOL.pas(14657,53) Error: OFFSET used without identifier
KOL.pas(14657,53) Error: Invalid constant expression
KOL.pas(14657,61) Error: Assembler syntax error in operand
KOL.pas(14659,60) Error: OFFSET used without identifier
KOL.pas(14659,60) Error: Invalid constant expression
KOL.pas(14659,75) Error: Assembler syntax error in operand
KOL.pas(14665,29) Error: OFFSET used without identifier
KOL.pas(14665,29) Error: Invalid constant expression
KOL.pas(14665,39) Error: Assembler syntax error in operand
KOL.pas(14692,53) Error: OFFSET used without identifier
KOL.pas(14692,53) Error: Invalid constant expression
KOL.pas(14692,60) Error: Assembler syntax error in operand
KOL.pas(14694,60) Error: OFFSET used without identifier
KOL.pas(14694,60) Error: Invalid constant expression
KOL.pas(14694,74) Error: Assembler syntax error in operand
KOL.pas(14895,47) Error: Error building record offset
KOL.pas(14899,47) Error: Error building record offset
KOL.pas(14939,44) Error: Error building record offset
KOL.pas(15055,18) Warning: No size specified and unable to determine the size of
 the operands, using DWORD as default
KOL.pas(15078,18) Warning: No size specified and unable to determine the size of
 the operands, using DWORD as default
KOL.pas(15176,29) Warning: Use of -offset(%ebp) is not recommended for local var
iable access
KOL.pas(15191,9) Warning: fdivrp without operand translated into fdivrpP
KOL.pas(15191,9) Warning: "fdivrp" without operand translated into "fdivrp %st,%
st(1)"
KOL.pas(15194,9) Warning: fmulp without operand translated into fmulpP
KOL.pas(15201,29) Warning: Use of -offset(%ebp) is not recommended for local var
iable access
KOL.pas(15205,9) Warning: fmulp without operand translated into fmulpP
KOL.pas(15211,9) Warning: fmulp without operand translated into fmulpP
KOL.pas(15218,9) Warning: faddp without operand translated into faddpP
KOL.pas(15218,9) Warning: "faddp" without operand translated into "faddp %st,%st
(1)"
KOL.pas(15219,9) Warning: fdivrp without operand translated into fdivrpP
KOL.pas(15219,9) Warning: "fdivrp" without operand translated into "fdivrp %st,%
st(1)"
KOL.pas(15220,9) Warning: faddp without operand translated into faddpP
KOL.pas(15220,9) Warning: "faddp" without operand translated into "faddp %st,%st
(1)"
KOL.pas(15228,9) Warning: fmulp without operand translated into fmulpP
KOL.pas(15234,9) Warning: fmulp without operand translated into fmulpP
KOL.pas(15263,29) Warning: Use of -offset(%ebp) is not recommended for local var
iable access
KOL.pas(15282,29) Warning: Use of -offset(%ebp) is not recommended for local var
iable access
KOL.pas(15352,51) Error: OFFSET used without identifier
KOL.pas(15352,51) Error: Invalid constant expression
KOL.pas(15352,62) Error: Assembler syntax error in operand
KOL.pas(15354,45) Error: Error building record offset
KOL.pas(15382,46) Error: Error building record offset
KOL.pas(15384,36) Error: Error building record offset
KOL.pas(15419,40) Error: Error building record offset
KOL.pas(15419,40) Fatal: There were 50 errors compiling module, stopping
Fatal: Compilation aborted
I use Lazarus 2.2.0 32/64 and FPC 3.2.2 32/64 on Debian 11 64 bit, Windows 10, Windows 7 32/64, Windows XP 32,  FreeBSD 64.
Widgetset: fpGUI, MSEgui, Win32, GTK2, Qt.

https://github.com/fredvs
https://gitlab.com/fredvs
https://codeberg.org/fredvs

Thaddy

  • Hero Member
  • *****
  • Posts: 16299
  • Censorship about opinions does not belong here.
Re: Pascal and Musical Tones :D
« Reply #19 on: January 11, 2025, 02:29:10 pm »
I see. Easy to fix, give a bit of time. Delphi is a bit more leanient with asm syntax.I used to have a Fpc version but that was not on one of my servers (where I found it eventually)
As is it compiles with D7, but I will make it compile again in freepascal.
You need to define purepascal, then the basm code is skipped altogether.
« Last Edit: January 11, 2025, 02:37:35 pm by Thaddy »
If I smell bad code it usually is bad code and that includes my own code.

Fred vS

  • Hero Member
  • *****
  • Posts: 3442
    • StrumPract is the musicians best friend
Re: Pascal and Musical Tones :D
« Reply #20 on: January 11, 2025, 02:37:06 pm »
but I will make it compile again in freepascal.
Zeer goed!  ;D
(And maybe also a Linux version and dont hesitate to create a github or gitlab or codeberg or gitelse ... project of your wonderful Chordfinder .  :-X )
I use Lazarus 2.2.0 32/64 and FPC 3.2.2 32/64 on Debian 11 64 bit, Windows 10, Windows 7 32/64, Windows XP 32,  FreeBSD 64.
Widgetset: fpGUI, MSEgui, Win32, GTK2, Qt.

https://github.com/fredvs
https://gitlab.com/fredvs
https://codeberg.org/fredvs

Thaddy

  • Hero Member
  • *****
  • Posts: 16299
  • Censorship about opinions does not belong here.
Re: Pascal and Musical Tones :D
« Reply #21 on: January 11, 2025, 11:44:50 pm »
Anyway, while I am busy fixing that, the drawing routines will work in a Lazarus control.
As will the midi stuff.
If I smell bad code it usually is bad code and that includes my own code.

TBMan

  • New member
  • *
  • Posts: 8
Re: Pascal and Musical Tones :D
« Reply #22 on: January 12, 2025, 12:32:37 am »
I'm doing this, but its in Borland Pascal. I haven't stepped up to Lazarus as yet although I have it installed. This is a preliminary music unit for a Pac Man clone I'm doing (just for my own entertainment). It uses the old CRT unit for the sound and delay calls. I have only one "dotted" note duration set up as I didn't need any others for the PacMan intro tune. You would need "rests" also, as rest32, rest16, rest8, rest4 etc and also the dotted rests as well set up as duration constants.  The pause procedure used may vary in other runtime environments. YMMV.
Code: Pascal  [Select][+][-]
  1. Unit Music;
  2. Interface
  3. uses crt;
  4.  
  5. Const
  6.   Note32 = 600;
  7.   Note32D= 900;
  8.   Note16 = 1200;
  9.   Note8  = 2400;
  10.   Note4  = 4800;
  11.   Note2  = 9600;
  12.   Note1  = 19200;
  13.  
  14. Type
  15.   NoteType = (A1,AS1,B1,C2,CS2,D2,DS2,E2,F2,FS2,G2,GS2,A2,AS2,B2,
  16.               C3,CS3,D3,DS3,E3,F3,FS3,G3,GS3,A3,AS3,B3,
  17.               C4,CS4,D4,DS4,E4,F4,FS4,G4,GS4,A4);
  18.  
  19.  
  20. var
  21.   Hz: array[A1..A4] of word;
  22.  Note:NoteType;
  23.  
  24.  
  25.  
  26. Procedure InitNotes;
  27. Procedure PlayNote(N:NoteType;Duration:word);
  28. Procedure PacManIntro;
  29.  
  30. Implementation
  31.  
  32. Procedure InitNotes;
  33. begin
  34.     Hz[a1]  := 55;
  35.     Hz[As1] := 58;
  36.     Hz[B1]  := 62;
  37.     Hz[C2]  := 65;
  38.     Hz[CS2] := 69;
  39.     Hz[D2]  := 73;
  40.     Hz[DS2] := 79;
  41.     Hz[E2]  := 82;
  42.     Hz[F2]  := 87;
  43.     Hz[Fs2] := 93;
  44.     Hz[G2]  := 98;
  45.     Hz[GS2] := 104;
  46.     Hz[A2]  := 110;
  47.     Hz[As2] := 117;
  48.     Hz[B2]  := 124;
  49.     Hz[C3]  := 131;
  50.     Hz[Cs3] := 139;
  51.     Hz[D3]  := 147;
  52.     Hz[Ds3] := 156;
  53.     Hz[E3]  := 165;
  54.     Hz[F3]  := 175;
  55.     Hz[Fs3] := 185;
  56.     Hz[G3]  := 196;
  57.     Hz[Gs3] := 208;
  58.     Hz[A3]  := 220;
  59.     Hz[As3] := 233;
  60.     Hz[B3]  := 247;
  61.     Hz[C4]  := 262;
  62.     Hz[Cs4] := 277;
  63.     Hz[D4]  := 294;
  64.     Hz[Ds4] := 311;
  65.     Hz[E4]  := 330;
  66.     Hz[F4]  := 349;
  67.     Hz[Fs4] := 370;
  68.     Hz[G4]  := 392;
  69.     Hz[GS4] := 415;
  70.     Hz[A4] :=  440;
  71.  
  72. end;
  73.  
  74.  
  75.  
  76.  
  77. Procedure Pause;
  78. begin
  79.   delay(10);
  80. end;
  81.  
  82.  
  83.  
  84. Procedure PlayNote(N:NoteType;Duration:word);
  85. begin
  86. Sound(Hz[N]);
  87. delay(Duration);
  88. NoSound;
  89. pause;
  90. end;
  91.  
  92. Procedure PacManIntro;
  93. begin
  94. PlayNote(c2,Note16);
  95. Playnote(c4,Note16);
  96. PlayNote(G3,Note16);
  97. PlayNote(E3,Note16);
  98.  
  99.  
  100. Playnote(g3,Note32);
  101. PlayNote(C4,Note32D);
  102. PlayNote(E3,Note8);
  103.  
  104. PlayNote(Cs2,Note16);
  105. PlayNote(cs4,Note16);
  106. PlayNote(gs3,Note16);
  107.  
  108. PlayNote(F3,Note16);
  109. playnote(gs3,Note32);
  110. playnote(cs4,Note32D);
  111. PlayNote(f3,Note8);
  112.  
  113.  
  114. PlayNote(c2,Note16);
  115. Playnote(c4,Note16);
  116. PlayNote(G3,Note16);
  117. PlayNote(E3,Note16);
  118. Playnote(g3,Note32);
  119. PlayNote(C4,Note32D);
  120. PlayNote(E3,Note8);
  121. PlayNote(Cs2,Note16);
  122. PlayNote(cs4,Note16);
  123. PlayNote(gs3,Note16);
  124. PlayNote(F3,Note16);
  125. playnote(gs3,Note32);
  126. playnote(cs4,Note32D);
  127. PlayNote(f3,Note8);
  128.  
  129. PlayNote(c3,Note16);
  130. PlayNote(c4,Note16);
  131. PlayNote(g3,Note16);
  132. PlayNote(e3,note16);
  133. PlayNote(g3,Note32);
  134. PlayNote(c4,Note32d);
  135. PlayNote(e3,Note8);
  136.  
  137. PlayNote(g2,Note32);
  138. PlayNote(gs2,Note32);
  139. PlayNote(a2,Note16);
  140. PlayNote(gs2,Note32);
  141. PlayNote(a2,Note32);
  142. PlayNote(as2,Note16);
  143. PlayNote(a2,Note32);
  144. PlayNote(as2,Note32);
  145. PlayNote(b2,Note16);
  146. PlayNote(c3,Note8);
  147. end;
  148.  
  149. begin
  150. initnotes;
  151.  
  152. end.
« Last Edit: January 12, 2025, 12:57:33 am by TBMan »

Roland57

  • Sr. Member
  • ****
  • Posts: 487
    • msegui.net
Re: Pascal and Musical Tones :D
« Reply #23 on: January 12, 2025, 04:11:37 am »
My contribution: a program which creates a MIDI file from a MML string.

https://gitlab.com/rchastain/qbasic-music-to-midi-file
My projects are on Gitlab and on Codeberg.

 

TinyPortal © 2005-2018