Get variables from midi-events with the pyhton-midi library











up vote
0
down vote

favorite












I use the python-midi library to read a midi file into a list.



variable = midi.read_midifile(source)


The entries look like those:



   midi.NoteOffEvent(tick=2, channel=10, data=[48, 98]),
midi.NoteOnEvent(tick=46, channel=10, data=[48, 100]),
midi.NoteOffEvent(tick=12, channel=10, data=[48, 100]),
midi.NoteOnEvent(tick=36, channel=10, data=[48, 91]),
midi.NoteOffEvent(tick=14, channel=10, data=[48, 91]),
midi.NoteOnEvent(tick=34, channel=10, data=[48, 122]),


Now I'd like to get the parameters of those Events but I don't know how to do that. I want to count all ticks, get all different channels and also read the data (so the note and the velocity). I looked into the Github-Repository but I did not find the answer to my question. link to repository: https://github.com/vishnubob/python-midi



Could it be that pyhton-midi is not really made for reading and manipulating midi-files?










share|improve this question




























    up vote
    0
    down vote

    favorite












    I use the python-midi library to read a midi file into a list.



    variable = midi.read_midifile(source)


    The entries look like those:



       midi.NoteOffEvent(tick=2, channel=10, data=[48, 98]),
    midi.NoteOnEvent(tick=46, channel=10, data=[48, 100]),
    midi.NoteOffEvent(tick=12, channel=10, data=[48, 100]),
    midi.NoteOnEvent(tick=36, channel=10, data=[48, 91]),
    midi.NoteOffEvent(tick=14, channel=10, data=[48, 91]),
    midi.NoteOnEvent(tick=34, channel=10, data=[48, 122]),


    Now I'd like to get the parameters of those Events but I don't know how to do that. I want to count all ticks, get all different channels and also read the data (so the note and the velocity). I looked into the Github-Repository but I did not find the answer to my question. link to repository: https://github.com/vishnubob/python-midi



    Could it be that pyhton-midi is not really made for reading and manipulating midi-files?










    share|improve this question


























      up vote
      0
      down vote

      favorite









      up vote
      0
      down vote

      favorite











      I use the python-midi library to read a midi file into a list.



      variable = midi.read_midifile(source)


      The entries look like those:



         midi.NoteOffEvent(tick=2, channel=10, data=[48, 98]),
      midi.NoteOnEvent(tick=46, channel=10, data=[48, 100]),
      midi.NoteOffEvent(tick=12, channel=10, data=[48, 100]),
      midi.NoteOnEvent(tick=36, channel=10, data=[48, 91]),
      midi.NoteOffEvent(tick=14, channel=10, data=[48, 91]),
      midi.NoteOnEvent(tick=34, channel=10, data=[48, 122]),


      Now I'd like to get the parameters of those Events but I don't know how to do that. I want to count all ticks, get all different channels and also read the data (so the note and the velocity). I looked into the Github-Repository but I did not find the answer to my question. link to repository: https://github.com/vishnubob/python-midi



      Could it be that pyhton-midi is not really made for reading and manipulating midi-files?










      share|improve this question















      I use the python-midi library to read a midi file into a list.



      variable = midi.read_midifile(source)


      The entries look like those:



         midi.NoteOffEvent(tick=2, channel=10, data=[48, 98]),
      midi.NoteOnEvent(tick=46, channel=10, data=[48, 100]),
      midi.NoteOffEvent(tick=12, channel=10, data=[48, 100]),
      midi.NoteOnEvent(tick=36, channel=10, data=[48, 91]),
      midi.NoteOffEvent(tick=14, channel=10, data=[48, 91]),
      midi.NoteOnEvent(tick=34, channel=10, data=[48, 122]),


      Now I'd like to get the parameters of those Events but I don't know how to do that. I want to count all ticks, get all different channels and also read the data (so the note and the velocity). I looked into the Github-Repository but I did not find the answer to my question. link to repository: https://github.com/vishnubob/python-midi



      Could it be that pyhton-midi is not really made for reading and manipulating midi-files?







      python python-2.7 midi






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Nov 10 at 12:58

























      asked Nov 10 at 12:36









      Stefan

      118110




      118110
























          1 Answer
          1






          active

          oldest

          votes

















          up vote
          1
          down vote



          accepted










          I don't know anything about the python-midi library but I'm guessing from the source code that read_midifile() method returns a Pattern object. The Pattern object contains a list of events.



          Each event will contain a tick, channel and data property.



          I'm guessing you can slice a Pattern object like a list, so you should be able to do this:



          pattern = midi.read_midifile(source)
          print pattern[0].tick


          This will select the first event in the Pattern and print its tick property.



          You could then count the ticks by doing something like:



          pattern = midi.read_midifile(source)
          tick_count = 0
          # a unique list
          channels = set()

          for event in pattern:
          tick_count += event.tick
          channels.add(event.channel)


          If you ever need to know what's in an object, you can always use the dir() function. E.g.



          print dir(event)


          Good luck with your learning. Keep aiming high!






          share|improve this answer























            Your Answer






            StackExchange.ifUsing("editor", function () {
            StackExchange.using("externalEditor", function () {
            StackExchange.using("snippets", function () {
            StackExchange.snippets.init();
            });
            });
            }, "code-snippets");

            StackExchange.ready(function() {
            var channelOptions = {
            tags: "".split(" "),
            id: "1"
            };
            initTagRenderer("".split(" "), "".split(" "), channelOptions);

            StackExchange.using("externalEditor", function() {
            // Have to fire editor after snippets, if snippets enabled
            if (StackExchange.settings.snippets.snippetsEnabled) {
            StackExchange.using("snippets", function() {
            createEditor();
            });
            }
            else {
            createEditor();
            }
            });

            function createEditor() {
            StackExchange.prepareEditor({
            heartbeatType: 'answer',
            convertImagesToLinks: true,
            noModals: true,
            showLowRepImageUploadWarning: true,
            reputationToPostImages: 10,
            bindNavPrevention: true,
            postfix: "",
            imageUploader: {
            brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
            contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
            allowUrls: true
            },
            onDemand: true,
            discardSelector: ".discard-answer"
            ,immediatelyShowMarkdownHelp:true
            });


            }
            });














             

            draft saved


            draft discarded


















            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53239018%2fget-variables-from-midi-events-with-the-pyhton-midi-library%23new-answer', 'question_page');
            }
            );

            Post as a guest
































            1 Answer
            1






            active

            oldest

            votes








            1 Answer
            1






            active

            oldest

            votes









            active

            oldest

            votes






            active

            oldest

            votes








            up vote
            1
            down vote



            accepted










            I don't know anything about the python-midi library but I'm guessing from the source code that read_midifile() method returns a Pattern object. The Pattern object contains a list of events.



            Each event will contain a tick, channel and data property.



            I'm guessing you can slice a Pattern object like a list, so you should be able to do this:



            pattern = midi.read_midifile(source)
            print pattern[0].tick


            This will select the first event in the Pattern and print its tick property.



            You could then count the ticks by doing something like:



            pattern = midi.read_midifile(source)
            tick_count = 0
            # a unique list
            channels = set()

            for event in pattern:
            tick_count += event.tick
            channels.add(event.channel)


            If you ever need to know what's in an object, you can always use the dir() function. E.g.



            print dir(event)


            Good luck with your learning. Keep aiming high!






            share|improve this answer



























              up vote
              1
              down vote



              accepted










              I don't know anything about the python-midi library but I'm guessing from the source code that read_midifile() method returns a Pattern object. The Pattern object contains a list of events.



              Each event will contain a tick, channel and data property.



              I'm guessing you can slice a Pattern object like a list, so you should be able to do this:



              pattern = midi.read_midifile(source)
              print pattern[0].tick


              This will select the first event in the Pattern and print its tick property.



              You could then count the ticks by doing something like:



              pattern = midi.read_midifile(source)
              tick_count = 0
              # a unique list
              channels = set()

              for event in pattern:
              tick_count += event.tick
              channels.add(event.channel)


              If you ever need to know what's in an object, you can always use the dir() function. E.g.



              print dir(event)


              Good luck with your learning. Keep aiming high!






              share|improve this answer

























                up vote
                1
                down vote



                accepted







                up vote
                1
                down vote



                accepted






                I don't know anything about the python-midi library but I'm guessing from the source code that read_midifile() method returns a Pattern object. The Pattern object contains a list of events.



                Each event will contain a tick, channel and data property.



                I'm guessing you can slice a Pattern object like a list, so you should be able to do this:



                pattern = midi.read_midifile(source)
                print pattern[0].tick


                This will select the first event in the Pattern and print its tick property.



                You could then count the ticks by doing something like:



                pattern = midi.read_midifile(source)
                tick_count = 0
                # a unique list
                channels = set()

                for event in pattern:
                tick_count += event.tick
                channels.add(event.channel)


                If you ever need to know what's in an object, you can always use the dir() function. E.g.



                print dir(event)


                Good luck with your learning. Keep aiming high!






                share|improve this answer














                I don't know anything about the python-midi library but I'm guessing from the source code that read_midifile() method returns a Pattern object. The Pattern object contains a list of events.



                Each event will contain a tick, channel and data property.



                I'm guessing you can slice a Pattern object like a list, so you should be able to do this:



                pattern = midi.read_midifile(source)
                print pattern[0].tick


                This will select the first event in the Pattern and print its tick property.



                You could then count the ticks by doing something like:



                pattern = midi.read_midifile(source)
                tick_count = 0
                # a unique list
                channels = set()

                for event in pattern:
                tick_count += event.tick
                channels.add(event.channel)


                If you ever need to know what's in an object, you can always use the dir() function. E.g.



                print dir(event)


                Good luck with your learning. Keep aiming high!







                share|improve this answer














                share|improve this answer



                share|improve this answer








                edited Nov 10 at 13:16

























                answered Nov 10 at 13:10









                Alastair McCormack

                14.6k33859




                14.6k33859






























                     

                    draft saved


                    draft discarded



















































                     


                    draft saved


                    draft discarded














                    StackExchange.ready(
                    function () {
                    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53239018%2fget-variables-from-midi-events-with-the-pyhton-midi-library%23new-answer', 'question_page');
                    }
                    );

                    Post as a guest




















































































                    Popular posts from this blog

                    Florida Star v. B. J. F.

                    Error while running script in elastic search , gateway timeout

                    Adding quotations to stringified JSON object values