Konnakol Compositions using Haskell - GSoC '22 Update 1
Tags: haskell, tidalcycles, music
Published: 2022-07-02 06:47:48

Since it has been 3 weeks since the Official Coding Period started at the Google Summer of Code '22, I thought it would be ideal to write about my experience so far in developing a system to formalize Konnakol compositions using Haskell. I shall talk about the features that I have developed so far, the major roadblocks I faced, and the way ahead. 

## The Pre-Coding Phase

The Community bonding period began as soon as the contributors for GSoC '22 were announced. I was introduced to the TidalCycles community, and the GSoC '22 Haskell community. I met my mentor Alex McLean, and we chalked out the project timeline in greater detail. 

Although I had a basic understanding of Haskell, I thought this period would be ideal to learn the language in greater detail. Since I had only learned Object Oriented Programming Languages till then, it took some time to get used to Haskell. I referred to "Learn You a Haskell For Greater Good" by Miran Lipovača, and as my understanding of Haskell improved, I started getting a detailed idea of how my project can be structured.

During this period, I also went through research papers on Konnakol in an attempt to find a formal document on the rules followed. On failing to do so, I approached Vidwan Sri H.S. Sudhindra, an Indian Classical Percussionist, and he was kind enough to help me identify the rules that would be necessary for implementing my project.

The next step was to go through the documentation of TidalCycles as well as Diagrams (a Haskell package which I would be using soon to visualize compositions). I also went through a series of videos on TidalCyles by my mentor. This helped provide a clearer image on how I should structure my datatypes, so that future integration with TidalCycles would be easier.

As I ended my community bonding period, I had gone through tons of documentation, research papers and videos, and was itching to start coding.

## The Coding Period

Since I finished my objectives for the community bonding period early, I thought I would get a head start for the coding period. I felt I had done enough groundwork to start building up.

I started by defining datatypes for components of Konnakol such as Thala, Jati, Gati and the syllables to be used. I then defined the Suladi Sapta Thala System, and a method to show thalas using the conventional symbols. Next was development of the necessary methods and datatypes for the user to enter a composition which has varying gatis, and methods for displaying them in the proper jathi notation. This is immensely helpful for beginners in Konnakol as they could enter a composition and see exactly where each of the syllables land. A simple example of the same has been provided with along with the function call used. Here KalaCh is used to change the Gati (or the time signature) of the composition. The phrases are entered along with the speed at which they are to be recited.

![Getting the representation of a simple set of phrases using GetRepresentation](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/pqkjv1si5qexiyeynioi.png)
 
The next step was to develop methods to generate a Mohra for a given thala, and to facilitate this, methods were created to generate phrases for a particular length. This method uses a random value to generate a phrase for the given length. This method, along with methods to partition the given thala into sections, are used to generate a mohra. Then the getRepresentation method is called on the same, and the user gets a custom Mohra along with its representation.

Another composition which can be composed it the Korvai. Since the structure of the Korvai is more complex than that of the Mohra, set comprehensions in Haskell were used to create subsets of the overall count which follow some pattern (such as arithmetic or geometric progressions). A similar procedure to Mohra generation was followed to obtain representation.

Users can now just run main, enter the jati, the thala and the gati, followed by a 1 if they desire to generate a Mohra and any other digit otherwise. Sample generations are provided below. Here a "-" denoted a gap in statements. "^" are used to separate beats, "|", "O" and "U" are used to denote the components of a thala, and "||" the beginning of the next cycle of the thala.

![Sample Korvai](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/68ijxbx9ogojc5mi1p64.png)
![Sample Mohra](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/7xqv87nckvqqvghsye2t.png)
  
Another method was developed (along with the necessary datatypes), with which the user can enter his composition as numbers and see whether the composition is valid with respect to its total count. This method was further developed to check whether custom Korvais are valid.

## What Next ? 

The next step in the project is to develop methods to visualize custom compositions. A grid like structure will be used here, and this will help understand the structure of certain compositions. Post this, the system developed will be integrated with TidalCycles.

To view the code developed for the project, visit 

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