{"id":268,"date":"2016-06-29T05:31:01","date_gmt":"2016-06-29T05:31:01","guid":{"rendered":"http:\/\/www.rangakrish.com\/?p=268"},"modified":"2016-06-29T05:37:19","modified_gmt":"2016-06-29T05:37:19","slug":"pattern-matching-with-optima-lisp-library-part-3","status":"publish","type":"post","link":"https:\/\/www.rangakrish.com\/index.php\/2016\/06\/29\/pattern-matching-with-optima-lisp-library-part-3\/","title":{"rendered":"Pattern Matching with Optima Lisp Library &#8211; Part 3"},"content":{"rendered":"<p>In the previous two posts on this topic, I explained some of the basic pattern matching facilities of <a href=\"https:\/\/github.com\/m2ym\/optima\" target=\"_blank\">Optima<\/a>\u00a0library. There are many\u00a0more advanced features in the library and I will try to discuss them in future posts. In today\u2019s post, I will outline a straightforward application of the library for processing scores in <a href=\"https:\/\/opusmodus.com\" target=\"_blank\">Opusmodus<\/a>.<\/p>\n<p>In the <a href=\"http:\/\/www.rangakrish.com\/index.php\/2016\/04\/27\/reading-and-transforming-a-midi-file\/\" target=\"_blank\">post<\/a>, I showed how we can build a simple framework in Opusmodus to read and transform MIDI files. Let us look at the same problem, but this time using Optima\u2019s pattern matching capabilities.<\/p>\n<p>The function <em><strong>convert-midifile-to-score<\/strong><\/em> takes as argument a MIDI file and returns its <em><strong>score<\/strong><\/em> representation. This representation is a list having the format:<\/p>\n<p style=\"padding-left: 30px;\"><strong>(def-score &lt;score-name&gt; &lt;title-section&gt; &lt;instrument section&gt; \u2026 &lt;instrument section&gt;)<\/strong><\/p>\n<p>The <em><strong>&lt;title-section&gt;<\/strong><\/em> and <em><strong>&lt;instrument section&gt;<\/strong><\/em> are examples of property lists in Optima, so we can use the matching mechanisms available in that context.<\/p>\n<p>For convenience, I have defined a function called <em><strong>process-score<\/strong><\/em> that takes a score object as well as two handler functions as arguments and works on the score.<\/p>\n<p>Take a look at the two handler functions to see how Optima\u2019s <em><strong>match<\/strong><\/em> function is used to de-structure the respective elements for further processing. In the handler for instrument section, for example, you can see how I modify the <em><strong>:volume<\/strong><\/em> parameter.<\/p>\n<figure id=\"attachment_269\" aria-describedby=\"caption-attachment-269\" style=\"width: 700px\" class=\"wp-caption aligncenter\"><a href=\"https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2016\/06\/Optima-Example.png\"><img data-recalc-dims=\"1\" fetchpriority=\"high\" decoding=\"async\" data-attachment-id=\"269\" data-permalink=\"https:\/\/www.rangakrish.com\/index.php\/2016\/06\/29\/pattern-matching-with-optima-lisp-library-part-3\/optima-example\/\" data-orig-file=\"https:\/\/www.rangakrish.com\/wp-content\/uploads\/2016\/06\/Optima-Example.png\" data-orig-size=\"1086,660\" data-comments-opened=\"1\" data-image-meta=\"{&quot;aperture&quot;:&quot;0&quot;,&quot;credit&quot;:&quot;&quot;,&quot;camera&quot;:&quot;&quot;,&quot;caption&quot;:&quot;&quot;,&quot;created_timestamp&quot;:&quot;0&quot;,&quot;copyright&quot;:&quot;&quot;,&quot;focal_length&quot;:&quot;0&quot;,&quot;iso&quot;:&quot;0&quot;,&quot;shutter_speed&quot;:&quot;0&quot;,&quot;title&quot;:&quot;&quot;,&quot;orientation&quot;:&quot;0&quot;}\" data-image-title=\"Optima Example\" data-image-description=\"&lt;p&gt;Optima Example&lt;\/p&gt;\n\" data-image-caption=\"&lt;p&gt;Optima Example&lt;\/p&gt;\n\" data-large-file=\"https:\/\/www.rangakrish.com\/wp-content\/uploads\/2016\/06\/Optima-Example-1024x622.png\" class=\"wp-image-269\" src=\"https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2016\/06\/Optima-Example-1024x622.png?resize=700%2C425\" alt=\"Optima Example\" width=\"700\" height=\"425\" srcset=\"https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2016\/06\/Optima-Example.png?resize=1024%2C622&amp;ssl=1 1024w, https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2016\/06\/Optima-Example.png?resize=300%2C182&amp;ssl=1 300w, https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2016\/06\/Optima-Example.png?resize=768%2C467&amp;ssl=1 768w, https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2016\/06\/Optima-Example.png?w=1086&amp;ssl=1 1086w\" sizes=\"(max-width: 700px) 100vw, 700px\" \/><\/a><figcaption id=\"caption-attachment-269\" class=\"wp-caption-text\">Optima Example<\/figcaption><\/figure>\n<p>Optima opens up many interesting possibilities. Try to experiment.<\/p>\n<p>You can download the code <a href=\"http:\/\/www.rangakrish.com\/downloads\/Optima Example.opmo\" target=\"_blank\">here<\/a>. The example MIDI file is available <a href=\"http:\/\/www.rangakrish.com\/downloads\/raga-bhanumanjari.mid\" target=\"_blank\">here<\/a>.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>In the previous two posts on this topic, I explained some of the basic pattern matching facilities of Optima\u00a0library. There are many\u00a0more advanced features in the library and I will try to discuss them in future posts. In today\u2019s post, I will outline a straightforward application of the library for processing scores in Opusmodus. In [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"advanced_seo_description":"","jetpack_seo_html_title":"","jetpack_seo_noindex":false,"jetpack_post_was_ever_published":false,"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_memberships_contains_paid_content":false,"footnotes":"","jetpack_publicize_message":"","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":false,"jetpack_social_options":{"image_generator_settings":{"template":"highway","default_image_id":0,"font":"","enabled":false},"version":2}},"categories":[18,5,17],"tags":[61,37,62],"class_list":["post-268","post","type-post","status-publish","format-standard","hentry","category-lisp","category-music","category-programming","tag-optima","tag-opusmodus","tag-pattern-matching"],"jetpack_publicize_connections":[],"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"jetpack_shortlink":"https:\/\/wp.me\/p9OLnF-4k","jetpack-related-posts":[{"id":256,"url":"https:\/\/www.rangakrish.com\/index.php\/2016\/06\/09\/pattern-matching-with-optima-lisp-library\/","url_meta":{"origin":268,"position":0},"title":"Pattern Matching with Optima Lisp Library","author":"admin","date":"June 9, 2016","format":false,"excerpt":"In the previous two posts, we looked at external tools and libraries that can be used along with Opusmodus for algorithmic composition. In this post, I want to introduce\u00a0another interesting Lisp library called Optima. Optima is a powerful library for pattern matching. Often, when we talk of pattern matching, the\u2026","rel":"","context":"In &quot;LISP&quot;","block_context":{"text":"LISP","link":"https:\/\/www.rangakrish.com\/index.php\/category\/lisp\/"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":263,"url":"https:\/\/www.rangakrish.com\/index.php\/2016\/06\/17\/pattern-matching-with-optima-lisp-library-part-2\/","url_meta":{"origin":268,"position":1},"title":"Pattern Matching with Optima Lisp Library &#8211; Part 2","author":"admin","date":"June 17, 2016","format":false,"excerpt":"Let us continue where we left off last time. List Patterns If the incoming argument is a list, then we can use two types of list patterns to match the list elements, namely, list and list*. (match '(a b c)\u00a0 ((list 'a 'b X) X)) => c This list pattern\u2026","rel":"","context":"In &quot;LISP&quot;","block_context":{"text":"LISP","link":"https:\/\/www.rangakrish.com\/index.php\/category\/lisp\/"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":218,"url":"https:\/\/www.rangakrish.com\/index.php\/2016\/04\/27\/reading-and-transforming-a-midi-file\/","url_meta":{"origin":268,"position":2},"title":"Reading and Transforming a MIDI File","author":"admin","date":"April 27, 2016","format":false,"excerpt":"Sometimes it can be interesting to take a MIDI file and transform the score it represents. For example, you can change the tempo, alter the instruments, or even modify the pitches and rhythm. To do something like this, it is helpful to build a convenient framework. In today\u2019s post, I\u2026","rel":"","context":"In &quot;LISP&quot;","block_context":{"text":"LISP","link":"https:\/\/www.rangakrish.com\/index.php\/category\/lisp\/"},"img":{"alt_text":"Transform Score","src":"https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2016\/04\/Transform-Score-1.png?resize=350%2C200","width":350,"height":200,"srcset":"https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2016\/04\/Transform-Score-1.png?resize=350%2C200 1x, https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2016\/04\/Transform-Score-1.png?resize=525%2C300 1.5x"},"classes":[]},{"id":169,"url":"https:\/\/www.rangakrish.com\/index.php\/2016\/03\/04\/a-gui-front-end-for-cellular-automata-generator\/","url_meta":{"origin":268,"position":3},"title":"A GUI Front-end for Cellular Automata Generator","author":"admin","date":"March 4, 2016","format":false,"excerpt":"In my last post, I explained how we can use Cellular Automata (CA) in Opusmodus\u00a0to create music. For today\u2019s post, I wanted to build a simple UI to control the parameters used in the CA example. This posed a practical difficulty. Opusmodus does not yet provide a GUI library. Even\u2026","rel":"","context":"In &quot;LISP&quot;","block_context":{"text":"LISP","link":"https:\/\/www.rangakrish.com\/index.php\/category\/lisp\/"},"img":{"alt_text":"Opusmodus GUI Driver","src":"https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2016\/03\/Opusmodus-Driver.png?resize=350%2C200","width":350,"height":200,"srcset":"https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2016\/03\/Opusmodus-Driver.png?resize=350%2C200 1x, https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2016\/03\/Opusmodus-Driver.png?resize=525%2C300 1.5x"},"classes":[]},{"id":2242,"url":"https:\/\/www.rangakrish.com\/index.php\/2020\/12\/20\/jfugue-a-java-library-for-music-synthesis\/","url_meta":{"origin":268,"position":4},"title":"JFugue: A Java Library for Music Synthesis","author":"admin","date":"December 20, 2020","format":false,"excerpt":"JFugue\u00a0is an open-source Java library that can be used for algorithmic music composition. Developed by David Koelle, currently it is in its fifth major version. You can get the library from here. I had downloaded the library some time ago, but could not spend much time since my primary focus\u2026","rel":"","context":"In &quot;LISP&quot;","block_context":{"text":"LISP","link":"https:\/\/www.rangakrish.com\/index.php\/category\/lisp\/"},"img":{"alt_text":"Simple Java Program","src":"https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2020\/12\/java-2-300x142.jpg?resize=350%2C200&ssl=1","width":350,"height":200,"srcset":"https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2020\/12\/java-2-300x142.jpg?resize=350%2C200&ssl=1 1x, https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2020\/12\/java-2-300x142.jpg?resize=525%2C300&ssl=1 1.5x"},"classes":[]},{"id":2224,"url":"https:\/\/www.rangakrish.com\/index.php\/2020\/12\/06\/using-falcon-2-with-opusmodus\/","url_meta":{"origin":268,"position":5},"title":"Using Falcon 2 with Opusmodus","author":"admin","date":"December 6, 2020","format":false,"excerpt":"The recently concluded Black Friday sale by UVI\u00a0was an irresistible temptation for me and I ended up investing in Falcon 2 and a few other instruments. Although I have the latest versions of Ableton Live, Propellerheads Reason, Renoise, and Reaper, I felt Falcon 2 would be a good addition to\u2026","rel":"","context":"In &quot;LISP&quot;","block_context":{"text":"LISP","link":"https:\/\/www.rangakrish.com\/index.php\/category\/lisp\/"},"img":{"alt_text":"Sample Code in Opusmodus","src":"https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2020\/12\/code-248x300.png?resize=350%2C200&ssl=1","width":350,"height":200},"classes":[]}],"_links":{"self":[{"href":"https:\/\/www.rangakrish.com\/index.php\/wp-json\/wp\/v2\/posts\/268","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.rangakrish.com\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.rangakrish.com\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.rangakrish.com\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.rangakrish.com\/index.php\/wp-json\/wp\/v2\/comments?post=268"}],"version-history":[{"count":0,"href":"https:\/\/www.rangakrish.com\/index.php\/wp-json\/wp\/v2\/posts\/268\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.rangakrish.com\/index.php\/wp-json\/wp\/v2\/media?parent=268"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.rangakrish.com\/index.php\/wp-json\/wp\/v2\/categories?post=268"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.rangakrish.com\/index.php\/wp-json\/wp\/v2\/tags?post=268"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}