Hydrogen-Pattern-Erzeugung, Fortsetzung


Eine neue Produktlinie ist ins Leben gerufen worden:

hydrogen-pattern-writer_2.0.pl


Die damit erzeugten Pattern klingen schon etwas brauchbarer. Und daran wird in den nächsten Tagen ein bisschen weitergebastelt.

Klangbeispiele:


https://drive.google.com/file/d/1w3r_QQeyOGqoUTcUSjAJbaU5FBQPXHio/view?usp=sharing
https://drive.google.com/file/d/1DI4XTVMOMEQSu2pg3bmNR1g8iNdWMwP1/view?usp=sharing
https://drive.google.com/file/d/1LrtWMuoyR_O6s_S_yNyXcAQQibiCM1k0/view?usp=sharing
https://drive.google.com/file/d/1dzhch9GUrYL8Okz5ucLIRyxLZS7vlQIZ/view?usp=sharing

Und ein kleiner Hybrid:

Hydro-Midi-Hybrido



Code:

#!/usr/bin/perl

# hydrogen-pattern-writer_2.0.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);

my $song_head = '<?xml version="1.0" encoding="UTF-8"?>
<song>
 <version>0.9.6.1</version>
 <bpm>120</bpm>
 <volume>0.73</volume>
 <metronomeVolume>0.5</metronomeVolume>
 <name>Untitled Song</name>
 <author>Zarko Maroli</author>
 <notes>Empty song.</notes>
 <license>omx-lizenziert</license>
 <loopEnabled>true</loopEnabled>
 <patternModeMode>true</patternModeMode>
 <mode>pattern</mode>
 <humanize_time>0</humanize_time>
 <humanize_velocity>0</humanize_velocity>
 <swing_factor>0</swing_factor>
 <instrumentList>
  <instrument>
   <id>0</id>
...
    <gain>1</gain>
    <pitch>0</pitch>
   </layer>
  </instrument>
 </instrumentList>
 <patternList>'."\n";

my $head_1 = ' <pattern>
  <name>random-pattern-11.3-';
 
my $head_2 = '</name>
  <category>No category</category>
  <size>192</size>
  <noteList>'."\n";

my $tail = "  </noteList>
 </pattern>\n";

my $pos_var;

my $note_var_1 = "    <note>
    <position>";
my $note_var_2 = "</position>
    <leadlag>0</leadlag>
    <velocity>0.8</velocity>
    <pan_L>0.5</pan_L>
    <pan_R>0.5</pan_R>
    <pitch>0</pitch>
    <key>C0</key>
    <length>-1</length>
    <instrument>";
my $note_var_3 = "</instrument>
   </note>\n";
  
