![]() |
Forum Index : Microcontroller and PC projects : Mr. Polysynth
Author | Message | ||||
TweakerRay![]() Senior Member ![]() Joined: 01/08/2020 Location: GermanyPosts: 138 |
Hi ! I made somehow a musical keyboard and named it Mr. Polysynth - you can play up to 4 notes. Change octaves and so on... It's not perfect but I think I made progress in programming ;-) Mr-Polysynth.zip And the Monoversion: Mr-Monosynth.zip (And maybe you missed my Drumsynth Programm) DrummachineV10.zip Cheers ;-) Edited 2020-09-28 07:22 by TweakerRay http://tweakerray.bandcamp.com |
||||
thwill![]() Guru ![]() Joined: 16/09/2019 Location: United KingdomPosts: 4311 |
Hey "TweakerRay", I know our last interaction was unproductive, but I was wondering if we could put that aside and ask you: 1) Do you think Mr-Polysynth might be suitable for inclusion on the "Welcome Tape" licensed under the MIT License - I also wondered whether it might be possible to display the musical stave at the same time reusing some of Bill's work: http://www.thebackshed.com/forum/ViewTopic.php?TID=12836 2) Do you have some pre-existing work that could be repurposed as the title screen soundtrack for PeteCotton's Defender clone which with some additional filing off of the serial numbers I'm proposing to include on the "Welcome Tape". Best wishes, Tom Edited 2020-10-01 21:31 by thwill MMBasic for Linux, Game*Mite, CMM2 Welcome Tape, Creaky old text adventures |
||||
TweakerRay![]() Senior Member ![]() Joined: 01/08/2020 Location: GermanyPosts: 138 |
Oh... Hi I just see this now @thwill - Yes you can use Mr. Polysynth in the welcometape...I mean it's such a small community and if someone will make money with my programm then I am screwed... But I hope at least the people will see the original credits which are in that programm. I am also working on another musical little helper programm... you could also use that too if you like Its a programm that plays the scale of a selected not and could randomly generate chord progressions from the selected scale... It's not finished yet but maybe you are interested in that too... I sure have a music which could be used for the defender clone music... Check this out: https://www.youtube.com/watch?v=c2rWBMTu-4Q you could use this song as mp3 as long as I am credited as the musician with correct credits... :-) If that is for interest let me give you the correct credits and then you can use this track... Edited 2020-10-04 04:26 by TweakerRay http://tweakerray.bandcamp.com |
||||
thwill![]() Guru ![]() Joined: 16/09/2019 Location: United KingdomPosts: 4311 |
Thanks TweakerRay, That's really generous of you and I will definitely check out all your programs for inclusion on the Welcome Tape. That music is amazing, and very appropriate, assuming the game's author @PeteCotton is also fine with it I would love to try and use it. Can you post or PM me the credits and a link to obtain the track. Best wishes, Tom MMBasic for Linux, Game*Mite, CMM2 Welcome Tape, Creaky old text adventures |
||||
TweakerRay![]() Senior Member ![]() Joined: 01/08/2020 Location: GermanyPosts: 138 |
Hi ! The Credits would be "Spaceflight" from the Album "Distance" available for FREE download at http://tweakerray.bandcamp.com composed by TweakerRay (www.tweakerray.de) you can simply download the Album at my bandcamp page https://tweakerray.bandcamp.com/album/tweakerray-distance-pay-as-much-as-you-like it is a pay as much as you like album. But you can also just put in 0 and get all songs for free... or you can just click the FREE single: https://tweakerray.bandcamp.com/track/space-flight-free-download http://tweakerray.bandcamp.com |
||||
thwill![]() Guru ![]() Joined: 16/09/2019 Location: United KingdomPosts: 4311 |
Hi TR, I've been "messing about" with Mr. Polysynth and kicking it into shape for inclusion on the "Welcome Tape" and I have some questions ... or possibly I have identified some bugs. 1. Does sine wave output s1,s2,s3,s4 = 2 (instead of the default 1) actually work for you ? ... it doesn't produce a tone for me. 2. In the key testing loop there is a variable named "switch" which is set when the keypress "tpress$" corresponds to one of the musical note keys ... however this is then tested outside the loop so when multiple keys are pressed simultaneously the test only passe if the last key depressed is a musical note key, i.e. for i=1 to keydown(0) ' start of the key testing loop ... switch=0 for x=28 to 44 if tpress$=ta$(x) then switch=1 next x next i ' end of the key testing loop ' The value of switch here is the one for the last key tested if switch=0 goto Screenstart 3. You maintain a variable "keys" which it looks like is supposed to be the number of musical note keys that are depressed, however when you then play the notes at the end of the main loop ... If s1=1 and keys>0 then Play Sound 1,B,Q,freq1(tnr(1)+okt1)+tune1,volume if s1=2 and Keys>0 then play Sound 1,B,S,freq1(tnr(1)+okt1)+tune1,volume If s2=1 and keys>1 then Play Sound 2,B,Q,freq2(tnr(2)+okt2)+tune2,volume if s2=2 and keys>1 then play Sound 2,B,S,freq2(tnr(2)+okt2)+tune2,volume If s3=1 and keys>2 then Play Sound 3,B,Q,freq3(tnr(3)+okt3)+tune3,volume if s3=2 and keys>2 then play Sound 3,B,S,freq3(tnr(3)+okt3)+tune3,volume If s4=1 and keys>3 then Play Sound 4,B,Q,freq4(tnr(4)+okt4)+tune4,volume if s4=2 and keys>3 then play Sound 4,B,S,freq4(tnr(4)+okt4)+tune4,volume ... I think this will produce the wrong result if for example 3 keys were depressed of which only keys 1 and 3 were musical, I think it will play tones 1 and 2 when it should play tones 1 and 3 shouldn't it? Best wishes, Tom MMBasic for Linux, Game*Mite, CMM2 Welcome Tape, Creaky old text adventures |
||||
TweakerRay![]() Senior Member ![]() Joined: 01/08/2020 Location: GermanyPosts: 138 |
When I tested last It worked for me... one did Square wave sound and the other did Sine when I rememeber that correctly. I will check that programm again ;-) hmmm with that switching thing. I am not sure. Have to check. Will report as soon as I have checked that. Cheers TweakerRay http://tweakerray.bandcamp.com |
||||
thwill![]() Guru ![]() Joined: 16/09/2019 Location: United KingdomPosts: 4311 |
Hey TR, In the interests of getting the next version of the "Welcome Tape" out I have taken the liberty of "messing about" with Mr. Polysynth. I hope you don't mind, I feel quite bad about the number of changes I've made: ' Mr. Polysynth ' Code by "TweakerRay" ' Messed about with for the CMM2 Welcome Tape by "thwill" Option Explicit On Option Base 1 '#Include "../../common/welcome.inc" cls color rgb(40,255,20) ?" Hi ! This is my small Polysynth V1" ?" " ?" You can play the synth with your keyboard:" ?" Just imagine the Keys from Q-P as White Keys and the numberkeys above as Black keys of a Piano" ?" " ?" 2 3 5 6 7 9 0 <----- Black Keys" ?" " ?" Q W E R T Z U I O P <----- White Keys" ?" " ?" The Synth can play up to 4 Notes simultaneously. All sounds come from both Speakers." ?" " ?" You can change the okaves on the 4 Notes independently:" ?" " ?" F1 / F2 Oktave up / down on Note 1" ?" F3 / F4 Oktave up / down on Note 2" ?" F5 / F6 Oktave up / down on Note 3" ?" F7 / F8 Oktave up / down on Note 4" ?" F9 / F10 Oktave up / down on ALL 4 Notes" ?" F11 Reset All oktaves to Zero " ?" F12 Reset Tuning to Zero " ?" " ?" Change the Sound on the Channel:" ?" " ?" A / S / D / F - Sound change + on Channel 1 / 2 / 3 / 4 (Square or Sine)" ?" Y / X / C / V - Sound change - on Channel 1 / 2 / 3 / 4 (Square or Sine)" ?" " ?" Detune Channels with:" ?" " ?" G / H / J / K - Detune + on Note 1 / 2 / 3 / 4" ?" B / N / M / , - Detune - on Note 1 / 2 / 3 / 4" ?" " ?" " ?" Press [Esc] to Quit" do while inkey$<>"" : loop do while inkey$="" : loop cls dim freq(88) dim i dim k(4) dim keys dim layout$ = mm.info$(option usbkeyboard) dim notes dim okt(4) dim s(4) ' 1=square, 2=sine, 3=noise dim tnr(4) = (28,28,28,28) ' For if okt would be pressed before a key we set the key to C2 dim tune(4) dim volume=12 ' Volume 1-25 freq(01)=27.5000 : freq(11)=48.9995 : freq(21)=87.3071 : freq(31)=155.563 freq(02)=29.1353 : freq(12)=51.9130 : freq(22)=92.4986 : freq(32)=164.814 freq(03)=30.8677 : freq(13)=55.0000 : freq(23)=97.9989 : freq(33)=174.614 freq(04)=32.7032 : freq(14)=58.2705 : freq(24)=103.826 : freq(34)=184.997 freq(05)=34.6479 : freq(15)=61.7354 : freq(25)=110.000 : freq(35)=195.998 freq(06)=36.7081 : freq(16)=65.4064 : freq(26)=116.541 : freq(36)=207.652 freq(07)=38.8909 : freq(17)=69.2957 : freq(27)=123.471 : freq(37)=220.000 freq(08)=41.2035 : freq(18)=73.4162 : freq(28)=130.813 : freq(38)=233.082 freq(09)=43.6536 : freq(19)=77.7817 : freq(29)=138.591 : freq(39)=246.942 freq(10)=46.2493 : freq(20)=82.4069 : freq(30)=146.832 : freq(40)=261.626 freq(41)=277.183 : freq(51)=493.883 : freq(61)=880.000 : freq(71)=1567.98 freq(42)=293.665 : freq(52)=523.251 : freq(62)=932.328 : freq(72)=1661.22 freq(43)=311.127 : freq(53)=554.365 : freq(63)=987.767 : freq(73)=1760.00 freq(44)=329.628 : freq(54)=587.330 : freq(64)=1046.50 : freq(74)=1864.66 freq(45)=349.228 : freq(55)=622.254 : freq(65)=1108.73 : freq(75)=1975.53 freq(46)=369.994 : freq(56)=659.255 : freq(66)=1174.66 : freq(76)=2093.00 freq(47)=391.995 : freq(57)=698.456 : freq(67)=1244.51 : freq(77)=2217.46 freq(48)=415.305 : freq(58)=739.989 : freq(68)=1318.51 : freq(78)=2349.32 freq(49)=440.000 : freq(59)=783.991 : freq(69)=1396.91 : freq(79)=2489.02 freq(50)=466.164 : freq(60)=830.609 : freq(70)=1479.98 : freq(80)=2637.02 freq(81)=2793.83 freq(82)=2959.96 freq(83)=3135.96 freq(84)=3322.44 freq(85)=3520.00 freq(86)=3729.31 freq(87)=3951.07 freq(88)=4186.01 dim ta$(88) ta$(28)="q" ta$(29)="2" ta$(30)="w" ta$(31)="3" ta$(32)="e" ta$(33)="r" ta$(34)="5" ta$(35)="t" ta$(36)="6" if layout$="DE" then ta$(37)="z" else ta$(37)="y" ta$(38)="7" ta$(39)="u" ta$(40)="i" ta$(41)="9" ta$(42)="o" ta$(43)="0" ta$(44)="p" do keys=keydown(0) notes=keys for i = 1 To 4 : k(i) = keydown(i) : next i if keys=0 then play stop for i=1 to keys handle_keypress(i) next i apply_restrictions() update_display() play_notes() loop sub handle_keypress(i) local j, kk$ kk$=chr$(k(i)) if kk$=chr$(27) then end ' we.end_program() ' Check for keys corresponding to musical notes for j=28 to 44 if kk$=ta$(j) then tnr(i)=j : Exit Sub next j select case kk$ ' Channel Oktave up and down case chr$(145) : okt(1)=okt(1)-12 ' F1 case chr$(146) : okt(1)=okt(1)+12 ' F2 case chr$(147) : okt(2)=okt(2)-12 ' F3 case chr$(148) : okt(2)=okt(2)+12 ' F4 case chr$(149) : okt(3)=okt(3)-12 ' F5 case chr$(150) : okt(3)=okt(3)+12 ' F6 case chr$(151) : okt(4)=okt(4)-12 ' F7 case chr$(152) : okt(4)=okt(4)+12 ' F8 ' All four Channels Oktave up and down case chr$(153) : for j=1 to 4 : okt(j)=okt(j)-12 : next j ' F9 case chr$(154) : for j=1 to 4 : okt(j)=okt(j)+12 : next j ' F10 ' Reset Tuning + Reset Oktaves case chr$(155) : for j=1 to 4 : okt(j)=0 : next j ' F11 case chr$(156) : for j=1 to 4 : tune(j)=0 : next j ' F12 ' Sound changes 1-4 case "a" : s(1)=s(1)+1 ' If "y" or "z" corresponds to a musical note key then this sub will already have exited. case "y", "z" : s(1)=s(1)-1 case "s" : s(2)=s(2)+1 case "x" : s(2)=s(2)-1 case "d" : s(3)=s(3)+1 case "c" : s(3)=s(3)-1 case "f" : s(4)=s(4)+1 case "v" : s(4)=s(4)-1 ' Detune channels 1-4 case "g" : tune(1)=tune(1)+0.1 case "b" : tune(1)=tune(1)-0.1 case "h" : tune(2)=tune(2)+0.1 case "n" : tune(2)=tune(2)-0.1 case "j" : tune(3)=tune(3)+0.1 case "m" : tune(3)=tune(3)-0.1 case "k" : tune(4)=tune(4)+0.1 case "," : tune(4)=tune(4)-0.1 case else : exit sub end select notes=notes-1 pause 100 end sub sub apply_restrictions() local i ' Restrict ocatave values. for i = 1 to 4 if okt(i) > 48 then okt(i) = 48 if okt(i) < -24 then okt(i) = -24 next i ' Restrict sound values. ' Only sounds 1 & 2 are useful, 3 and 4 are noise. for i = 1 to 4 if s(i) <= 1 then s(i)=1 else s(i)=2 next i ' Restrict frequency. for i = 1 to 4 if okt(i)=48 and tnr(i) > 40 then tnr(i)=40 next i end sub sub update_display() local i font 2 color rgb(rnd()*255,rnd()*255,rnd()*255) print @(12,1) "* * * * * * * * * Mr. Polysynth by TweakerRay * * * * * * * * *" color rgb(0,255,0) print @(10,100) "Keydown :" format$(keys, "%4g") format$(notes, "%4g") print @(10,120) "Frequency :"; for i = 1 To 4 : print format$(freq(tnr(i)), "%10g"); : next i : print print @(10,160) "Tuning :"; for i = 1 to 4 : print format$(tune(i), "%4g"); : next i : print print @(10,180) "Oktave :"; for i = 1 to 4 : print format$(okt(i), "%4g"); : next i : print print @(10,200) "Key num :"; for i = 1 to 4 : print format$(tnr(i)+okt(i), "%4g"); : next i : print print @(10,220) "Sound :"; for i = 1 To 4 : print format$(s(i), "%4g"); : next i : print print @(10,240) "Layout : ";layout$ font 1 print @(10,320) "More music at http://tweakerray.bandcamp,com" print @(10,340) "And follow at http://www.youtube.com/tweakerray" end sub sub play_notes() local i for i=1 to notes if s(i)=1 then play sound 1,B,Q,freq(tnr(i)+okt(i))+tune(i),volume elseif s(i)=2 then play sound 1,B,S,freq(tnr(i)+okt(i))+tune(i),volume endif next i end sub Whilst I've been careful, as a non-musician I can't be certain that I haven't broken something. I think there are two issues that were present in the original and which are duplicated in my code: 1) I'm not sure that keydown() correctly picks up multiple key presses. This may just be an issue with cheap USB keyboards, or it may be a general issue. I have raised the problem in the firmware RC1 thread. 2) If multiple note are being played simultaneously or the user is mixing non-note keys with note keys then I'm not convinced that the correct notes are being played on the correct channels. Best regards, Tom MMBasic for Linux, Game*Mite, CMM2 Welcome Tape, Creaky old text adventures |
||||
elk1984![]() Senior Member ![]() Joined: 11/07/2020 Location: United KingdomPosts: 228 |
From what I've read in the manual it should do, although I don't think it would work over TeraTerm or similar. |
||||
TweakerRay![]() Senior Member ![]() Joined: 01/08/2020 Location: GermanyPosts: 138 |
Hi Tom, I‘m already on that problem. I think i need to do a whole different approach for that. The soundchange you asked before works fine at my end the sine is just more silent than the square... i guess i have to do a more different keypress check... since i only check one key... this does work if you play one after another but not 4 keys at once... so i will try to work on this and solve the problem. Since I am still learning the code which i started has its flaws... i know but it works to the most extend - i will change the key checking... http://tweakerray.bandcamp.com |
||||
thwill![]() Guru ![]() Joined: 16/09/2019 Location: United KingdomPosts: 4311 |
No, keydown() doesn't work over serial, only for an attached USB keyboard. I agree with your reading of the manual, I am strongly suspecting this may be to do with having a cheap USB keyboard, perhaps certain key combinations cannot be uniquely decoded or something ... I am not a hardware guy, but recall reading about something similar with some keyboard in the past. Regards, Tom MMBasic for Linux, Game*Mite, CMM2 Welcome Tape, Creaky old text adventures |
||||
thwill![]() Guru ![]() Joined: 16/09/2019 Location: United KingdomPosts: 4311 |
I think i need to do a whole different approach for that. The soundchange you asked before works fine at my end the sine is just more silent than the square... i guess i have to do a more different keypress check... since i only check one key... this does work if you play one after another but not 4 keys at once... so i will try to work on this and solve the problem. Since I am still learning the code which i started has its flaws... i know but it works to the most extend - i will change the key checking... Thanks TR, I agree regarding sine vs. square, when I changed the octave I could hear the sine wave sound. I suggest you check-out my version of the code, because provided I haven't borked anything I think you will find it a lot "cleaner", YMMV. Tom MMBasic for Linux, Game*Mite, CMM2 Welcome Tape, Creaky old text adventures |
||||
thwill![]() Guru ![]() Joined: 16/09/2019 Location: United KingdomPosts: 4311 |
... at the moment I'm inclined to think it is "good enough" and as soon as I've finished smoke testing the rest of the "Welcome Tape" I will release it as is. We can always add a Mr. Polysynth v2 in a later release. Do you agree? Tom MMBasic for Linux, Game*Mite, CMM2 Welcome Tape, Creaky old text adventures |
||||
TweakerRay![]() Senior Member ![]() Joined: 01/08/2020 Location: GermanyPosts: 138 |
Hi ! I tried my best to change the keyaccess... I also have the thought that the usb keymoard sometimes work and sometimes have problems with the keycheck... This is what I came up with... I think this is okay to demonstrate the "soundabilitys" of the cmm2 with the internal sounds... Mr-Polysynth.zip So Feel free to check this version... maybe it solved the problem ? Edited 2020-10-21 00:24 by TweakerRay http://tweakerray.bandcamp.com |
||||
thwill![]() Guru ![]() Joined: 16/09/2019 Location: United KingdomPosts: 4311 |
Hi TR, I"m in a quandary as I can't see how your changes improve the situation and it takes me back to square one in terms of tidying the code up for the Welcome Tape. Could you please look at the version I included above, if you are not happy then perhaps I would be best to leave Mr. Polysynth out this time? In my musical ignorance I suspect what is required is a more advanced algorithm so that if A ... G are notes then: - Press key for A then start playing A on channel 1. - Continue to hold A and press B then play A on 1 and B on 2. - Continue to hold A and B and press C then play A on 1, B on 2 and C on 3. - Continue to hold A and C but release B then play A on 1, nothing on 2 and C on 3. - Continue to hold C but release A then play nothing on 1, nothing on 2 and C on 3. Is that the desired behaviour? Tom Edited 2020-10-21 01:18 by thwill MMBasic for Linux, Game*Mite, CMM2 Welcome Tape, Creaky old text adventures |
||||
TweakerRay![]() Senior Member ![]() Joined: 01/08/2020 Location: GermanyPosts: 138 |
Hi Tom, your code reseted my CMM2 while playing... it also did not play 2 notes at the same time... Then it crashed with "Error System fault - possible caus Incorrect use of POKE faulty CSUB Reserved words used as varibles Firmware problem" So I think if you want to use my last version I posted - I am fine with that. I don't think your other version works better... If you don't want to use it then leave it out... its your welcome tape... What I tried to archiev was that you can press more than 1 key and each of the keys will have a note... Problem with keydown is that if you lose one key of 4 pressed ones the last key switches over and such strange things... so the keypresses are not first press gets first note and so on... if you change your fingers on the keyboard the keys also switch... It's rather hard to describe...It works on my end here with a few hickups but better than the crashed version.... And I am sure some other people could programm it much better... I am a musician... not a professional coder - I do this for fun. So it is what it is... a not perfect but useable programm... otherwise just use Mr. Monosynth... with just one key ? Much easier... but more boring. Mr-Monosynth.zip Edited 2020-10-21 01:39 by TweakerRay http://tweakerray.bandcamp.com |
||||
thwill![]() Guru ![]() Joined: 16/09/2019 Location: United KingdomPosts: 4311 |
It's probably this: http://xahlee.info/kbd/keyboard_n-key_rollover_key_ghosting.html. So that will place a hardware limit on the multi-key capabilities of Mr. Polysynth. Tom MMBasic for Linux, Game*Mite, CMM2 Welcome Tape, Creaky old text adventures |
||||
TweakerRay![]() Senior Member ![]() Joined: 01/08/2020 Location: GermanyPosts: 138 |
WT.... actual... wow... I did not know about ghosting keyboards... I just tested this on my office keyboard and if I press (left shift)+(right shift) + X - I get no key... If i do that on a different key it works... just not on the X... Thats crazy... Yeah I guess that is a very big limitation here in the hardware then ? Maybe use my Game Heartattack instead ? ;-) It also supports the WII Classic now... and has basic soundeffects and a mp3 playback at start ;-) http://tweakerray.bandcamp.com |
||||
thwill![]() Guru ![]() Joined: 16/09/2019 Location: United KingdomPosts: 4311 |
Hi TR, Not sure why it crashes, I will have to test again, and I think I know how to fix some of the strange stuff you reported with multi-key presses, though hardware limitations may mean it can never be reliable for simultaneous key presses on some keyboards. Yes, and your programming is much better than my music. It's just an unfortunate case here where my professional standards and the fact that I have ultimate responsibility for the "Welcome Tape" means I feel obliged to "tidy up" some of the code that is included - this always had the potential to be awkward when I started this project and is no reflection on you. Thank you for your continuing contributions, Tom MMBasic for Linux, Game*Mite, CMM2 Welcome Tape, Creaky old text adventures |
||||
thwill![]() Guru ![]() Joined: 16/09/2019 Location: United KingdomPosts: 4311 |
It looks that way, I may just add a warning about use of more than two simultaneous keys. People with more expensive USB keyboards may be able to use more. Thanks for the offer, and maybe in a later version of the "Welcome Tape", but I don't want to start juggling new content so late in the release cycle for v0.5. I'm going to try and fix up "Mr. Polysynth" as well as I can (I want to include it because I feel it fills an important niche in the Welcome Tape's inventory) and then call it done ... once I've smoke tested everything with Peter's latest experimental firmware. Best regards, Tom Edited 2020-10-21 02:33 by thwill MMBasic for Linux, Game*Mite, CMM2 Welcome Tape, Creaky old text adventures |
||||
![]() |
![]() |
The Back Shed's forum code is written, and hosted, in Australia. | © JAQ Software 2025 |