Intermediate step 2 a (hopefully) magical journey

Midi-Muster schreiben

Das war der nächste Zwischenschritt auf meinem Weg zu einer automatischen Jamsession-Begleitmusik-Erstellung (halt für M3T-Trainings onda zur Kompositons-Fantasieanregung):

 

Code - 4 Takte-XML-Datei nach Arrayfüllung ausgeben

#!/usr/bin/perl

# midi-pattern-writer_1.1.pl

use strict;
use warnings;
use DBI;
use ZugangsDaten_postgresql qw($DB_USER $DB_PASSWD);
use Encode qw(is_utf8 decode encode);
use Storable qw(store retrieve);


# Variablen

my $timestamp = localtime(time);


# Program

## Timestamp für Dateinamen anpassen

$timestamp =~ s/ /_/g;
$timestamp =~ s/:/_/g;


## Ein Array pro Takt

my @chord_1 = ("C", "3", "E", "4", "G", "4", "B", "4");
my @chord_2 = ("A", "2", "E", "4", "G", "4", "C", "5");
my @chord_3 = ("D", "3", "F", "4", "A", "4", "C", "5");
my @chord_4 = ("D", "3", "F", "4", "A", "4", "B", "4");



my $midi_muster = '<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE score-partwise PUBLIC "-//Recordare//DTD MusicXML 3.0 Partwise//EN" "http://www.musicxml.org/dtds/partwise.dtd">
<score-partwise>
  <work>
    <work-title>Midi-Muster</work-title>
    </work>
  <identification>
    <creator type="composer">Zarko Maroli</creator>
    <creator type="lyricist">Hembel</creator>
    <encoding>
      <software>MuseScore 2.0.2</software>
      <encoding-date>2019-02-16</encoding-date>
      <supports element="accidental" type="yes"/>
      <supports element="beam" type="yes"/>
      <supports element="print" attribute="new-page" type="yes" value="yes"/>
      <supports element="print" attribute="new-system" type="yes" value="yes"/>
      <supports element="stem" type="yes"/>
      </encoding>
    </identification>
  <defaults>
    <scaling>
      <millimeters>7.05556</millimeters>
      <tenths>40</tenths>
      </scaling>
    <page-layout>
      <page-height>1683.36</page-height>
      <page-width>1190.88</page-width>
      <page-margins type="even">
        <left-margin>56.6929</left-margin>
        <right-margin>56.6929</right-margin>
        <top-margin>56.6929</top-margin>
        <bottom-margin>113.386</bottom-margin>
        </page-margins>
      <page-margins type="odd">
        <left-margin>56.6929</left-margin>
        <right-margin>56.6929</right-margin>
        <top-margin>56.6929</top-margin>
        <bottom-margin>113.386</bottom-margin>
        </page-margins>
      </page-layout>
    <word-font font-family="FreeSerif" font-size="10"/>
    <lyric-font font-family="FreeSerif" font-size="11"/>
    </defaults>
  <credit page="1">
    <credit-words default-x="595.44" default-y="1626.67" justify="center" valign="top" font-size="24">Midi-Muster</credit-words>
    </credit>
  <credit page="1">
    <credit-words default-x="1134.19" default-y="1526.67" justify="right" valign="bottom" font-size="12">Zarko Maroli</credit-words>
    </credit>
  <credit page="1">
    <credit-words default-x="56.6929" default-y="1526.67" justify="left" valign="bottom" font-size="12">Hembel</credit-words>
    </credit>
  <part-list>
    <score-part id="P1">
      <part-name>Piano</part-name>
      <part-abbreviation>Pno.</part-abbreviation>
      <score-instrument id="P1-I1">
        <instrument-name>Piano</instrument-name>
        </score-instrument>
      <midi-device id="P1-I1" port="1"></midi-device>
      <midi-instrument id="P1-I1">
        <midi-channel>1</midi-channel>
        <midi-program>1</midi-program>
        <volume>78.7402</volume>
        <pan>0</pan>
        </midi-instrument>
      </score-part>
    </part-list>
  <part id="P1">
    <measure number="1" width="299.86">
      <print>
        <system-layout>
          <system-margins>
            <left-margin>21.00</left-margin>
            <right-margin>0.00</right-margin>
            </system-margins>
          <top-system-distance>170.00</top-system-distance>
          </system-layout>
        <staff-layout number="2">
          <staff-distance>65.00</staff-distance>
          </staff-layout>
        </print>
      <attributes>
        <divisions>1</divisions>
        <key>
          <fifths>0</fifths>
          </key>
        <time>
          <beats>4</beats>
          <beat-type>4</beat-type>
          </time>
        <staves>2</staves>
        <clef number="1">
          <sign>G</sign>
          <line>2</line>
          </clef>
        <clef number="2">
          <sign>F</sign>
          <line>4</line>
          </clef>
        </attributes>
      <note default-x="80.38" default-y="-40.00">
        <pitch>
          <step>'.$chord_1[2].'</step>
          <octave>'.$chord_1[3].'</octave>
          </pitch>
        <duration>2</duration>
        <voice>1</voice>
        <type>half</type>
        <stem>up</stem>
        <staff>1</staff>
        </note>
      <note default-x="80.38" default-y="-30.00">
        <chord/>
        <pitch>
          <step>'.$chord_1[4].'</step>
          <octave>'.$chord_1[5].'</octave>
          </pitch>
        <duration>2</duration>
        <voice>1</voice>
        <type>half</type>
        <stem>up</stem>
        <staff>1</staff>
        </note>
      <note default-x="80.38" default-y="-20.00">
        <chord/>
        <pitch>
          <step>'.$chord_1[6].'</step>
          <octave>'.$chord_1[7].'</octave>
          </pitch>
        <duration>2</duration>
        <voice>1</voice>
        <type>half</type>
        <stem>up</stem>
        <staff>1</staff>
        </note>
      <note default-x="189.13" default-y="-40.00">
        <pitch>
          <step>'.$chord_1[2].'</step>
          <octave>'.$chord_1[3].'</octave>
          </pitch>
        <duration>2</duration>
        <voice>1</voice>
        <type>half</type>
        <stem>up</stem>
        <staff>1</staff>
        </note>
      <note default-x="189.13" default-y="-30.00">
        <chord/>
        <pitch>
          <step>'.$chord_1[4].'</step>
          <octave>'.$chord_1[5].'</octave>
          </pitch>
        <duration>2</duration>
        <voice>1</voice>
        <type>half</type>
        <stem>up</stem>
        <staff>1</staff>
        </note>
      <note default-x="189.13" default-y="-20.00">
        <chord/>
        <pitch>
          <step>'.$chord_1[6].'</step>
          <octave>'.$chord_1[7].'</octave>
          </pitch>
        <duration>2</duration>
        <voice>1</voice>
        <type>half</type>
        <stem>up</stem>
        <staff>1</staff>
        </note>
      <backup>
        <duration>4</duration>
        </backup>
      <note default-x="77.44" default-y="-130.00">
        <pitch>
          <step>'.$chord_1[0].'</step>
          <octave>'.$chord_1[1].'</octave>
          </pitch>
        <duration>4</duration>
        <voice>5</voice>
        <type>whole</type>
        <staff>2</staff>
        </note>
      </measure>
    <measure number="2" width="241.10">
      <note default-x="14.93" default-y="-40.00">
        <pitch>
          <step>'.$chord_2[2].'</step>
          <octave>'.$chord_2[3].'</octave>
          </pitch>
        <duration>2</duration>
        <voice>1</voice>
        <type>half</type>
        <stem>up</stem>
        <staff>1</staff>
        </note>
      <note default-x="14.93" default-y="-30.00">
        <chord/>
        <pitch>
          <step>'.$chord_2[4].'</step>
          <octave>'.$chord_2[5].'</octave>
          </pitch>
        <duration>2</duration>
        <voice>1</voice>
        <type>half</type>
        <stem>up</stem>
        <staff>1</staff>
        </note>
      <note default-x="14.93" default-y="-15.00">
        <chord/>
        <pitch>
          <step>'.$chord_2[6].'</step>
          <octave>'.$chord_2[7].'</octave>
          </pitch>
        <duration>2</duration>
        <voice>1</voice>
        <type>half</type>
        <stem>up</stem>
        <staff>1</staff>
        </note>
      <note default-x="127.03" default-y="-40.00">
        <pitch>
          <step>'.$chord_2[2].'</step>
          <octave>'.$chord_2[3].'</octave>
          </pitch>
        <duration>2</duration>
        <voice>1</voice>
        <type>half</type>
        <stem>up</stem>
        <staff>1</staff>
        </note>
      <note default-x="127.03" default-y="-30.00">
        <chord/>
        <pitch>
          <step>'.$chord_2[4].'</step>
          <octave>'.$chord_2[5].'</octave>
          </pitch>
        <duration>2</duration>
        <voice>1</voice>
        <type>half</type>
        <stem>up</stem>
        <staff>1</staff>
        </note>
      <note default-x="127.03" default-y="-15.00">
        <chord/>
        <pitch>
          <step>'.$chord_2[6].'</step>
          <octave>'.$chord_2[7].'</octave>
          </pitch>
        <duration>2</duration>
        <voice>1</voice>
        <type>half</type>
        <stem>up</stem>
        <staff>1</staff>
        </note>
      <backup>
        <duration>4</duration>
        </backup>
      <note default-x="12.00" default-y="-140.00">
        <pitch>
          <step>'.$chord_2[0].'</step>
          <octave>'.$chord_2[1].'</octave>
          </pitch>
        <duration>4</duration>
        <voice>5</voice>
        <type>whole</type>
        <staff>2</staff>
        </note>
      </measure>
    <measure number="3" width="241.10">
      <note default-x="14.93" default-y="-35.00">
        <pitch>
          <step>'.$chord_3[2].'</step>
          <octave>'.$chord_3[3].'</octave>
          </pitch>
        <duration>2</duration>
        <voice>1</voice>
        <type>half</type>
        <stem>up</stem>
        <staff>1</staff>
        </note>
      <note default-x="14.93" default-y="-25.00">
        <chord/>
        <pitch>
          <step>'.$chord_3[4].'</step>
          <octave>'.$chord_3[5].'</octave>
          </pitch>
        <duration>2</duration>
        <voice>1</voice>
        <type>half</type>
        <stem>up</stem>
        <staff>1</staff>
        </note>
      <note default-x="14.93" default-y="-15.00">
        <chord/>
        <pitch>
          <step>'.$chord_3[6].'</step>
          <octave>'.$chord_3[7].'</octave>
          </pitch>
        <duration>2</duration>
        <voice>1</voice>
        <type>half</type>
        <stem>up</stem>
        <staff>1</staff>
        </note>
      <note default-x="127.03" default-y="-35.00">
        <pitch>
          <step>'.$chord_3[2].'</step>
          <octave>'.$chord_3[3].'</octave>
          </pitch>
        <duration>2</duration>
        <voice>1</voice>
        <type>half</type>
        <stem>up</stem>
        <staff>1</staff>
        </note>
      <note default-x="127.03" default-y="-25.00">
        <chord/>
        <pitch>
          <step>'.$chord_3[4].'</step>
          <octave>'.$chord_3[5].'</octave>
          </pitch>
        <duration>2</duration>
        <voice>1</voice>
        <type>half</type>
        <stem>up</stem>
        <staff>1</staff>
        </note>
      <note default-x="127.03" default-y="-15.00">
        <chord/>
        <pitch>
          <step>'.$chord_3[6].'</step>
          <octave>'.$chord_3[7].'</octave>
          </pitch>
        <duration>2</duration>
        <voice>1</voice>
        <type>half</type>
        <stem>up</stem>
        <staff>1</staff>
        </note>
      <backup>
        <duration>4</duration>
        </backup>
      <note default-x="12.00" default-y="-125.00">
        <pitch>
          <step>'.$chord_3[0].'</step>
          <octave>'.$chord_3[1].'</octave>
          </pitch>
        <duration>4</duration>
        <voice>5</voice>
        <type>whole</type>
        <staff>2</staff>
        </note>
      </measure>
    <measure number="4" width="274.42">
      <note default-x="19.03" default-y="-35.00">
        <pitch>
          <step>'.$chord_4[2].'</step>
          <octave>'.$chord_4[3].'</octave>
          </pitch>
        <duration>2</duration>
        <voice>1</voice>
        <type>half</type>
        <stem>up</stem>
        <staff>1</staff>
        </note>
      <note default-x="19.03" default-y="-25.00">
        <chord/>
        <pitch>
          <step>'.$chord_4[4].'</step>
          <alter>-1</alter>
          <octave>'.$chord_4[5].'</octave>
          </pitch>
        <duration>2</duration>
        <voice>1</voice>
        <type>half</type>
        <accidental>flat</accidental>
        <stem>up</stem>
        <staff>1</staff>
        </note>
      <note default-x="31.68" default-y="-20.00">
        <chord/>
        <pitch>
          <step>'.$chord_4[6].'</step>
          <octave>'.$chord_4[7].'</octave>
          </pitch>
        <duration>2</duration>
        <voice>1</voice>
        <type>half</type>
        <stem>up</stem>
        <staff>1</staff>
        </note>
      <note default-x="141.24" default-y="-35.00">
        <pitch>
          <step>'.$chord_4[2].'</step>
          <octave>'.$chord_4[3].'</octave>
          </pitch>
        <duration>2</duration>
        <voice>1</voice>
        <type>half</type>
        <stem>up</stem>
        <staff>1</staff>
        </note>
      <note default-x="141.24" default-y="-25.00">
        <chord/>
        <pitch>
          <step>'.$chord_4[4].'</step>
          <alter>-1</alter>
          <octave>'.$chord_4[5].'</octave>
          </pitch>
        <duration>2</duration>
        <voice>1</voice>
        <type>half</type>
        <stem>up</stem>
        <staff>1</staff>
        </note>
      <note default-x="153.89" default-y="-20.00">
        <chord/>
        <pitch>
          <step>'.$chord_4[6].'</step>
          <octave>'.$chord_4[7].'</octave>
          </pitch>
        <duration>2</duration>
        <voice>1</voice>
        <type>half</type>
        <stem>up</stem>
        <staff>1</staff>
        </note>
      <backup>
        <duration>4</duration>
        </backup>
      <note default-x="16.10" default-y="-125.00">
        <pitch>
          <step>'.$chord_4[0].'</step>
          <alter>-1</alter>
          <octave>'.$chord_4[1].'</octave>
          </pitch>
        <duration>4</duration>
        <voice>5</voice>
        <type>whole</type>
        <accidental>flat</accidental>
        <staff>2</staff>
        </note>
      <barline location="right">
        <bar-style>light-heavy</bar-style>
        </barline>
      </measure>
    </part>
  </score-partwise>';
  






