Visualising Konnakol Compositions - GSoC '22 Update 2
Tags: haskell, music, tidalcycles, visualization
Published: 2022-07-26 06:05:18

It has been 6 weeks since the official coding period started for the Google Summer of Code '22. The last three weeks have been interesting as well as hectic . There were multiple new concepts to learn, hundreds of lines of code to go through and understand, and an attempt to get to that one elusive final plan which will decide how my next 6 weeks shall go.

## Visualizing Compositions

After fixing a few minor bugs in the generations of Korvais and Mohras, the next step was developing methods to visualize compositions. This meant going through the Diagrams package, and discovering methods to visualize compositions in a grid-like structure. 

The first idea that I had in visualizing Korvais was that I would represent the phrases in a color, and the gaps in another. Each row would represent a new rhythmic cycle. As I developed functions for the same, I realized that it would be better if I had a gradient as well instead of just a single color. Phrases would have a decreasing gradient, where the rate of decline would depend on the length of the phrase. The same would hold true for gaps, albeit with an increasing gradient. Another great idea, which was recommended by my mentor, Alex McLean, was to have a header which would help one understand where the beats would land. 

An example generation for a normal numerical pattern is as follows: 

![Pattern1](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/uoyc673dnp7zhtd24k9h.png)

Another such visualization for a Korvai is as follows:

![Pattern2](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/0sswwytlsprsbyojz3eo.png)

These were custom compositions that were provided as a list of phrases and gaps. The next step was in getting the system to compose as well as visualize compositions in one go. One such Korvai that the system has composed is given below:

![Sample Korvai](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/cd66jm8jxr8alljozhhw.png)

Visualizing Mohras proved to be a completely different ballgame. Unlike Korvais, gaps were not a characteristic feature here. Hence, I decided to use the fundamental structure, i.e., the separation of a Mohra into components as the deciding feature.

One such Mohra generated by the system has been given below:

![Sample Mohra](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/4wrsvmk6jwnqwxdgqeup.png)

The final step that I wanted to figure out was the representation of compositions which have changing time signatures. This required generating diagrams where the length of the individual components would vary.

The earlier composition visualized in two different time signatures is given below:

![Changing Times-1](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/3037rf2u0c6f3ycf0hc9.png)

Another numerical pattern which used 4 different time signatures is given below:

![More Changing Times](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/0jqw6oqn6n5jcarj5mtr.png)

At this point, I was interested to find out how it would be to overlap cycles over themselves to see what the resultant color would be. I accomplished this using circular wedges. Phrases would add a positive value to the resultant color, while gaps would add a negative value. Such a visualization is given below:

![Circle](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/npu0e270oxcuap167ixr.png)

Once I was done with the diagrams part, all that was left was to create a package and upload it on hackage. The package has been linked below:

{% embed https://hackage.haskell.org/package/konnakol-0.1.0.0#readme %}

## Listening to Konnakol

After visualizing Konnakol compositions, the next thing on the list was to listen to Konnakol compositions. Fortunately, we came across an amazing collection of Mridangam samples by Arthur Carabott, who recorded these with the help of Mridangam artist Harishankar V Menon. They were kind enough to grant us permission to use the audio samples in our project.

To use the samples along with compositions generated by the system, I had to define methods which would convert these compositions into mini notation, as well as a suitable value by which the compositions needed to be slowed down so they would attain optimal tempo. Once I did this, it was only a matter of installing the _konnakol_ package, importing it in tidal and live coding Konnakol!!

The audio generation code has been written in such a way that anyone with a basic understanding of Konnakol would be able to generate a Mohra or a Korvai with just a single line of code. For example, to generate a Mohra one would only have to type in 

```
d1 $ (tidalM Khanda rupaka Khanda (mkStdGen 112)) 
```

To make it sound better, one case use other available functions and audio samples in Tidal Cycles. One such example is given below:

```
do
  resetCycles
  d1 $ jux (fast 2) $ (tidalK Chaturasra thriputa Chaturasra (mkStdGen 112232)) # gain 1.3

d2 $ sound "bd sd ~ sd" # gain 1

d5 $ sound "arpy(<3 5>, 8)" # gain 1.1
```

Sample audios generated can be found in the code repository, linked at the end of the document.

## What Next?

The main aim for the second half of the project is to develop a system within TidalCycles, which would be able to handle sequences. I would also be working on  

To view the code developed, as well as a detailed description of Konnakol, visit:

{% embed https://github.com/tidalcycles/konnakol-gsoc %}

### Audio Samples

Mridangam samples (c) Arthur Carabott, distributed under a CC-BY-SA license https://creativecommons.org/licenses/by-sa/4.0/, performed by Harishankar V Menon.