<!DOCTYPE article PUBLIC "-//NLM//DTD JATS (Z39.96) Journal Archiving and Interchange DTD v1.0 20120330//EN" "JATS-archivearticle1.dtd">
<article xmlns:xlink="http://www.w3.org/1999/xlink">
  <front>
    <journal-meta />
    <article-meta>
      <title-group>
        <article-title>Using answer set programming to detect and compose music in the structure of twelve bar blues</article-title>
      </title-group>
      <contrib-group>
        <contrib contrib-type="author">
          <string-name>Flavio Everardo</string-name>
          <email>flavio.everardo@ftec.mx</email>
          <xref ref-type="aff" rid="aff0">0</xref>
          <xref ref-type="aff" rid="aff1">1</xref>
        </contrib>
        <contrib contrib-type="author">
          <string-name>Gabriel Rodrigo Gil</string-name>
          <xref ref-type="aff" rid="aff0">0</xref>
        </contrib>
        <contrib contrib-type="author">
          <string-name>Oscar B. Pe´rez Alcala´</string-name>
          <xref ref-type="aff" rid="aff0">0</xref>
        </contrib>
        <contrib contrib-type="author">
          <string-name>Gabriela Silva Ballesteros</string-name>
          <xref ref-type="aff" rid="aff0">0</xref>
        </contrib>
        <aff id="aff0">
          <label>0</label>
          <institution>Tecnolo ́ gico de Monterrey, Puebla Campus</institution>
          ,
          <country country="MX">Mexico</country>
        </aff>
        <aff id="aff1">
          <label>1</label>
          <institution>University of Potsdam</institution>
          ,
          <country country="DE">Germany</country>
        </aff>
      </contrib-group>
      <fpage>15</fpage>
      <lpage>25</lpage>
      <abstract>
        <p>The inclusion of Artificial Intelligence (AI) in the music domain has attracted the attention of different research directions towards intelligent solutions for different users, being students or professionals. On the other hand, Answer Set Programming (ASP), has over a decade of music production-related contributions going in directions from composition up to mixing. To continue to empower the user with intelligent solutions under ASP, we focus this paper to combine ASP with the Twelve Bar Blues musical structure. This structure is well known and a very common musical structure used in many popular genres. This work intends to support students during their music formation. To do this, we present the first of a two-stages ASP-based system towards helping the student to train her listening, and at the same time, be aware and understand musical structures. This initial stage receives a (partial) composition, perform an analysis, and returns feedback to the user in the form of error detection and notifications of chords or partial structures out of the Twelve Bar Blues.</p>
      </abstract>
      <kwd-group>
        <kwd>Answer Set Programming</kwd>
        <kwd>ASP</kwd>
        <kwd>Twelve Bar Blues</kwd>
        <kwd>Musical Structures</kwd>
        <kwd>Intelligent Music Production</kwd>
      </kwd-group>
    </article-meta>
  </front>
  <body>
    <sec id="sec-1">
      <title>-</title>
      <p>The inclusion of Artificial Intelligence (AI) in the music domain has attracted the
attention of different research directions to contribute to any stage of music production [19,20],
where intelligent solutions are required to help the user to outperform at any level, being
under their studies or professionally. Regardless of the level where the user is currently
situated (may it be a composer, sound designer, mixing, or mastering engineer to say a
few), there is a fundamental aspect that all share at a professional level, and it is a proper
listening and musical training. Talking concretely about students, they should work to
develop the necessary skills under their formation. This may sound simpler in principle,
however, it takes practice and years to achieve.</p>
      <p>Continuing with intelligent music solutions, Answer Set Programming [1] or ASP for
short, has over a decade of music production-related contributions, either for composition
or even to mixing. ASP and music met back in 2008 when Anton, the first system for
music composition [9] abled to compose melodic, harmonic and rhythmic music in the
style of Palestrina. This system also helps to diagnose errors in human compositions and
serve as a computer-aided composition tool. Since then, composing in ASP derived in
other works. In 2011, an Anton-based system named Armin [10] composed electronic
music, particularly a primer for the trance music genre. This tool can compose basic beats
progressions as a starting point for electronic music producers. In a similar direction, [11]
proposed melodic variations to any given input composition. From 2015, other systems
started to compose with different chords progression. In [12], the authors presented
chasp, an automatic music composition system that creates simple accompanying pieces
of different genres focusing on chord progressions and harmony rules. [13] shows a
computational system that invents novel cadences and chord progressions based on
blending. A year later, [14] presented a song generation system that combines music
and lyrics generation into a single generative phase. The advantage of this approach in
comparison to previous work on automated song composition is in its seamless
combination of language and music. Haspie [15] is a musical harmonization and composition
assistant with features such as preferred harmonization and score completion from 2016.
Currently, the only work outside the composition and arrangement is focus on multitrack
mixing [16] from 2017, proving a concept for multitrack stereo mixing based on best
practices from the literature. This work aims to demonstrate the use of this declarative
approach to achieve a well-balanced mix by compiling a knowledge base with rules
and constraints about what professional music producers and audio engineers suggest
creating a good mix.</p>
      <p>We have described all the published works where music and ASP converge. Still, at
the moment of this writing, we are aware of a complete work, but not yet published. 4
This work takes musical pieces converted to MIDI [21] files and extracts different
patterns. These patterns form an essential block to compose music ideally close to the
input songs. In other words, these common features of similar music are exploited to
create new music, making this system genre-independent, and both the analysis and the
composer are entirely encoded in ASP.</p>
      <p>As we show above, it’s been over a decade and still, the combination of ASP and
music is in its first steps. To continue to empower the user with intelligent solutions
under ASP, we focus this paper to combine ASP with the Twelve Bar Blues musical
structure [17].</p>
      <p>The Twelve Bar Blues is a well-known and very common musical structure used in
