is there a way to use the C++ layer of makecode or whatever its called? i feel like some extensions have cpp files in them, though i dont remember any. Im tryin to play partials, a type of sound, but playInstructions() or something else is making some of it sound like junk (likely makecode struggling to play hundreds at once).
did a bit of researching, @richard is it true that c++ only compiles for the hardware and not the website? can this be changed, assuming itās possible? There is also an app for makecode I believe, does that support c++ on computers? if I remember right (probably donāt), makecode can also use visual studio code (I have visual studio, would that work), does that work?
c++ is never compiled to run in the simulator, regardless of platform. all versions of makecode (browser, vs code, offline app) work exactly the same in this regard.
your project can contain c++, it just wonāt work in the simulator.
the way we āsimulateā c++ code in the browser is by having completely separate browser implementations. in most of our built-in extensions, this code can be found inside a /sim/ directory, for example here is where all the code for dealing with images/drawing in arcade lives: https://github.com/microsoft/pxt-common-packages/tree/master/libs/screen/sim
these browser implementations donāt go through the makecode compiler. as a result, they also have full access to the browser APIs. if we let extensions or projects run code that had access to browser APIs, it would be possible to, say, make a share link where it runs some simulator code that hacks your computer or starts mining bitcoin or something. for that reason, no extension or project is allowed to contribute code that runs in the simulator. itās purely a security concern.
i always recommend that you try to keep all code in TS if possible
i guess i should also mention that we do accept pull requests! if you want to add new native c++ code along with browser implementations, we would be delighted!
for example, here are some example prs from our very own forum user @kwx adding new sound waveforms
Is there a way to upload files to makecode? I have an SDIF file that is 247KB, my output file is 145KB. I could probably compress the output file into a binary file (using every UTF-8 character (0x00 - 0xFF)) and parse it with makecode, but from what Iām aware, makecode canāt do anything like that. the output file is a number[] that can be copy pasted into makecode, utf-8 encoding cannot. the utf-8 encoded file would also be around 72KB which is a huge difference, so I would appreciate it if it was added! Also, when i was trying to comporess a huge number array (base 10) into my own character set (base 85), makecode crashed so bad, that instead of just crashing the simulator it closed every single chrome window (i was running it on chrome) on my comeputer, even windows from other accounts. Please answer this:
-
yes
-
no
-
need more info
-
no thoughts on it
-
other (respond with your own post)
I guess I could probably expand on what I said earlier: I am taking a wav file, running it through SPEAR to generate an sdif file (an SDIF file contains āpartialsā of a sound file, if you use SPEAR it is all the lines you see after uploading). I then use some c++ code to parse it (NOT what I want to add to makecode) and generate a number[]. Makecode can play it, using a loop and music.playInstructions(). this is the sound project (2 seconds of megalovania):
it is very glitchy, and sometimes makecode will crash because itās playing so many partials. I was thinking that if I could access the c++ it would be possible to somehow create my own music.playInstructions(), and it would sound better. reducing the partials would make it sound worse, so Iām not doing that
@VoxelMaster64 Iāve moved these posts into their own thread so that they donāt get lost in the just chatting milieu.
no, there is no way to upload data files into makecode but there is a much more efficient way to include them in your program. see this post where i gave a sample script for converting number arrays into hex buffers:
as for what you want to do, iād say that if you wanted to edit the C++ then you might be better off adding straight up sample playback rather than doing some waveform trickery to better approximate the sound. then you could write a script to convert your sample to PCM data and have the C++ code play that back.
we do have sample playback implemented in some of our other targets (micro:bit) it just hasnāt made its way to arcade yet.
I was totally not expecting this to become another post.
If I fork the github repo(s) that make makecode run, if I get them into visual studio and have node.js, can I run makecode on vs and edit the code? Im a little confused, but would I then show you the changes I made to add sound playing?
I would like a little help if thatās possible, and if so, what github repo(s) I need to fork
alright, fair warning: makecode is a very complex project and i would not recommend doing this unless you have some experience working with microcontrollers and webapps. with that out of the way, i donāt think iāll be able to walk you through the entire process, but in general here is what i recommend:
- Install VS Code
- Install node.js (or node version manager)
- Install git
open up a terminal (or command prompt on windows) and run these commands to set up your dev environment (note, this will probably take a while)
npm install -g pxt
mkdir makecode
cd makecode
git clone https://github.com/microsoft/pxt.git
cd pxt
npm install
npx gulp
cd ..
git clone https://github.com/microsoft/pxt-common-packages.git
cd pxt-common-packages
npm install
npm link ../pxt
cd ..
git clone https://github.com/microsoft/pxt-arcade.git
cd pxt-arcade
npm install
npm link ../pxt ../pxt-common-packages
once youāve done that, you can run makecode arcade locally by running pxt serve from within pxt-arcade.
which versions of git, node.js, and vs code should I use?
for node, use something recent (iām on v24) and always use the latest for git and vs code
if you use multiple versions of node, i highly recommend installing node version manager (or node version manager for windows if on windows)
When i run pxt serve, it opens makecode! This a great start to me. When i edit any code and want to test it, do i run this:
cd C:\Users\Dan\Desktop\miles\Cpp\makecode\pxt
npm install
npm run build
cd ..\pxt-arcade
npm install
pxt serve
Also, what is something i should change to make sure its working? For example, it could be changing the
Share Project
header in the share popup to
This project will be shared when you press the Blue āShare Projectā Button at the bottom-right corner
you donāt need to run npm install every time you make a change, and donāt run npm install in pxt-arcade because it will break the link you setup before. if you already did that, make sure to run this command from within pxt-arcade again:
npm link ../pxt ../pxt-common-packages
you are primarily going to be making changes in pxt-common-packages, so if you want to make sure your changes are working it might be easiest to just add a console.log to one of the files in pxt-common-packages/libs/mixer (which is where the audio code lives).
@richard when I do finish, how should I send the audio function(s)?
you should open pull requests on the repositories in github