# Pattern speichern

open ( my $fh, '>', "midi-pattern.xml" );
print $fh $midi_muster;
close $fh;


# Erstell-Zeit ermitteln

my $erstellzeit = times();

print "\nSong wurde in $erstellzeit Sekunden erstellt.\n\n";



So klingt's:

midi-pattern

...



Das "Altern" und div. noch berücksichtigt:

 

Code

#!/usr/bin/perl

# midi-pattern-writer_1.2.pl

use strict;
use warnings;
use DBI;
use ZugangsDaten_postgresql qw($DB_USER $DB_PASSWD);
use Encode qw(is_utf8 decode encode);
use Storable qw(store retrieve);


# Variablen

my $timestamp = localtime(time);


# Program

## Timestamp für Dateinamen anpassen

$timestamp =~ s/ /_/g;
$timestamp =~ s/:/_/g;


## Ein Array pro Takt

my @chord_1 = ("C", "3", "E", "4", "G", "4", "B", "4");
my @chord_2 = ("A", "2", "E", "4", "G", "4", "C", "5");
my @chord_3 = ("D", "3", "F", "4", "A", "4", "C", "5");
my @chord_4 = ("D-", "3", "F", "4", "A-", "4", "B", "4");

### Array-Transformation

my @arrays = (\@chord_1, \@chord_2, \@chord_3, \@chord_4);

