Sort for fun, sort of fun
The classic bleep-bloop thing in computer science.
(A visualization of Quick Sort)
When started the applications presents an array of numbers. Each integer is represented as a vertical bar to a certain height; larger numbers produces taller heights.
At the beginning, the numbers will be shuffled using a user-chosen hardcoded shuffling method. This will cause the "bars" to be out of order.
Then the sorting algorithm will be started to sort the "bars" into their respective places.
The number of comparisons and writes will be kept tracked of during the sorting process.
- Pre-compiled Binaries
- Building / Compiling from source
- Tweaking
Binaries are the stuff you can directly run on the system (example .exe
on Windows). For some operating systems, the pre-compiled executables are available to download and ready to run.
The applications can be downloaded from the releases page.
If the latest release does not contain a download that can be run on your system, you will have to build from the source code by following the instructions below.
For small college-student style projects like this, it is not worth it to pay companies like Microsoft and Apple annual fees to codesign or notarize the executables. However, the operating systems will by default block these applications from running, and hints to users to make an association of those application with a possible malware.
During the signing process, the companies will check the application through (presumably) an automated process for any suspicious behaviours. Then a certificate will be given to bundle with the application.
While this is a very important protection system, charging for access for these services will hurt small hobbyist projects like this as people ended up thinking that the application is malicious. (I guess it's a fair sacrifice for a greater good in society)
NOTE: Always make sure that you trust the executables before attempting to bypass the gatekeeping systems.
If you downloaded the binaries from this repository on github, rest assured that the function of the binaries is exactly the same function described by the source code. If this project binaries is found somewhere else, make sure you verify the hashes on the releases pages (Steps are there too!) before opening them. Despite the assurance, the only way for an average user to know if the binaries are trustable is to put on faith on the creator. If you would rather compile from the source code you can do so in the next section.
To bypass you need to click on the link on the dialog that says something on the line of "More info" and click "Run Anyways".
To bypass first you need to locate the executable on Finder, then "right click" and select "Open". A dialog box will appear and the option to run the app should be there. It is recommended to close the application afterwards and re-run the application from the Terminal.
During this process a sounds folder and three .txt
files, chord_progression.txt
, settings.txt
and sound_frequencies.txt
, may appear in your Home folder. You can delete those once you've unblocked the executables.
Another way to enable the option to run is to
- Attempt to run the executable first
- Go to Settings and then Security & Privacy
- The text
"<sort_name>" was blocked from use because it is not from an identified developer
should appear. - Click on the lock on the bottom left corner, unlock the setting and then click 'Open Anyway'
- Re-run the executable. The option to run it will appear on the dialog box.
In this section are the instructions to produce the executable binaries from the source code.
To compile this project you will need two items:
- GNU Compiler Collection (GCC)
- PortAudio (This can be omitted if you want to build a mute version)
This project is designed to be compiled using the GNU Compiler Collection (GCC).
For windows, it is recommended to use MinGW64 (a fork of the original MinGW, standing for Minimalist GNU for Windows) to compile the code.
You can download the installers / zip packages via the download link on the MinGW64 website or on their SourceForge.
For your convenience you can add the bin folder of your MinGW64 installation to your Environment Variables (You can search on how to do this)
- Right click on start menu button and click System (or My Computer and click
properties
). - Inside the system dialog find the link that says
Advanced System Settings
and then click on it. - Inside the advanced settings click on the
Environment Variables
button. - Find PATH in your users environment variables (the top white box), edit it by adding the bin folder in your MinGW64 installation.
GCC is included in the Xcode Command Line Tools. You can install Xcode Command Tools by entering the following in the Terminal
xcode-select --install
The command line tools can be uninstalled by deleting the /Library/Developer/CommandLineTools
folder.
Use your package manager to install GCC and make (apt install
on debian (Ubuntu) systems, pacman -S
on Arch systems).
On debian based systems you can install all necessary tools with:
sudo apt install build-essential
PortAudio is a library that is used to play sounds on different Operating Systems. It is required to create a version of the visualizer with sound.
If you want to build a mute version withoud sound, you can skip ahead to building this project. If you want a sound (or musical) version, you have to prepare PortAudio.
For Windows, you will need to install MSYS to build PortAudio. MSYS2 is a bash terminal that allows one to use bash scripts to configure their makefiles. You can download MSYS2 from MSYS2 website and follow the instructions.
After installing, you will need to install either mingw-w64-x86_64-toolchain
(64-bit) or mingw-w64-i686-toolchain
(32-bit) using pacman
Once everything is installed and updated, you can go ahead and build PortAudio, using MSYS2 MINGWXX (NOT MSYS) terminal instead of your typical CMD.
Note: If you already have ALSA or libasound
on your system, you can skip this extra preparation.
For linux distros, PortAudio strongly recommends installing Advanced Linux Sound Architecture (ALSA) project to interface with the sound system on different distros. There are a couple of ways to do this.
You can install ALSA library using the command line package manager provided by the distro. The library name could be libasound-dev
. Example for debian-based systems (including Ubuntu and its derivatives):
sudo apt-get install libasound-dev
You can download alsa-lib
compressed tarball from ALSA's website and extract its contents. Example:
tar zxvf alsa-lib-1.2.7.2.tar.bz2
Using command line, navigate to the extracted folder (using cd
) and enter (for default)
./configure
or (for static linking)
./configure --enable-shared=no --enable-static=yes
Then enter the following command to install:
make install
or
sudo make install
if extra permissions are needed.
For PortAudio, download the source code from PortAudio website or PortAudio GitHub.
Then extract and navigate to the folder of the extracted contents using the bash/zsh command line (for Windows use MSYS2 MINGWXX) (using cd
). Firstly enter
./configure
to configure the build files. The above command produces a dynamic library at the end, which on some systems you will have to manually copy the library file to certain locations (NOTE for Windows the Makefile is configured to automatically do this for you, but for macOS, more on this below). For a static configuration (you may not need to copy the libraries, but you will have to copy part of a script):
./configure --enable-static --disable-shared
([Optional] For Windows, you can build using directsound using ./configure --with-winapi=directx
; further build instructions can be found on this page.)
After the process completes, you can simply type
make
to build PortAudio. The bin
and lib
folders will be created. (Enter make clean
to undo.)
Note: For macOS users, if you encountered errors while building (that stops you from building PortAudio), you can try opening up the PortAudio's Makefile
(not this project's) with a text editor, find -Werror
and delete them. Then save the Makefile
and run make
again.
Note: For linux users, if you encountered errors while building (that stops you from building PortAudio), if you see something along the lines of "recompile with -fPIC" in your error, you can try to re-configure PortAudio to use static linking instead (./configure --enable-static --disable-shared
). You will then ensure that you adjust this project's Makefile
according to these instructions
Lower the volume of your device before trying out the following step.
To test the sound playing property of your built PortAudio, enter bin/paex_sine
or bin/paex_saw
. The command will cause your device to play a sine-wave or a saw-wave sound respectively.
In your PortAudio folder the building process creates a file called libportaudio.2.dylib
inside the hidden folder lib/.libs/
. You will need to copy the file to the /usr/local/lib/
folder.
To automatically copy the library to the correct folder, you can use
sudo make install_mac_pa_dylib
to install, and
sudo make uninstall_mac_pa_dylib
to reverse.
The process has to be seperated because the folder is in a location that is only modifiable by a root user; one would have to run that process in elevated permission mode.
You can also use the command below to manually do so:
sudo cp lib/.libs/libportaudio.2.dylib /usr/local/lib
and the command below to undo it (plus deleting it from the desktop):
sudo mv /usr/local/lib/libportaudio.2.dylib ~/Desktop
Finally, after getting the required tools and libraries, you can now build the visualizer.
Firstly, if you have successfully built PortAudio, you can copy the include
and the lib
folder to the src/pa
folder.
If you want to statically link PortAudio to the final executables (no extra dlls required in the final executables), you have to modify the project Makefile
. If you use dynamic linking (a.k.a. the default setting) you can just jump ahead to Build instructions.
For static linking,
- Open both the project
Makefile
and the PortAudio'sMakefile
with a text editor. - Find the line in the PortAudio's
Makefile
that begins withLIBS =
- Copy everything after the equal sign (Note that the screenshot above is for an Arch Linux system. The code you have to copy will differ for Windows and macOS, but the location will remain the same.)
- In the project's
Makefile
, find the line that begins withW_SOUND_LINKERS =
- Paste the copied code at the end of the line. Ensure that there is a space separating the existing code with your pasted one.
- If there is
-lm
within the pasted code, remove-lm
. - [Windows MSYS2 Only] Find two sections of code that are encased with the folloing comments:
# NOTE For MSYS2 comment out between here...
<a bunch of code here>
# ...and here.
[Windows MSYS2 Only] Comment them out by adding a pound / hash #
sign at the front of every line of code in between the aformentioned comments. (And yes you have to build this project with MSYS2 terminal too!)
You can download (clone) this repository by download the zip and extracting into a folder, or using
git clone https://github.com/snqzspg/cli-sort-visual makeshift_visualizer
if you have Git installed.
To build, you first navigate into the src folder (cd src
) and then you can simply type
make withsound
if you managed to have PortAudio, or
make nosound
to build a mute version. (For Windows with MinGW64, under default settings / not statically linked, replace make
with mingw32-make
or mingw64-make
, or drag the mingw32-make.exe
file into the console).
You can simply type make
to get some information about the installation process, including how to clean up.
This project does not leave any remnants on your system (less the dependencies). You can delete the entire project folder and it's gone.
To run the binaries, navigate up to the parent of the source folder and run the executable labelled with the sort names.
If you type ./<sort_name> help
(or <sort_name>.exe help
, replacing <sort_name>
with any sort), you can get a somewhat comprehensive guide on how to adjust certain parameters. Note that except for the first option, you cannot skip any option when typing in the parameters. (Use default values if you don't want to change certain values, but want to do so for the options afterwards.)
When you first run any sorting executables, it will generate a settings.txt
file. Inside there are more settings that you can tweak to modify the behaviour of the visualizer.