many genres for decades including pop, rock, and jazz music to say a few [17]. We refer
to this structure independently of the genre of the blues, however as the name says, they
are related. Musically, this structure is taught during the formation of students and is key
to understanding more complex compositions. This structure, or sometimes referred to
as pattern, consists exactly of 12 bars repeated over time with some hard rules. Some of
these rules involve a specific progression build from chord structures and duration. In
its essence, the progression relies predominantly based on the I, IV, and V chords of a
key [17,18]. making the compositions to sound “recognizable” or “predictable”.
4 This work is an undergraduate thesis by Leo Pinetzki, supervised by the first author of this
paper.</p>
      <p>To help the student to train her listening at the same time be aware and understand
musical structures, this work presents the design and an initial implementation of a
twostages ASP-based system. This initial stage receives a (partial) composition, perform an
analysis, and returns feedback to the user in the form of error detection and notifications
of chords or partial structures out of the Twelve Bar Blues.</p>
      <p>The remainder of the paper is structured as follows. Section 2 introduces the
fundamentals of the Twelve Bar Blues structure and the formalities of ASP. Section 3
presents our system proposal and some ASP encodings of particular subtasks as part of
the analysis, and lastly, Section 4 directs future work and concludes the paper.
2</p>
    </sec>
    <sec id="sec-2">
      <title>Background</title>
      <p>In this section, we formally provide a brief account of what the Twelve Bar Blues
structure is, including progressions, chords, and structure. Then, we introduce in a
highlevel the foundations of Answer Set Programming, including actual syntax from the
state-of-the-art and award-winner ASP system clingo [3].
2.1</p>
      <sec id="sec-2-1">
        <title>The Twelve Bar Blues Structure</title>
        <p>The Twelve Bar Blues is a progression of of chords consisting of four bars of the tonic
(I), two bars of the subdominant (IV), two bars of the tonic (I), a bar of the dominant
seventh (V7), a bar of the subdominant (IV), and two final bars of the tonic (I). Following
this structure it is understandable for a musician to follow the blues on a given key, for
instance “a blues in F” [17].</p>
        <p>This structure follows a “call-and-response” succession in which a lead voice or
instrument states a phrase that is answered by other voices or players. An example of
the most common Twelve Bar song pattern, the leader sings two repeated lines, each of
which is answered by an instrumental phrase, then a rhyming third line that is answered
by a final instrumental passage [17]. This pattern is the most common blues form, but it
does not fully define the style. Other common characteristics of this structure are that
almost invariably, the songs will be in 4/4 time, the chords structure consist of three
basic chords, built on the first, fourth and fifth notes of the scale. In the scale of C, the
chords will be C, F, and G7 [18]. These aspects also impact the lyrics.</p>
        <p>For the pass of the years, this progression has developed certain variations to make
music more interesting. Examples of these involve a subdominant in the second bar, and
the 10th and the 12th bar could be dominant, to mention a few.</p>
        <p>Figure 1 shows an example of a score representing this progression. We can see that
it follows the rules mentioned above, starting with four bars of the tonic. In this case,
this blues is in C, and the rest is calculated accordingly.
2.2</p>
      </sec>
      <sec id="sec-2-2">
        <title>Answer Set Programming</title>
        <p>Answer Set Programming (ASP; [1]), is many things in one. On the one hand, it is
a knowledge-based Artificial Intelligence (AI) oriented to solve high-combinatorial
optimization problems. On the other hand (and more properly), ASP is a rule-based
j
oeoe boeoeoe ™™™ oe oe boeoeoe ™™™
oe
Œ
oe
oe boe
oe oe
w
oe noe
w
j j
oeoeoe oeoeoe ™™™ oeoeoe oeoeoe ™™™
oe boe
oe boe
oe oe
˙ ™
oe oe
˙ ™
j
oeoe boeoeoe ™™™</p>
        <p>oe oe
Œ
oe oe</p>
        <p>Œ