foreach ( @arrays ) {
    my $tmparray_ref = $_;
    foreach ( @$tmparray_ref ) {
        $_ =~ s/([CDEFGAB])/<step>$1<\/step>/;
        $_ =~ s/([1234567])/<octave>$1<\/octave>/;
        $_ =~ s/([-+])/<alter>$1X<\/alter>/;
        $_ =~ s/X/1/;
        print "$_\n";
    }
}

## Array-Einträge in Vorlage beamen

my $midi_muster = '<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE score-partwise PUBLIC "-//Recordare//DTD MusicXML 3.0 Partwise//EN" "http://www.musicxml.org/dtds/partwise.dtd">
<score-partwise>
  <work>
    <work-title>Midi-Muster</work-title>
    </work>
  <identification>
    <creator type="composer">Zarko Maroli</creator>
    <creator type="lyricist">Hembel</creator>
    <encoding>
      <software>MuseScore 2.0.2</software>
      <encoding-date>2019-02-16</encoding-date>
      <supports element="accidental" type="yes"/>
      <supports element="beam" type="yes"/>
      <supports element="print" attribute="new-page" type="yes" value="yes"/>
      <supports element="print" attribute="new-system" type="yes" value="yes"/>
      <supports element="stem" type="yes"/>
      </encoding>
    </identification>
  <defaults>
    <scaling>
      <millimeters>7.05556</millimeters>
      <tenths>40</tenths>
      </scaling>
    <page-layout>
      <page-height>1683.36</page-height>
      <page-width>1190.88</page-width>
      <page-margins type="even">
        <left-margin>56.6929</left-margin>
        <right-margin>56.6929</right-margin>
        <top-margin>56.6929</top-margin>
        <bottom-margin>113.386</bottom-margin>
        </page-margins>
      <page-margins type="odd">
        <left-margin>56.6929</left-margin>
        <right-margin>56.6929</right-margin>
        <top-margin>56.6929</top-margin>
        <bottom-margin>113.386</bottom-margin>
        </page-margins>
      </page-layout>
    <word-font font-family="FreeSerif" font-size="10"/>
    <lyric-font font-family="FreeSerif" font-size="11"/>
    </defaults>
  <credit page="1">
    <credit-words default-x="595.44" default-y="1626.67" justify="center" valign="top" font-size="24">Midi-Muster</credit-words>
    </credit>
  <credit page="1">
    <credit-words default-x="1134.19" default-y="1526.67" justify="right" valign="bottom" font-size="12">Zarko Maroli</credit-words>
    </credit>
  <credit page="1">
    <credit-words default-x="56.6929" default-y="1526.67" justify="left" valign="bottom" font-size="12">Hembel</credit-words>
    </credit>
  <part-list>
    <score-part id="P1">
      <part-name>Piano</part-name>
      <part-abbreviation>Pno.</part-abbreviation>
      <score-instrument id="P1-I1">
        <instrument-name>Piano</instrument-name>
        </score-instrument>
      <midi-device id="P1-I1" port="1"></midi-device>
      <midi-instrument id="P1-I1">
        <midi-channel>1</midi-channel>
        <midi-program>1</midi-program>
        <volume>78.7402</volume>
        <pan>0</pan>
        </midi-instrument>
      </score-part>
    </part-list>
  <part id="P1">
    <measure number="1" width="299.86">
      <print>
        <system-layout>
          <system-margins>
            <left-margin>21.00</left-margin>
            <right-margin>0.00</right-margin>
            </system-margins>
          <top-system-distance>170.00</top-system-distance>
          </system-layout>
        <staff-layout number="2">
          <staff-distance>65.00</staff-distance>
          </staff-layout>
        </print>
      <attributes>
        <divisions>1</divisions>
        <key>
          <fifths>0</fifths>
          </key>
        <time>
          <beats>4</beats>
          <beat-type>4</beat-type>
          </time>
        <staves>2</staves>
        <clef number="1">
          <sign>G</sign>
          <line>2</line>
          </clef>
        <clef number="2">
          <sign>F</sign>
          <line>4</line>
          </clef>
        </attributes>
      <note default-x="80.38" default-y="-40.00">
        <pitch>
          '.$chord_1[2].'
          '.$chord_1[3].'
          </pitch>
        <duration>2</duration>
        <voice>1</voice>
        <type>half</type>
        <stem>up</stem>
        <staff>1</staff>
        </note>
      <note default-x="80.38" default-y="-30.00">
        <chord/>
        <pitch>
          '.$chord_1[4].'
          '.$chord_1[5].'
          </pitch>
        <duration>2</duration>
        <voice>1</voice>
        <type>half</type>
        <stem>up</stem>
        <staff>1</staff>
        </note>
      <note default-x="80.38" default-y="-20.00">
        <chord/>
        <pitch>
          '.$chord_1[6].'
          '.$chord_1[7].'
          </pitch>
        <duration>2</duration>
        <voice>1</voice>
        <type>half</type>
        <stem>up</stem>
        <staff>1</staff>
        </note>
      <note default-x="189.13" default-y="-40.00">
        <pitch>
          '.$chord_1[2].'
          '.$chord_1[3].'
          </pitch>
        <duration>2</duration>
        <voice>1</voice>
        <type>half</type>
        <stem>up</stem>
        <staff>1</staff>
        </note>
      <note default-x="189.13" default-y="-30.00">
        <chord/>
        <pitch>
          '.$chord_1[4].'
          '.$chord_1[5].'
          </pitch>
        <duration>2</duration>
        <voice>1</voice>
        <type>half</type>
        <stem>up</stem>
        <staff>1</staff>
        </note>
      <note default-x="189.13" default-y="-20.00">
        <chord/>
        <pitch>
          '.$chord_1[6].'
          '.$chord_1[7].'
          </pitch>
        <duration>2</duration>
        <voice>1</voice>
        <type>half</type>
        <stem>up</stem>
        <staff>1</staff>
        </note>
      <backup>
        <duration>4</duration>
        </backup>
      <note default-x="77.44" default-y="-130.00">
        <pitch>
          '.$chord_1[0].'
          '.$chord_1[1].'
          </pitch>
        <duration>4</duration>
        <voice>5</voice>
        <type>whole</type>
        <staff>2</staff>
        </note>
      </measure>
    <measure number="2" width="241.10">
      <note default-x="14.93" default-y="-40.00">
        <pitch>
          '.$chord_2[2].'
          '.$chord_2[3].'
          </pitch>
        <duration>2</duration>
        <voice>1</voice>
        <type>half</type>
        <stem>up</stem>
        <staff>1</staff>
        </note>
      <note default-x="14.93" default-y="-30.00">
        <chord/>
        <pitch>
          '.$chord_2[4].'
          '.$chord_2[5].'
          </pitch>
        <duration>2</duration>
        <voice>1</voice>
        <type>half</type>
        <stem>up</stem>
        <staff>1</staff>
        </note>
      <note default-x="14.93" default-y="-15.00">
        <chord/>
        <pitch>
          '.$chord_2[6].'
          '.$chord_2[7].'
          </pitch>
        <duration>2</duration>
        <voice>1</voice>
        <type>half</type>
        <stem>up</stem>
        <staff>1</staff>
        </note>
      <note default-x="127.03" default-y="-40.00">
        <pitch>
          '.$chord_2[2].'
          '.$chord_2[3].'
          </pitch>
        <duration>2</duration>
        <voice>1</voice>
        <type>half</type>
        <stem>up</stem>
        <staff>1</staff>
        </note>
      <note default-x="127.03" default-y="-30.00">
        <chord/>
        <pitch>
          '.$chord_2[4].'
          '.$chord_2[5].'
          </pitch>
        <duration>2</duration>
        <voice>1</voice>
        <type>half</type>
        <stem>up</stem>
        <staff>1</staff>
        </note>
      <note default-x="127.03" default-y="-15.00">
        <chord/>
        <pitch>
          '.$chord_2[6].'
          '.$chord_2[7].'
          </pitch>
        <duration>2</duration>
        <voice>1</voice>
        <type>half</type>
        <stem>up</stem>
        <staff>1</staff>
        </note>
      <backup>
        <duration>4</duration>
        </backup>
      <note default-x="12.00" default-y="-140.00">
        <pitch>
          '.$chord_2[0].'
          '.$chord_2[1].'
          </pitch>
        <duration>4</duration>
        <voice>5</voice>
        <type>whole</type>
        <staff>2</staff>
        </note>
      </measure>
    <measure number="3" width="241.10">
      <note default-x="14.93" default-y="-35.00">
        <pitch>
          '.$chord_3[2].'
          '.$chord_3[3].'
          </pitch>
        <duration>2</duration>
        <voice>1</voice>
        <type>half</type>
        <stem>up</stem>
        <staff>1</staff>
        </note>
      <note default-x="14.93" default-y="-25.00">
        <chord/>
        <pitch>
          '.$chord_3[4].'
          '.$chord_3[5].'
          </pitch>
        <duration>2</duration>
        <voice>1</voice>
        <type>half</type>
        <stem>up</stem>
        <staff>1</staff>
        </note>
      <note default-x="14.93" default-y="-15.00">
        <chord/>
        <pitch>
          '.$chord_3[6].'
          '.$chord_3[7].'
          </pitch>
        <duration>2</duration>
        <voice>1</voice>
        <type>half</type>
        <stem>up</stem>
        <staff>1</staff>
        </note>
      <note default-x="127.03" default-y="-35.00">
        <pitch>
          '.$chord_3[2].'
          '.$chord_3[3].'
          </pitch>
        <duration>2</duration>
        <voice>1</voice>
        <type>half</type>
        <stem>up</stem>
        <staff>1</staff>
        </note>
      <note default-x="127.03" default-y="-25.00">
        <chord/>
        <pitch>
          '.$chord_3[4].'
          '.$chord_3[5].'
          </pitch>
        <duration>2</duration>
        <voice>1</voice>
        <type>half</type>
        <stem>up</stem>
        <staff>1</staff>
        </note>
      <note default-x="127.03" default-y="-15.00">
        <chord/>
        <pitch>
          '.$chord_3[6].'
          '.$chord_3[7].'
          </pitch>
        <duration>2</duration>
        <voice>1</voice>
        <type>half</type>
        <stem>up</stem>
        <staff>1</staff>
        </note>
      <backup>
        <duration>4</duration>
        </backup>
      <note default-x="12.00" default-y="-125.00">
        <pitch>
          '.$chord_3[0].'
          '.$chord_3[1].'
          </pitch>
        <duration>4</duration>
        <voice>5</voice>
        <type>whole</type>
        <staff>2</staff>
        </note>
      </measure>
    <measure number="4" width="274.42">
      <note default-x="19.03" default-y="-35.00">
        <pitch>
          '.$chord_4[2].'
          '.$chord_4[3].'
          </pitch>
        <duration>2</duration>
        <voice>1</voice>
        <type>half</type>
        <stem>up</stem>
        <staff>1</staff>
        </note>
      <note default-x="19.03" default-y="-25.00">
        <chord/>
        <pitch>
          '.$chord_4[4].'
          '.$chord_4[5].'
          </pitch>
        <duration>2</duration>
        <voice>1</voice>
        <type>half</type>
        <accidental>flat</accidental>
        <stem>up</stem>
        <staff>1</staff>
        </note>
      <note default-x="31.68" default-y="-20.00">
        <chord/>
        <pitch>
          '.$chord_4[6].'
          '.$chord_4[7].'
          </pitch>
        <duration>2</duration>
        <voice>1</voice>
        <type>half</type>
        <stem>up</stem>
        <staff>1</staff>
        </note>
      <note default-x="141.24" default-y="-35.00">
        <pitch>
          '.$chord_4[2].'
          '.$chord_4[3].'
          </pitch>
        <duration>2</duration>
        <voice>1</voice>
        <type>half</type>
        <stem>up</stem>
        <staff>1</staff>
        </note>
      <note default-x="141.24" default-y="-25.00">
        <chord/>
        <pitch>
          '.$chord_4[4].'
          '.$chord_4[5].'
          </pitch>
        <duration>2</duration>
        <voice>1</voice>
        <type>half</type>
        <stem>up</stem>
        <staff>1</staff>
        </note>
      <note default-x="153.89" default-y="-20.00">
        <chord/>
        <pitch>
          '.$chord_4[6].'
          '.$chord_4[7].'
          </pitch>
        <duration>2</duration>
        <voice>1</voice>
        <type>half</type>
        <stem>up</stem>
        <staff>1</staff>
        </note>
      <backup>
        <duration>4</duration>
        </backup>
      <note default-x="16.10" default-y="-125.00">
        <pitch>
          '.$chord_4[0].'
          '.$chord_4[1].'
          </pitch>
        <duration>4</duration>
        <voice>5</voice>
        <type>whole</type>
        <accidental>flat</accidental>
        <staff>2</staff>
        </note>
      <barline location="right">
        <bar-style>light-heavy</bar-style>
        </barline>
      </measure>
    </part>
  </score-partwise>';
  