my $song_tail = ' </patternList>
 <virtualPatternList/>
 <patternSequence>
  <group>
   <patternID>random-pattern-11.3-1</patternID>
  </group>
  <group>
   <patternID>random-pattern-11.3-1</patternID>
  </group>
  <group>
   <patternID>random-pattern-11.3-1</patternID>
  </group>
  <group>
   <patternID>random-pattern-11.3-1</patternID>
  </group>
  <group>
   <patternID>random-pattern-11.3-2</patternID>
  </group>
  <group>
   <patternID>random-pattern-11.3-2</patternID>
  </group>
  <group>
   <patternID>random-pattern-11.3-2</patternID>
  </group>
  <group>
   <patternID>random-pattern-11.3-2</patternID>
  </group>
  <group>
   <patternID>random-pattern-11.3-3</patternID>
  </group>
  <group>
   <patternID>random-pattern-11.3-3</patternID>
  </group>
  <group>
   <patternID>random-pattern-11.3-3</patternID>
  </group>
  <group>
   <patternID>random-pattern-11.3-3</patternID>
  </group>
  <group>
   <patternID>random-pattern-11.3-4</patternID>
  </group>
  <group>
   <patternID>random-pattern-11.3-4</patternID>
  </group>
  <group>
   <patternID>random-pattern-11.3-4</patternID>
  </group>
  <group>
   <patternID>random-pattern-11.3-4</patternID>
  </group>
  <group>
   <patternID>random-pattern-11.3-5</patternID>
  </group>
  <group>
   <patternID>random-pattern-11.3-5</patternID>
  </group>
  <group>
   <patternID>random-pattern-11.3-5</patternID>
  </group>
  <group>
   <patternID>random-pattern-11.3-5</patternID>
  </group>
  <group>
   <patternID>random-pattern-11.3-6</patternID>
  </group>
  <group>
   <patternID>random-pattern-11.3-6</patternID>
  </group>
  <group>
   <patternID>random-pattern-11.3-6</patternID>
  </group>
  <group>
   <patternID>random-pattern-11.3-6</patternID>
  </group>
  <group>
   <patternID>random-pattern-11.3-7</patternID>
  </group>
  <group>
   <patternID>random-pattern-11.3-7</patternID>
  </group>
  <group>
   <patternID>random-pattern-11.3-7</patternID>
  </group>
  <group>
   <patternID>random-pattern-11.3-7</patternID>
  </group>
  <group>
   <patternID>random-pattern-11.3-8</patternID>
  </group>
  <group>
   <patternID>random-pattern-11.3-8</patternID>
  </group>
  <group>
   <patternID>random-pattern-11.3-8</patternID>
  </group>
  <group>
   <patternID>random-pattern-11.3-8</patternID>
  </group>
  <group>
   <patternID>random-pattern-11.3-9</patternID>
  </group>
  <group>
   <patternID>random-pattern-11.3-9</patternID>
  </group>
  <group>
   <patternID>random-pattern-11.3-9</patternID>
  </group>
  <group>
   <patternID>random-pattern-11.3-9</patternID>
  </group>
  <group>
   <patternID>random-pattern-11.3-10</patternID>
  </group>
  <group>
   <patternID>random-pattern-11.3-10</patternID>
  </group>
  <group>
   <patternID>random-pattern-11.3-10</patternID>
  </group>
  <group>
   <patternID>random-pattern-11.3-10</patternID>
  </group>
 </patternSequence>
 <ladspa>
  <fx>
   <name>no plugin</name>
   <filename>-</filename>
   <enabled>false</enabled>
   <volume>0.0</volume>
  </fx>
  <fx>
   <name>no plugin</name>
   <filename>-</filename>
   <enabled>false</enabled>
   <volume>0.0</volume>
  </fx>
  <fx>
   <name>no plugin</name>
   <filename>-</filename>
   <enabled>false</enabled>
   <volume>0.0</volume>
  </fx>
  <fx>
   <name>no plugin</name>
   <filename>-</filename>
   <enabled>false</enabled>
   <volume>0.0</volume>
  </fx>
 </ladspa>
 <BPMTimeLine/>
 <timeLineTag/>
</song>';
  
my $instrument;
my $hits;


my @positions_1 = ("0");
my @positions_2 = ("0", "96");
my @positions_4 = ("0", "48", "96", "144");
my @positions_8 = ("0", "24", "48", "72", "96", "120", "144", "168");
my @positions_16 = ("0", "12", "24", "36", "48", "60", "72", "84", "96", "108", "120", "132", "144", "156", "168", "180");
my @positions_32 = ("0", "6", "12", "18", "24", "30", "36", "42", "48", "54", "60", "66", "72", "78", "84", "90", "96", "102", "108", "114", "120", "126", "132", "138", "144", "150", "156", "162", "168", "174", "180", "186");
my @positions_64 = ("0", "3", "6", "9", "12", "15", "18", "21", "24", "27", "30", "33", "36", "39", "42", "45", "48", "51",
                    "54", "57", "60", "63", "66", "69", "72", "75", "78", "81","84", "87", "90", "93", "96", "99", "102", "105",
                    "108", "111", "114", "117", "120", "123", "126", "129", "132", "135", "138", "141", "144", "147", "150", "153",
                    "156", "159", "162", "165", "168", "171", "174", "177", "180", "183", "186", "189");
                   