oe oe
oe oe
j
oeoeoe boeoeoe ™™™
oeoej ™™
boe
™
™
j j
oeoeoe oeoeoe ™™™ oeoeoe oeoeoe ™™™</p>
        <p>oe boe
{? oew oe boe oe
oe oe
˙ ™
oe oe
w
&amp; boeoeoe ™™™ oe oe oeoeoe ™™™ oe oe boeoeoe ™™™ oe oe oeoeoe ™™™ oe oe nboeoeoe ™™™ oeoeoej oeoeoe ™™™ oeoeoej oeoeoe ™™™ oeoej boeoeoe ™™™ oe oe
&amp; noeoeoeoe ™™™™ oeoej oeoeoeoe ™™™™ oe oe boeoeoeoe ™™™™ oeoej oeoeoeoe ™™™™ oe oe noeoe ™™ boeoeoej oeoeoe ™™™ oeoeoej oeoeoeoe ™™™™
{? oew oe oe oe oew oe oe oe oew boe oe oe
oe boe
w
formalism for modeling and solving knowledge-intense combinatorial (optimization)
problems as part of the area of knowledge representation and reasoning (KRR) [4]. 5</p>
        <p>Besides the success in both academic and industry in areas like planning, scheduling,
configuration design, biology, logistics, and even music [2], what makes ASP attractive is
its combination of a declarative modeling language with highly effective solving engines.
This allows you to concentrate on specifying—rather than programming the algorithm
for solving—a problem at hand. In resume, just define the problem, the solution path is
found autonomously [7].</p>
        <p>Formally, an ASP program consists of rules of the form:
a1;...;am :- am+1,...,an, not an+1,..., not ao.</p>
        <p>Copyright ©
where each ai is an atom of form p(t1,...,tk) and all ti are terms, composed of
function symbols and variables. If an expression contains no variables, it is said to be
ground and not denotes (default) negation. A rule is called a fact if m = o = 1, normal
if m = 1, and an integrity constraint if m = 0. An answer set (or an interpretation) is a
set of atoms that satisfies the ASP program in question.</p>
        <p>An ASP solver takes information as input and starts propagating what it knows
towards deriving new information. A very basic example program is defined below in
Listing 1.1. It consists of four normal rules and one fact, and we read them from left to
right. 6 7</p>
        <p>For instance, we can read that b becomes true if a is proven to be true. Similarly,
c becomes true if we have evidence that both a and b are true and no proof that f is
5 For a non-technical reading about ASP, we refer to [8]
6 For more information about ASP syntax, particularly for clingo, we refer to [4,5,6]
7 For more details of clasp’s trophies and tracks, see http://potassco.sourceforge.
net/trophy.html.
true. In other words, f must be false. 8 The following two rules (lines 3 and 4) yield no
information because to prove e we need d to be true, and the same happens when trying
to prove d. Lastly, the line 5 has a choice rule in the head. This rule is an example of
the benefit of the non-determinism capabilities of ASP, by choosing between subsets of
atoms, where any subset of its head atoms can be included in a stable model if the body
holds (in this case c). For this example, this unrestricted (unbounded) choice rule selects
between the subsets f g or fgg as part of the answer set.</p>
        <p>If a is given as a fact (or assigned to true as shown in line 6) we have two answer
sets, being fa,b,cg and fa,b,c,gg. Another example could be if both a and f are
given as facts, the only answer set is fa,b,fg. The atom c cannot be inferred because
of the existence of f, thus, the rule in line 5 will be automatically discarded.
1 b :- a.
2 c :- b, a, not f.
3 e :- d.
4 d :- e.
5 {g} :- c.
6 a.</p>
        <sec id="sec-2-2-1">
          <title>Listing 1.1: A basic ASP encoding.</title>
          <p>For an easy grasp to clingo, its syntax and simple examples, please go to:
http://flavioeverardo.com/clingo/ or http://potassco.org/
3</p>
        </sec>
      </sec>
    </sec>
    <sec id="sec-3">
      <title>Towards an ASP System with Twelve Bar Blues Knowledge</title>
      <p>Now that we have the Twelve Bar Blues and ASP foundations, our approach is
represented in Figure 2.</p>
      <sec id="sec-3-1">
        <title>Musical piece</title>
      </sec>
      <sec id="sec-3-2">
        <title>Translate</title>
        <p>MIDI to ASP</p>
      </sec>
      <sec id="sec-3-3">
        <title>Analysis</title>
      </sec>
      <sec id="sec-3-4">
        <title>Composition</title>
      </sec>
      <sec id="sec-3-5">
        <title>Translate</title>
        <p>ASP to MIDI</p>
      </sec>
      <sec id="sec-3-6">
        <title>Feedback</title>
        <p>For this first stage of our system, we cover only the first two blocks from the
proposed architecture, and part of the feedback output. The composition block as well as
the translation back to MIDI are left for future work. Being more specific, our approach
starts with the input of a given (incomplete) composition in MIDI format [21] and
translates it to ASP facts. Then, we proceed to analyze the piece by means of ASP
8 ASP uses logical operators such as AND (^), interpreted by a comma, IF ( ), interpreted by a
colon and hyphen, and negation (as failure) written as not or tilde ( ). In a formal representation,
we would rewrite b :- a. as b a, and c :- b, a,not f. as c b ^ a ^ not f
encodings. Currently, we have implemented three ASP encodings being the detection of
the structure, the tonality detection for calculating the composition mode, and chords
detection. All the encodings have additional rules that contribute to user feedback. That
is, some rules catch errors or suggestions to return to the user.</p>
        <p>The translation to ASP facts (also known as instance in the ASP vocabulary) consist in
capturing the continuity of MIDI events over time. 9 MIDI stands for Musical Instrument
Digital Interface and it is a technical standard that describes a communications protocol,
digital interface, and electrical connectors to communicate a wide variety of electronic
musical instruments, computers, and music production audio devices. MIDI files are very
common in the music production process when handling music. It has been a standard
file to use it in music production software such as Digital Audio Workstations (DAW) or
score writer. 10 The MIDI files represent all the events and timings from a composition,
and each event is consecutively stored within the file. For instance, Listing 1.2 shows an
excerpt of a MIDI file, particularly for the note on and note off events. 11
1 note_on channel=0 note=48 velocity=81 time=0
2 note_on channel=0 note=36 velocity=81 time=0
3 note_off channel=0 note=48 velocity=0 time=960
4 note_on channel=0 note=52 velocity=78 time=0
5 note_off channel=0 note=64 velocity=0 time=589
6 note_off channel=0 note=67 velocity=0 time=0</p>
        <p>Listing 1.2: Example of the events inside a MIDI file</p>
        <p>An example of the output of this process, is shown in Listing 1.3, where these facts
represent the blues shown in Figure 1.</p>
        <p>
          1 note(1,48,81,(
          <xref ref-type="bibr" rid="ref1 ref4">1,4</xref>
          ),(
          <xref ref-type="bibr" rid="ref1">0,1</xref>
          )). note(1,64,81,(
          <xref ref-type="bibr" rid="ref3 ref8">3,8</xref>
          ),(
          <xref ref-type="bibr" rid="ref1">0,1</xref>
          )).
2 note(1,67,81,(
          <xref ref-type="bibr" rid="ref3 ref8">3,8</xref>
          ),(
          <xref ref-type="bibr" rid="ref1">0,1</xref>
          )). note(1,70,81,(
          <xref ref-type="bibr" rid="ref3 ref8">3,8</xref>
          ),(
          <xref ref-type="bibr" rid="ref1">0,1</xref>
          )).
3 note(1,36,81,(
          <xref ref-type="bibr" rid="ref1 ref1">1,1</xref>
          ),(
          <xref ref-type="bibr" rid="ref1">0,1</xref>
          )).
4 note(2,52,78,(
          <xref ref-type="bibr" rid="ref1 ref4">1,4</xref>
          ),(
          <xref ref-type="bibr" rid="ref1 ref4">1,4</xref>
          )).
5 note(3,64,78,(
          <xref ref-type="bibr" rid="ref1 ref8">1,8</xref>
          ),(
          <xref ref-type="bibr" rid="ref1 ref8">1,8</xref>
          )). note(3,67,78,(
          <xref ref-type="bibr" rid="ref1 ref8">1,8</xref>
          ),(
          <xref ref-type="bibr" rid="ref1 ref8">1,8</xref>
          )).
6 note(3,72,78,(
          <xref ref-type="bibr" rid="ref1 ref8">1,8</xref>
          ),(
          <xref ref-type="bibr" rid="ref1 ref8">1,8</xref>
          )).
        </p>
        <p>Listing 1.3: Extract of the ASP facts capturing the first three events from the first
bar shown in Figure 1</p>
        <p>We can read this instance from the atom note of arity 5, where the first parameter
is number of a note on event. The second parameter is the MIDI note number, followed
by the velocity. The last two correspond to the duration of the event, and the distance
from the last played note, respectively. For instance, from lines 1-3 we see the first chord,
being its lowest note the C2. Line 4 is the second event, which lasts one quarter, and it is
represented by its fraction of 1/4.</p>
        <p>Then, as mentioned in Section 2.1, there are several tasks or checks that the system
needs to perform to detect a valid composition in the Twelve Bar Blues structure, and as
9 For this process, we use ASPI, an open translator from MIDI to ASP and back developed by</p>
        <p>
          Leo Pinetzki. Available at https://github.com/pinetzki/ASPI
10 Examples of DAW and music notation software are Ableton Live and MuseScore, respectively
11 The note on event is triggered as soon as a key is pressed, and the note off event sends the
signal to stop the sound as soon as the key is not pressed anymore.
mentioned above (for the scope of this work), the first one is the calculation of the
structure as shown in Listing 1.4. To calculate the structure we prefer to perform calculations
over integer numbers instead of reals or fractions, so we convert each distance from the
atom note by applying the rule:
duration(E,F):- figure(F,DST), note(E,N,V,DR,DST),event(E).
This rule means that for each event E, we take the distance and map it to an integer
number. For example, the atom figure(64,(
          <xref ref-type="bibr" rid="ref1 ref1">1,1</xref>
          ))., tells that a whole note equals
to 64, and figure(16,(
          <xref ref-type="bibr" rid="ref1 ref4">1,4</xref>
          ))., represents a quarter note.12
        </p>
        <p>Now, we proceed to the bars detection encoding (Listing 1.4) which consists of four
lines.</p>
        <p>1 selectedMeasure(1,E,E,F) :- duration(E,F), event(E), E=0.
2 selectedMeasure(M,S,E,R) :- duration(E,F1),
selectedMeasure(M,S,E-1,F2), event(E), E&gt;0, R=(F1+F2),
R&lt;=TL, timeLimit(TL).
3 measure(M,S,F,F-S) :- selectedMeasure(M,S,F,R), timeLimit
(TL), R\TL==0, F!=0.
4 selectedMeasure(M+1,E,E,F1) :- duration(E,F1),
selectedMeasure(M,S,E-1,_), event(E), E=F+1, measure(M,
S,F,F-S).</p>
        <p>Listing 1.4: Encoding to detect the structure of the composition</p>
        <p>
          The system first analyses the piece and perform a set of tasks being the first one,
the calculation of the structure. As described in Section 2.1, the music style in question
is built from 12 bars and repetitions, so the first step is to have this musical structure
identified. The first line handles the first event of the input. In other words, the first event
is directly assigned to the first bar. Then, line 2 captures the rest of the events from the
first bar. The constraint in this rule is that the durations of the events in the bar must not
exceed the limit where in a 4/4 case, is 64. Benefiting from the recursion power from
the ASP system clingo, lines 3 and 4 captures the rest of the input from the deductions
from line 2. The atom measure/4 captures the essential information after this analysis.
For example, the only answer set for this instance has the atoms measure(
          <xref ref-type="bibr" rid="ref1 ref1 ref5 ref6">1,1,6,5</xref>
          )
measure(
          <xref ref-type="bibr" rid="ref13 ref2 ref6 ref7">2,7,13,6</xref>
          ) measure(
          <xref ref-type="bibr" rid="ref14 ref19 ref3 ref5">3,14,19,5</xref>
          ) capturing that the first measure
or bar comprises the events from 1 to 6. The events 7 to 13 belongs to the second bar
and the third one has the events 14 to 19. The last argument is the number of events per
bar. 13
1 selectedMeasure(
          <xref ref-type="bibr" rid="ref1 ref1 ref1 ref16">1,1,1,16</xref>
          ) selectedMeasure(
          <xref ref-type="bibr" rid="ref1 ref1 ref2">1,1,2,24</xref>
          )
2 selectedMeasure(
          <xref ref-type="bibr" rid="ref1 ref1 ref3">1,1,3,32</xref>
          ) selectedMeasure(
          <xref ref-type="bibr" rid="ref1 ref1 ref4">1,1,4,48</xref>
          )
3 selectedMeasure(
          <xref ref-type="bibr" rid="ref1 ref1 ref5">1,1,5,56</xref>
          ) selectedMeasure(
          <xref ref-type="bibr" rid="ref1 ref1 ref6">1,1,6,64</xref>
          )
5 selectedMeasure(
          <xref ref-type="bibr" rid="ref16 ref2 ref7 ref7">2,7,7,16</xref>
          ) selectedMeasure(
          <xref ref-type="bibr" rid="ref2 ref7 ref8">2,7,8,24</xref>
          )
6 selectedMeasure(
          <xref ref-type="bibr" rid="ref2 ref7 ref9">2,7,9,32</xref>
          ) selectedMeasure(
          <xref ref-type="bibr" rid="ref10 ref2 ref7">2,7,10,48</xref>
          )
7 selectedMeasure(
          <xref ref-type="bibr" rid="ref11 ref2 ref7">2,7,11,56</xref>
          ) selectedMeasure(
          <xref ref-type="bibr" rid="ref12 ref2 ref7">2,7,12,60</xref>
          )
8 selectedMeasure(
          <xref ref-type="bibr" rid="ref13 ref2 ref7">2,7,13,64</xref>
          )
10 selectedMeasure(
          <xref ref-type="bibr" rid="ref14 ref14 ref16 ref3">3,14,14,16</xref>
          ) selectedMeasure(
          <xref ref-type="bibr" rid="ref14 ref15 ref3">3,14,15,24</xref>
          )
12 This fraction-integer convention was proposed in [10]
13 The encoding 1.4 is deterministic. This is why there is only one answer set per instance.
Listing 1.5: Answer Set capturing the first three bars from the input composition
shown in Figure 1
        </p>
        <p>Listing 1.5 shows an extract of the answer set where the first three bars from the
input composition are detected. We can see that the first bar is represented in lines 1-3,
followed by the second and third in lines 5-8, and 10-12, respectively. The structure
of the atom selectedMeasure/4 shows the bar number as the first argument. The
second argument is the first MIDI event of that particular bar, followed by the consecutive
enumeration of events. The last argument keeps track of the note duration.</p>
        <p>Our second encoding is shown in Listing 1.6. To illustrate the purpose of our
encoding, we show only the detection of three chord types, however, we have rules to identify
up to 13 chords including, major, minor, augmented, half-diminished, dominant-seventh,
maj7, diminished, and dominant-seventh 9th. This encoding is straightforward where
each rule captures a chord type. For example, the first rule states that a chord in a singular
event E is major if it has a note N and its respective pitches N+4, N+7, and there is
no evidence of N+10 in the same event. This default negation is necessary to avoid the
calculation of the major chord as a subset from a dominant-seventh. With this encoding,
we can identify that the chords shown in the first and third events from Listing 1.3, are
dominant-seventh, and major respectively.</p>
        <p>1 chordType(E,major) :- note(E,1,N), note(E,2,N+4), note(E
,3,N+7), not note(E,4,N+10).
2 chordType(E,minor) :- note(E,1,N), note(E,2,N+3), note(E
,3,N+7), not note(E,4,N+10).
3 chordType(E,augmented) :- note(E,1,N), note(E,2,N+4), note
(E,3,N+8).</p>
        <p>Listing 1.6: Extract of the chords detection encoding</p>
        <p>Another key feature from the analysis is the identification of the composition mode
or tonality. Once we capture the structure and chords, we can easily identify all the notes
used in the composition. For example, consider the notes C#; A; B; G#; E; F # and
D# represented by the atoms note(cs). note(a). note(b). note(gs).
note(e). note(fs). and note(ds)., respectively. Now, we can apply the
encoding in Listing 1.7.</p>
        <p>This encoding starts by counting the number of notes in the input. For our example,
we have seven. Then, we have our knowledge base for all the major and minor scales as
shown in the atoms scale/3 from lines 5-31. To calculate which scale the given notes
belong to, we need to perform some steps. The first step is a choice rule that computes
subsets of notes that matches the number of input notes (line 34). Then, in line 37, we
do not allow guesses without the input notes. Lines 30 and 43, avoid crosses or overlaps
between fundamentals and modes from the knowledge base, and lastly, we get the used
scale in line 46. Running the example with the seven notes listed above, there are two
answer sets fscale(e,major)g and fscale(cs,minor)g. This tell us that the
given composition is in E major or in its relative minor key C# minor.</p>
        <p>One of the main advantages of this encoding is that it also works on incomplete
data. For example, if we remove D# or note(ds). from the input notes, we get four
answer sets fscale(e,major)g, fscale(cs,minor)g, fscale(a,major)g
and fscale(fs,minor)g. In other words, it proposes all the different composition
modes on which a subset of notes belong.</p>
        <p>1 count(C) :- C = { note(N) }.
3 %% Major scales
4 % W, W, H, W, W, W, H
5 scale(c ,major,(c ;d ;e ;f ;g ;a ;b)).
6 scale(cs,major,(cs;ds;f ;fs;gs;as;c)).
7 scale(d ,major,(d ;e ;fs;g ;a ;b ;cs)).
8 scale(ds,major,(ds;f ;g ;gs;as;c ;d)).
9 scale(e ,major,(e ;fs;gs;a ;b ;cs;ds)).
10 scale(f ,major,(f ;g ;a ;as;c ;d ;e)).
11 scale(fs,major,(fs;gs;as;b ;cs;ds;f)).
12 scale(g ,major,(g ;a ;b ;c ;d ;e ;fs)).
13 scale(gs,major,(gs;as;c ;cs;ds;f ;g)).
14 scale(a ,major,(a ;b ;cs;d ;e ;fs;gs)).
15 scale(as,major,(as;c ;d ;ds;f ;g ;a)).
16 scale(b ,major,(b ;cs;ds;e ;fs;gs;as)).
18 %% Minor scales
19 % W, H, W, W, H, W, W
20 scale(a ,minor,(a ;b ;c ;d ;e ;f ;g)).
21 scale(as,minor,(as;c ;cs;ds;f ;fs;gs)).
22 scale(b ,minor,(b ;cs;d ;e ;fs;g ;a)).
23 scale(c ,minor,(c ;d ;ds;f ;g ;gs;as)).
24 scale(cs,minor,(cs;ds;e ;fs;gs;a ;b)).
25 scale(d ,minor,(d ;e ;f ;g ;a ;as;c)).
26 scale(ds,minor,(ds;f ;fs;gs;as;b ;cs)).
27 scale(e ,minor,(e ;fs;g ;a ;b ;c ;d)).
28 scale(f ,minor,(f ;g ;gs;as;c ;cs;ds)).
29 scale(fs,minor,(fs;gs;a ;b ;cs;d ;e)).
30 scale(g ,minor,(g ;a ;as;c ;d ;ds;f)).
31 scale(gs,minor,(gs;as;b ;cs;ds;e ;fs)).
33 %% Calculate all subsets of size C for each scale
34 C { guess(F,M,N) : scale(F,M,N) } C :- count(C).
36 %% Discard guesses not having the given notes
37 :- not guess(_,_,N), note(N).
39 %% Not allowed to have two guesses with different
fundamentals and different notes
40 :- guess(F1,_,N1), guess(F2,_,N2), F1 != F2, N1 != N2.
42 %% Discard the subsets pointing to opposite modes
43 :- scale(F,M1), scale(F,M2), M1!=M2.
45 %% Get the scale
scale(F,M) :- guess(F,M,_).</p>
      </sec>
      <sec id="sec-3-7">
        <title>Listing 1.7: Mode detection encoding</title>
        <p>Our last encoding is related to the previous ones, as it characterizes rules to give
feedback to the user (Listing 1.8). The encoding catches three types of errors, such as
structure, chord, and scale errors. The structure error determines if the given composition
does not have 12 bars. The chord error states that a chord is not recognizable for some
event E, and the scale error is derived when there is not a scale that comprises all the
input notes.
#const err_str = "Structure error. There are no 12 bars.".
error(err_str) :- not measure(12,_,_,_).
#const err_chord = "Not a valid chord at this event".
error(err_chord,E) :- not chordType(E,_), event(E).
#const err_scl = "Not a valid scale".
error(err_scl) :- not guess(F,M,_), scale(F,M).</p>
        <p>Listing 1.8: Examples of feedback messages to the user
4</p>
      </sec>
    </sec>
    <sec id="sec-4">
      <title>Discussion</title>
      <p>In this work we present an initial phase to build an ASP system capable of reasoning
about basic features of the Twelve Bar Blues structure. This system has the intention
to support the students to train their audition and composition skills at the same time
they comprehend musical structures by benefiting from feedback. Currently, we have
ASP encodings to detect the structure of a given score in MIDI format, detect chords for
progression, and the scaled used in the composition. We have several challenges before
we complete this work. For the musical efforts, we aim to detect variations of the mode
from the blues structure, as mentioned in Section 2.1.</p>
      <p>In the case of ASP, one of the main aspects to consider is proper performance
evaluation over different size compositions to test our encodings. Another upcoming work
is to build the composer that can suggest a score completion or alternative compositions
associated with the input. To do so, we are studying the different systems of music
composition with ASP. Lastly, as the work progresses, we need to enrich our
ASPsystem with more feedback options.</p>
    </sec>
  </body>
  <back>
    <ref-list>
      <ref id="ref1">
        <mixed-citation>
          1.
          <string-name>
            <surname>Lifschitz</surname>
          </string-name>
          , V.:
          <article-title>Answer set planning</article-title>
          .
          <source>In International Conference on Logic Programming and Nonmonotonic Reasoning</source>
          . pp.
          <fpage>373</fpage>
          -
          <lpage>374</lpage>
          . Springer, Berlin, Heidelberg (
          <year>1999</year>
          ).
        </mixed-citation>
      </ref>
      <ref id="ref2">
        <mixed-citation>
          2.
          <string-name>
            <surname>Erdem</surname>
            ,
            <given-names>E.</given-names>
          </string-name>
          ,
          <string-name>
            <surname>Gelfond</surname>
            ,
            <given-names>M.</given-names>
          </string-name>
          , and
          <string-name>
            <surname>Leone</surname>
          </string-name>
          , N.:
          <article-title>Applications of ASP</article-title>
          .
          <source>In AI Magazine</source>
          .
          <volume>37</volume>
          (
          <issue>3</issue>
          ) (
          <year>2016</year>
          ).
        </mixed-citation>
      </ref>
      <ref id="ref3">
        <mixed-citation>
          3.
          <string-name>
            <surname>Gebser</surname>
            <given-names>M.</given-names>
          </string-name>
          ,
          <string-name>
            <surname>Kaminski</surname>
            <given-names>R.</given-names>
          </string-name>
          , Kaufmann B., and
          <string-name>
            <surname>Schaub</surname>
            <given-names>T.</given-names>
          </string-name>
          :
          <article-title>Clingo = ASP + control: Preliminary report</article-title>
          .
          <source>In Technical Communications of the Thirtieth International Conference on Logic Programming (ICLP'14)</source>
          , (
          <year>2014</year>
          ). Available at http://arxiv.org/abs/1405.3694.
        </mixed-citation>
      </ref>
      <ref id="ref4">
        <mixed-citation>
          4.
          <string-name>
            <surname>Gebser</surname>
            ,
            <given-names>M.</given-names>
          </string-name>
          ,
          <string-name>
            <surname>Kaminski</surname>
            ,
            <given-names>R.</given-names>
          </string-name>
          , Kaufmann,
          <string-name>
            <given-names>B.</given-names>
            , and
            <surname>Schaub</surname>
          </string-name>
          , T.:
          <article-title>Answer set solving in practice</article-title>
          .
          <source>Synthesis lectures on artificial intelligence and machine learning</source>
          ,
          <volume>6</volume>
          (
          <issue>3</issue>
          ),
          <fpage>1</fpage>
          -
          <lpage>238</lpage>
          (
          <year>2012</year>
          ).
        </mixed-citation>
      </ref>
      <ref id="ref5">
        <mixed-citation>
          5.
          <string-name>
            <surname>Gebser</surname>
            ,
            <given-names>M.</given-names>
          </string-name>
          ,
          <string-name>
            <surname>Kaminski</surname>
            ,
            <given-names>R.</given-names>
          </string-name>
          , Kaufmann,
          <string-name>
            <given-names>B.</given-names>
            ,
            <surname>Lindauer</surname>
          </string-name>
          ,
          <string-name>
            <given-names>M.</given-names>
            ,
            <surname>Ostrowski</surname>
          </string-name>
          ,
          <string-name>
            <given-names>M.</given-names>
            ,
            <surname>Romero</surname>
          </string-name>
          ,
          <string-name>
            <given-names>J.</given-names>
            ,
            <surname>Schaub</surname>
          </string-name>
          ,
          <string-name>
            <given-names>T.</given-names>
            ,
            <surname>Thiele</surname>
          </string-name>
          ,
          <string-name>
            <given-names>S.</given-names>
            , and
            <surname>Wanko</surname>
          </string-name>
          ,
          <string-name>
            <surname>P.</surname>
          </string-name>
          : Potassco User Guide.
          <volume>2</volume>
          <fpage>edn</fpage>
          . (
          <year>2019</year>
          ), http://potassco.org
        </mixed-citation>
      </ref>
      <ref id="ref6">
        <mixed-citation>6. Answer Set Programming at Wikipedia: https://en.wikipedia.org/wiki/ Answer_set_programming</mixed-citation>
      </ref>
      <ref id="ref7">
        <mixed-citation>
          7.
          <string-name>
            <surname>Schaub</surname>
          </string-name>
          , T. Interview at University of Potsdam: The Universal Problem Solver - “
          <source>AI</source>
          Made in Potsdam”
          <article-title>on its Triumphal Procession around the World Short URL: shorturl</article-title>
          .at/ kvLTX
        </mixed-citation>
      </ref>
      <ref id="ref8">
        <mixed-citation>
          8.
          <string-name>
            <surname>Schaub</surname>
            ,
            <given-names>T.</given-names>
          </string-name>
          , and
          <string-name>
            <surname>Woltran</surname>
            ,
            <given-names>S.</given-names>
          </string-name>
          :
          <article-title>Answer set programming unleashed!</article-title>
          .
          <source>KI-Ku¨nstliche Intelligenz</source>
          ,
          <volume>32</volume>
          (
          <issue>2-3</issue>
          ),
          <fpage>105</fpage>
          -
          <lpage>108</lpage>
          , (
          <year>2018</year>
          ).
        </mixed-citation>
      </ref>
      <ref id="ref9">
        <mixed-citation>
          9.
          <string-name>
            <surname>Boenn</surname>
            ,
            <given-names>G.</given-names>
          </string-name>
          ,
          <string-name>
            <surname>Brain</surname>
            ,
            <given-names>M.</given-names>
          </string-name>
          ,
          <string-name>
            <surname>De Vos</surname>
            ,
            <given-names>M.</given-names>
          </string-name>
          , and
          <string-name>
            <surname>Ffitch</surname>
          </string-name>
          , J.:
          <article-title>Automatic Composition of Melodic and Harmonic Music by Answer Set Programming</article-title>
          .
          <source>In International Conference on Logic Programming</source>
          ,
          <source>ICLP08. Lecture Notes in Computer Science</source>
          , vol.
          <volume>4386</volume>
          . Springer Berlin / Heidelberg, 160-
          <fpage>174</fpage>
          (
          <year>2008</year>
          ).
        </mixed-citation>
      </ref>
      <ref id="ref10">
        <mixed-citation>
          10.
          <string-name>
            <surname>Everardo</surname>
            ,
            <given-names>F.</given-names>
          </string-name>
          , and
          <string-name>
            <surname>Aguilera</surname>
            ,
            <given-names>A.</given-names>
          </string-name>
          :
          <article-title>Armin: Automatic trance music composition using answer set programming</article-title>
          .
          <source>In Fundamenta Informaticae</source>
          , vol.
          <volume>113</volume>
          , no.
          <issue>1</issue>
          , pp.
          <fpage>79</fpage>
          -
          <lpage>96</lpage>
          , (
          <year>2011</year>
          ).
        </mixed-citation>
      </ref>
      <ref id="ref11">
        <mixed-citation>
          11.
          <string-name>
            <surname>Everardo</surname>
            ,
            <given-names>F.</given-names>
          </string-name>
          :
          <article-title>A logical approach for melodic variations</article-title>
          .
          <source>In Latin American New Methods of Reasoning</source>
          , pp.
          <fpage>141</fpage>
          -
          <lpage>150</lpage>
          (
          <year>2011</year>
          ).
        </mixed-citation>
      </ref>
      <ref id="ref12">
        <mixed-citation>
          12.
          <string-name>
            <surname>Opolka</surname>
            ,
            <given-names>S.</given-names>
          </string-name>
          ,
          <string-name>
            <surname>Obermeier</surname>
            ,
            <given-names>P.</given-names>
          </string-name>
          , and
          <string-name>
            <surname>Schaub</surname>
            ,
            <given-names>T.</given-names>
          </string-name>
          :
          <article-title>Automatic genre-dependent composition using answer set programming</article-title>
          .
          <source>Proceedings of the 21st International Symposium on Electronic Art</source>
          . Vancouver, Canada (
          <year>2015</year>
          ).
        </mixed-citation>
      </ref>
      <ref id="ref13">
        <mixed-citation>
          13.
          <string-name>
            <surname>Eppe</surname>
            ,
            <given-names>M.</given-names>
          </string-name>
          ,
          <string-name>
            <surname>Confalonieri</surname>
            ,
            <given-names>R.</given-names>
          </string-name>
          ,
          <string-name>
            <surname>Maclean</surname>
            ,
            <given-names>E.</given-names>
          </string-name>
          ,
          <string-name>
            <surname>Kaliakatsos</surname>
            ,
            <given-names>M.</given-names>
          </string-name>
          ,
          <string-name>
            <surname>Cambouropoulos</surname>
            ,
            <given-names>E.</given-names>
          </string-name>
          ,
          <string-name>
            <surname>Schorlemmer</surname>
            ,
            <given-names>M.</given-names>
          </string-name>
          ,
          <string-name>
            <surname>Codescu</surname>
            ,
            <given-names>M.</given-names>
          </string-name>
          , and Ku¨hnberger, K. U.:
          <article-title>Computational invention of cadences and chord progressions by conceptual chord-blending</article-title>
          .
          <source>In Twenty-Fourth International Joint Conference on Artificial Intelligence</source>
          (
          <year>2015</year>
          ).
        </mixed-citation>
      </ref>
      <ref id="ref14">
        <mixed-citation>
          14.
          <string-name>
            <surname>Toivanen</surname>
            .,
            <given-names>J. M.</given-names>
          </string-name>
          :
          <article-title>Methods and models in linguistic and musical computational creativity (</article-title>
          <year>2016</year>
          ).
        </mixed-citation>
      </ref>
      <ref id="ref15">
        <mixed-citation>
          15.
          <string-name>
            <surname>Cabalar</surname>
            ,
            <given-names>P.</given-names>
          </string-name>
          , and Mart´ın, R.:
          <article-title>Haspie-A Musical Harmonisation Tool Based on ASP</article-title>
          .
          <source>In EPIA Conference on Artificial Intelligence</source>
          (pp.
          <fpage>637</fpage>
          -
          <lpage>642</lpage>
          ). Springer, Cham (
          <year>2017</year>
          ).
        </mixed-citation>
      </ref>
      <ref id="ref16">
        <mixed-citation>
          16.
          <string-name>
            <surname>Everardo</surname>
            ,
            <given-names>F.</given-names>
          </string-name>
          :
          <article-title>Towards an Automated Multitrack Mixing Tool using Answer Set Programming</article-title>
          . In Lokki T., Pa¨tynen J., and Va¨lima¨ki V. (eds.)
          <source>Proceedings of the 14th Sound and Music Computing Conference</source>
          . pp.
          <fpage>422</fpage>
          -
          <lpage>428</lpage>
          (
          <year>2017</year>
          ).
        </mixed-citation>
      </ref>
      <ref id="ref17">
        <mixed-citation>
          17.
          <string-name>
            <surname>Wald</surname>
            ,
            <given-names>E.</given-names>
          </string-name>
          :
          <article-title>The blues: a very short introduction</article-title>
          . Oxford University Press (
          <year>2010</year>
          ).
        </mixed-citation>
      </ref>
      <ref id="ref18">
        <mixed-citation>
          18.
          <string-name>
            <surname>Weissman</surname>
            ,
            <given-names>D.</given-names>
          </string-name>
          :
          <article-title>Blues: the basics</article-title>
          .
          <source>Routledge</source>
          (
          <year>2004</year>
          ).
        </mixed-citation>
      </ref>
      <ref id="ref19">
        <mixed-citation>
          19.
          <string-name>
            <surname>De Man</surname>
            ,
            <given-names>B.</given-names>
          </string-name>
          ,
          <string-name>
            <surname>Stables</surname>
            ,
            <given-names>R.</given-names>
          </string-name>
          , &amp;
          <string-name>
            <surname>Reiss</surname>
            ,
            <given-names>J. D.</given-names>
          </string-name>
          :
          <article-title>Intelligent Music Production</article-title>
          .
          <source>Routledge</source>
          (
          <year>2019</year>
          ).
        </mixed-citation>
      </ref>
      <ref id="ref20">
        <mixed-citation>
          20.
          <string-name>
            <surname>Everardo</surname>
            ,
            <given-names>F.</given-names>
          </string-name>
          :
          <article-title>Over a Decade of Producing Music with Answer Set Programming. A Survey. Submitted to the Workshop on Trends and Applications of Answer Set Programming (TAASP</article-title>
          <year>2020</year>
          ).
        </mixed-citation>
      </ref>
      <ref id="ref21">
        <mixed-citation>
          21.
          <string-name>
            <surname>Moog</surname>
            ,
            <given-names>R. A.</given-names>
          </string-name>
          :
          <article-title>Midi: Musical instrument digital interface</article-title>
          .
          <source>Journal of the Audio Engineering Society</source>
          ,
          <volume>34</volume>
          (
          <issue>5</issue>
          ),
          <fpage>394</fpage>
          -
          <lpage>404</lpage>
          , (
          <year>1986</year>
          ).
        </mixed-citation>
      </ref>
    </ref-list>
  </back>
</article>