# Pattern speichern

open ( my $fh, '>', "midi-pattern.xml" );
print $fh $midi_muster;
close $fh;


# Erstell-Zeit ermitteln

my $erstellzeit = times();

print "\nSong wurde in $erstellzeit Sekunden erstellt.\n\n";

Schönheit rules. Mir gefällt mein Code. [ Und er funzt auch, ist omx-geprüft! ]


Next step follows ...


~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Nachgereicht:

{ zählt noch nicht zum "next step" }

#!/usr/bin/perl

# midi-pattern-writer_1.3.pl

use strict;
use warnings;
use DBI;
use ZugangsDaten_postgresql qw($DB_USER $DB_PASSWD);
use Encode qw(is_utf8 decode encode);
use Storable qw(store retrieve);


# Variablen

my $timestamp = localtime(time);


# Program

## Timestamp für Dateinamen anpassen

$timestamp =~ s/ /_/g;
$timestamp =~ s/:/_/g;


## Ein Array pro Takt

my @chord_1 = ("C", "3", "E", "4", "G", "4", "B", "4");
my @chord_2 = ("A", "2", "E", "4", "G", "4", "C", "5");
my @chord_3 = ("D", "3", "F", "4", "A", "4", "C", "5");
my @chord_4 = ("D-", "3", "F", "4", "A-", "4", "B", "4");
my @chord_5 = ("E", "3", "G", "4", "B", "4", "D", "5");
my @chord_6 = ("A", "2", "E", "4", "G", "4", "C+", "5");
my @chord_7 = ("D", "3", "F", "4", "A", "4", "C", "5");
my @chord_8 = ("G", "2", "F", "4", "B", "4", "D", "5");

