SlideShare uma empresa Scribd logo
1 de 24
Baixar para ler offline
Perl
Musica Automagica!
Andrew
Plotkin
Nel mezzo del cammin di nostra vita

mi ritrovai per una selva oscura

ché la diritta via era smarrita.

 Ahi quanto a dir qual era è cosa dura

esta selva selvaggia e aspra e forte

che nel pensier rinova la paura!

 Tant'è amara che poco è più morte;

ma per trattar del ben ch'i' vi trovai,

dirò de l'altre cose ch'i' v'ho scorte.

 Io non so ben ridir com'i' v'intrai,

tant'era pien di sonno a quel punto
Nel mezzo del cammin di nostra vita

mi ritrovai per una selva oscura

ché la diritta via era smarrita.

 Ahi quanto a dir qual era è cosa dura

esta selva selvaggia e aspra e forte

che nel pensier rinova la paura!

 Tant'è amara che poco è più morte;

ma per trattar del ben ch'i' vi trovai,

dirò de l'altre cose ch'i' v'ho scorte.

 Io non so ben ridir com'i' v'intrai,

tant'era pien di sonno a quel punto
Nel mezzo del cammin di nostra vita

mi ritrovai per una selva oscura

ché la diritta via era smarrita.

 Ahi quanto a dir qual era è cosa dura

esta selva selvaggia e aspra e forte

che nel pensier rinova la paura!

 Tant'è amara che poco è più morte;

ma per trattar del ben ch'i' vi trovai,

dirò de l'altre cose ch'i' v'ho scorte.

 Io non so ben ridir com'i' v'intrai,

tant'era pien di sonno a quel punto
while( @notes ) {

    if( scalar @notes >= $tuple_size + 1 ) {

        my $key = join ' ',
          @notes[0 .. $tuple_size-1];

        push @{ $tuples{ $key } } ,
             $notes[$tuple_size];
    }
    shift @notes;
}
Markov Chain
 di grado N
Algorithm::
MarkovChain
$chain->seed(
    symbols => @notes ,
    longest => $tuple_size
)
MIDI / MIDI::Simple


• read, compose, modify, and write
  MIDI files
• Sean Burke++
while( $n-- ) {
    my @tuple = @{ $tuples{ $k } };
    my $last = $tuple[ int rand scalar @tuple ];

    n( $last, $tempo[ rand scalar @tempo ], 'f' );

    my @next_tuple = split / /, $k;
    shift @next_tuple;
    push @next_tuple, $last;

    if (defined $tuples{ join ' ', @next_tuple }) {
        $k = join ' ', @next_tuple;
        ++$hit;
    }
    else {
        $k = ( keys %tuples )[ int rand $l ];
        ++$miss;
    }
}
hobbes:~/Desktop larsen$ perl mozart.pl 
  -f peaches.mid -t 6 -s 4 -n 100
Fetching info from MIDI file...
     # Type   Track Name           Instrument
     1 MTrk
     2 MTrk   Peaches en Regalia   original
     3 MTrk   Drums                Drums
     4 MTrk   Saxes                Saxes
     5 MTrk   Brass                Brass
     6 MTrk   Bass                 Bass
     7 MTrk   Piano                Piano
     8 MTrk   Synth                Synth
     9 MTrk   Clarinet             Clarinet
    10 MTrk   Guitar               Guitar
    11 MTrk   M-Playback*recorded M-Playback
Fetching track 6...
I've learnt 376 tuples...
Average number of buckets per   key:
1.90159574468085...
 1. '38 41 29 34' => 35
 2. '43 35 35 42' => 47
 3. '41 42 43 46' => 38 38
 4. '40 35 42 47' => 42 42 42   42 42 42
 5. '46 38 39 40' => 41
 6. '40 42 40 40' => 35 47 35   35 35 35 35
 7. '42 40 37 36' => 40 40 40   40 40 40 40 40
 8. '54 52 49 42' => 49
 9. '42 47 42 35' => 35 35 35   35 35 35 35 35
10. '40 42 40 43' => 43
11. '46 33 33 33' => 45
12. '45 51 52 45' => 44
13. '48 40 40 44' => 32
14. '53 41 41 41' => 43
Demo
I am quite struck by them.. from
 listening to them you can tell they
      are meant to have musical
 structure, and they sound like
     they are intentionally
musical, but they contain no
coherent musical quot;thoughtquot;
“Peaches en regalia”
“Frame by frame”
“Epitaph”
MIDI
MIDI::Simple
Algorithm::MarkovChain
Getopt::*
http://larsen.perlmonk.org/perl/mozart.html

Mais conteúdo relacionado

Destaque

2024 State of Marketing Report – by Hubspot
2024 State of Marketing Report – by Hubspot2024 State of Marketing Report – by Hubspot
2024 State of Marketing Report – by HubspotMarius Sescu
 
Everything You Need To Know About ChatGPT
Everything You Need To Know About ChatGPTEverything You Need To Know About ChatGPT
Everything You Need To Know About ChatGPTExpeed Software
 
Product Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage EngineeringsProduct Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage EngineeringsPixeldarts
 
How Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental HealthHow Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental HealthThinkNow
 
AI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdfAI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdfmarketingartwork
 
PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024Neil Kimberley
 
Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)contently
 
How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024Albert Qian
 
Social Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsSocial Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsKurio // The Social Media Age(ncy)
 
Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024Search Engine Journal
 
5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summarySpeakerHub
 
ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd Clark Boyd
 
Getting into the tech field. what next
Getting into the tech field. what next Getting into the tech field. what next
Getting into the tech field. what next Tessa Mero
 
Google's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search IntentGoogle's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search IntentLily Ray
 