my @positions_1_to_64 = ( \@positions_1, \@positions_2, \@positions_4, \@positions_8, \@positions_16, \@positions_32, \@positions_64 );


# Program

## Timestamp für Dateinamen anpassen

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

## Song eröffnen

my $song = $song_head;

print "Song: song_1.3-$timestamp.h2song\n\n";

## Pattern erzeugen

for ( my $pattern_nr = 1; $pattern_nr < 11; $pattern_nr++ ) {
       
        print "\nPattern-Nr.: $pattern_nr\nPattern-Name: random-pattern-11.3-$pattern_nr\n";
       
        my $positions = int rand(scalar @positions_1_to_64) + 1;
        my @positions;
   
    print "Zahl der Positionen: ", $positions, "\n";
    # sleep 1;
   
    for ( my $poscount = 1; $poscount < $positions + 1; $poscount++ ) {
        my $poschoose = int rand(scalar @positions_1_to_64);
        print "Nummer der gewählten Position $poscount: ", $poschoose, "\n";
        # sleep 1;
        my $position_ref = $positions_1_to_64[$poschoose];
        push @positions, $position_ref
    }
   
    $hits = "";
   
    foreach ( @positions ) {
   
        $instrument = int rand(16);
       
        # Würfel, ob nach Zufallsprinzip Hits erzeugt werden oder ob aus Patternsammlung übernommen wird
       
        my $glueckswuerfel = int rand (6);
        my $rndbits = 0;   
       
        if ( $glueckswuerfel <= 3 ) {
            print "\nEs werden Zufalls-Schläge erzeugt!\n\n";
            # Zufallsschlagerzeugung gemäß vorbelegter Position ( => Auflösung )
            while ( $rndbits == 0 ) {
                $rndbits = 0;
                my $hits_new = "";               
                foreach ( @$_ ) {
                    my $rndbit = int rand(2);
                    $rndbits = $rndbits + $rndbit;
                    # print $rndbit, "\n";
                    if ( $rndbit == 1 ) {
                        $pos_var = $_;
                        $hits_new = $hits_new.$note_var_1.$pos_var.$note_var_2.$instrument.$note_var_3
                    } else { next }
                }
                # Hinzufügen des $hits_new an Hits-String, wenn $rndbits > 0
                if ( $rndbits > 0 ) {
                    $hits = $hits.$hits_new
                }
            }
        } elsif ( $glueckswuerfel > 3 ) {
            print "\nEs wird ein Pattern ausgelost!\n";
            # Pattern-Auslosung & Anfügen der neuen Hits an den Hits-String
            my $hits_new = patternchoice($instrument);
            $hits = $hits.$hits_new
        }
   
    }
   
   
    # Pattern speichern

    my $pattern_new = $head_1.$pattern_nr.$head_2.$hits.$tail;
   
    open ( my $fh, '>', "/home/zarko/.hydrogen/data/patterns/randompatterns/random-pattern-11.3-$pattern_nr.h2pattern" );
    print $fh $pattern_new;
    close $fh;

    # Pattern in Song einfügen
   
    $song = $song.$pattern_new;

}

# Song abschließen

$song = $song.$song_tail;

# Song speichern

open ( my $fh_2, '>', "/home/zarko/.hydrogen/data/patterns/randompatterns/song_2.0-$timestamp.h2song" );
print $fh_2 $song;
close $fh_2;

# Erstell-Zeit ermitteln

my $erstellzeit = times();

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





#####################################################
################## SUBROUTINEN ######################
#####################################################

# Subroutine patternchoice