### Array-Transformation

my @arrays = (\@chord_1, \@chord_2, \@chord_3, \@chord_4, \@chord_5, \@chord_6, \@chord_7, \@chord_8,);

foreach ( @arrays ) {
    my $tmparray_ref = $_;
    foreach ( @$tmparray_ref ) {
        $_ =~ s/([CDEFGAB])/<step>$1<\/step>/;
        $_ =~ s/([1234567])/<octave>$1<\/octave>/;
        $_ =~ s/([-+])/<alter>$1X<\/alter>/;
        $_ =~ s/X/1/;
        print "$_\n";
    }
}

...


Etwas weniger schön, weil mit der Brechstange.

 

Ergebnis

So sieht's aus:



Da fehlt ein Taktstrich! :-)

So klingt's:


Und so klingt's in der Zusammenfügung bis jetzt:


{ daß das noch ( lange ) nicht ernst zu nehmen ist, brauche ich meinen Lesern sicher nicht zu sagen }

Problem gelöst!


...
        <staff>2</staff>
        </note>
       </measure>
     <measure number="5" width="299.86">
      <note default-x="80.38" default-y="-40.00">
        <pitch>
          '.$chord_5[2].'
          '.$chord_5[3].'
          </pitch>
        <duration>2</duration>

...



Oki, genug für heut'.

Kommentare

Beliebte Posts aus diesem Blog

·

Es brennt.

Bye, bye Nord Stream 2!