Time Management & Productivity - Best Practices
Time Management & Productivity -  Best PracticesTime Management & Productivity -  Best Practices
Time Management & Productivity - Best PracticesVit Horky
 
The six step guide to practical project management
The six step guide to practical project managementThe six step guide to practical project management
The six step guide to practical project managementMindGenius
 
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...RachelPearson36
 

Destaque (20)

2024 State of Marketing Report – by Hubspot
2024 State of Marketing Report – by Hubspot2024 State of Marketing Report – by Hubspot
2024 State of Marketing Report – by Hubspot
 
Everything You Need To Know About ChatGPT
Everything You Need To Know About ChatGPTEverything You Need To Know About ChatGPT
Everything You Need To Know About ChatGPT
 
Product Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage EngineeringsProduct Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage Engineerings
 
How Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental HealthHow Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental Health
 
AI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdfAI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdf
 
Skeleton Culture Code
Skeleton Culture CodeSkeleton Culture Code
Skeleton Culture Code
 
PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024
 
Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)
 
How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024
 
Social Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsSocial Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie Insights
 
Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024
 
5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary
 
ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd
 
Getting into the tech field. what next
Getting into the tech field. what next Getting into the tech field. what next
Getting into the tech field. what next
 
Google's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search IntentGoogle's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search Intent
 
How to have difficult conversations
How to have difficult conversations How to have difficult conversations
How to have difficult conversations
 
Introduction to Data Science
Introduction to Data ScienceIntroduction to Data Science
Introduction to Data Science
 
Time Management & Productivity - Best Practices
Time Management & Productivity -  Best PracticesTime Management & Productivity -  Best Practices
Time Management & Productivity - Best Practices
 
The six step guide to practical project management
The six step guide to practical project managementThe six step guide to practical project management
The six step guide to practical project management
 
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
 

Perl, musica automagica

  • 3. Nel mezzo del cammin di nostra vita mi ritrovai per una selva oscura ché la diritta via era smarrita. Ahi quanto a dir qual era è cosa dura esta selva selvaggia e aspra e forte che nel pensier rinova la paura! Tant'è amara che poco è più morte; ma per trattar del ben ch'i' vi trovai, dirò de l'altre cose ch'i' v'ho scorte. Io non so ben ridir com'i' v'intrai, tant'era pien di sonno a quel punto
  • 4. Nel mezzo del cammin di nostra vita mi ritrovai per una selva oscura ché la diritta via era smarrita. Ahi quanto a dir qual era è cosa dura esta selva selvaggia e aspra e forte che nel pensier rinova la paura! Tant'è amara che poco è più morte; ma per trattar del ben ch'i' vi trovai, dirò de l'altre cose ch'i' v'ho scorte. Io non so ben ridir com'i' v'intrai, tant'era pien di sonno a quel punto
  • 5. Nel mezzo del cammin di nostra vita mi ritrovai per una selva oscura ché la diritta via era smarrita. Ahi quanto a dir qual era è cosa dura esta selva selvaggia e aspra e forte che nel pensier rinova la paura! Tant'è amara che poco è più morte; ma per trattar del ben ch'i' vi trovai, dirò de l'altre cose ch'i' v'ho scorte. Io non so ben ridir com'i' v'intrai, tant'era pien di sonno a quel punto
  • 6.
  • 7.
  • 8.
  • 9. while( @notes ) { if( scalar @notes >= $tuple_size + 1 ) { my $key = join ' ', @notes[0 .. $tuple_size-1]; push @{ $tuples{ $key } } , $notes[$tuple_size]; } shift @notes; }
  • 10. Markov Chain di grado N
  • 12. $chain->seed( symbols => @notes , longest => $tuple_size )
  • 13. MIDI / MIDI::Simple • read, compose, modify, and write MIDI files • Sean Burke++
  • 14. while( $n-- ) { my @tuple = @{ $tuples{ $k } }; my $last = $tuple[ int rand scalar @tuple ]; n( $last, $tempo[ rand scalar @tempo ], 'f' ); my @next_tuple = split / /, $k; shift @next_tuple; push @next_tuple, $last; if (defined $tuples{ join ' ', @next_tuple }) { $k = join ' ', @next_tuple; ++$hit; } else { $k = ( keys %tuples )[ int rand $l ]; ++$miss; } }
  • 15. hobbes:~/Desktop larsen$ perl mozart.pl -f peaches.mid -t 6 -s 4 -n 100 Fetching info from MIDI file... # Type Track Name Instrument 1 MTrk 2 MTrk Peaches en Regalia original 3 MTrk Drums Drums 4 MTrk Saxes Saxes 5 MTrk Brass Brass 6 MTrk Bass Bass 7 MTrk Piano Piano 8 MTrk Synth Synth 9 MTrk Clarinet Clarinet 10 MTrk Guitar Guitar 11 MTrk M-Playback*recorded M-Playback
  • 16. Fetching track 6... I've learnt 376 tuples... Average number of buckets per key: 1.90159574468085... 1. '38 41 29 34' => 35 2. '43 35 35 42' => 47 3. '41 42 43 46' => 38 38 4. '40 35 42 47' => 42 42 42 42 42 42 5. '46 38 39 40' => 41 6. '40 42 40 40' => 35 47 35 35 35 35 35 7. '42 40 37 36' => 40 40 40 40 40 40 40 40 8. '54 52 49 42' => 49 9. '42 47 42 35' => 35 35 35 35 35 35 35 35 10. '40 42 40 43' => 43 11. '46 33 33 33' => 45 12. '45 51 52 45' => 44 13. '48 40 40 44' => 32 14. '53 41 41 41' => 43
  • 17. Demo
  • 18. I am quite struck by them.. from listening to them you can tell they are meant to have musical structure, and they sound like they are intentionally musical, but they contain no coherent musical quot;thoughtquot;
  • 23.