sub patternchoice {
    my $instrument = shift;
    my $pattern_count = pattern("Anzahl");
    print "\nMeine Pattern-Anzahl: $pattern_count\n";
    # Zufallsauswahl eines Pattern
    my $pattern_no = int rand($pattern_count);
    print "Meine Pattern-Auswahl: $pattern_no\n";
    my $pattern_ref = pattern($pattern_no);
    my @pattern = @$pattern_ref;
    # Kontrolldruck des gewählten Pattern
    print "Mein Pattern: ";
    print map { $_ } @pattern;
    print "\n";
    # print "\nInnehaltung!\n";
    # sleep 11;
    # Ausgewähltes Pattern zu $hits transformieren
    foreach ( @pattern ) {
        if ( $_ ne "-" ) {
            $pos_var = $_;
            $hits = $hits.$note_var_1.$pos_var.$note_var_2.$instrument.$note_var_3;
        }
    }
    return $hits
}

sub pattern {
    # Anfrage, ob Patternanzahl oder einzelnes Pattern gewünscht wird
    my $request = shift;
    my @pattern_halbe_triolen = (
        ["0", "64", "128"],
        ["-", "64", "128"],
        ["0", "-", "128"],
        ["0", "64", "-"],
        ["-", "-", "128"],
        ["-", "64", "-"] );
    my @pattern_viertel = (
        ["0", "48", "96", "144"],
        ["-", "48", "96", "144"],
        ["0", "-", "96", "144"],
        ["0", "48", "-", "144"],
        ["0", "48", "96", "-"],
        ["-", "-", "96", "144"],
        ["-", "48", "-", "144"],
        ["-", "48", "96", "-"],
        ["0", "-", "-", "144"],
        ["0", "-", "96", "-"],
        ["0", "48", "-", "-"] );
    my @pattern_viertel_triolen = (
        ["0", "32", "64", "96", "128", "160"],
        ["0", "-", "64", "96", "-", "160"],
        ["0", "32", "-", "96", "128", "-"],
        ["-", "32", "64", "-", "128", "160"],
        ["0", "32", "64", "-", "-", "160"],
        ["0", "-", "64", "-", "128", "160"] );
    my @pattern_achtel = (
        ["0", "24", "48", "72", "96", "120", "144", "168"],
        ["-", "24", "48", "72", "96", "120", "144", "168"],
        ["0", "-", "48", "72", "96", "120", "144", "168"],
        ["0", "24", "-", "72", "96", "120", "144", "168"],
        ["0", "24", "48", "-", "96", "120", "144", "168"],
        ["0", "24", "48", "72", "-", "120", "144", "168"],
        ["0", "24", "48", "72", "96", "-", "144", "168"],
        ["0", "24", "48", "72", "96", "120", "-", "168"],
        ["0", "24", "48", "72", "96", "120", "144", "-"],
        ["-", "-", "48", "72", "96", "120", "144", "168"],
        ["-", "24", "-", "72", "96", "120", "144", "168"],
        ["-", "24", "48", "-", "96", "120", "144", "168"],
        ["-", "24", "48", "72", "-", "120", "144", "168"],
        ["-", "24", "48", "72", "96", "-", "144", "168"],
        ["-", "24", "48", "72", "96", "120", "-", "168"],
        ["-", "24", "48", "72", "96", "120", "144", "-"],
        ["0", "-", "48", "-", "96", "-", "144", "-"],
        ["-", "24", "-", "-", "96", "-", "144", "-"] );
    # Pattern zusammenfügen
    my @pattern = (@pattern_halbe_triolen,@pattern_viertel,@pattern_viertel_triolen,@pattern_achtel);
    # Return nach Request
    if ( $request eq "Anzahl" ) {
        my $pattern_count = scalar @pattern;
        return $pattern_count
    } elsif ( $request =~ m/[0-9]+/ ) {
        my $pattern_ref = $pattern[$request];
        return \@$pattern_ref
    }
}
   

Kommentare

Beliebte Posts aus diesem Blog

·

Es brennt.

Bye, bye Nord Stream 2!