MIDI.lua

classic Classic list List threaded Threaded
9 messages Options
pj
Reply | Threaded
Open this post in threaded view
|

MIDI.lua

pj
Greetings,

Another module: http://www.pjb.com.au/comp/lua/MIDI.lua
doc homepage:   http://www.pjb.com.au/comp/lua/MIDI.html
test script:    http://www.pjb.com.au/comp/lua/test_mi.lua
version:        3.7

MIDI.lua - for Reading, writing and manipulating MIDI data
translates the MIDI data into Lua variables and back, e.g.

 local MIDI = require 'MIDI'
 local my_score = {
    96,  -- ticks per beat
    {    -- first track
       {'patch_change', 0, 1, 11}, -- vibraphone on channel 1
       {'set_tempo', 0, 750000},   -- microseconds per beat
       {'note', 5, 96, 1, 25, 100},
       {'note', 101, 96, 1, 29, 100},
    },  -- end of first track
 }
 local f = assert(io.open('f.mid','wb'))
 f:write(MIDI.score2midi(my_score))
 f:close()

and, aside from offering this low-level access, also offers a
number of different functions to perform common manipulations.

It's a translation into Lua of my Python module:
  http://www.pjb.com.au/midi/MIDI.html
  http://www.pjb.com.au/midi/free/MIDI.py
which is the basis of my midisox program, which already has a
Perl version, and may soon get a Lua version...

( Translating is a process which I find really instructive; plus
  I really like having compatible calling-interfaces to my most-
  -needed-stuff in different languages; also the resulting study
  of the code and the new test-scripts finds and fixes lots of
  little bugs that no-one seems to spot otherwise. )

May it be useful,  let me know of problems,
Peter Billam

http://www.pjb.com.au       [hidden email]      (03) 6278 9410
"Was der Meister nicht kann,   vermöcht es der Knabe, hätt er
 ihm immer gehorcht?"   Siegfried to Mime, from Act 1 Scene 2


Reply | Threaded
Open this post in threaded view
|

Re: MIDI.lua

云帆江
cool, i have tried smidi , but thats for pys60

On Tue, Sep 14, 2010 at 9:10 AM, <[hidden email]> wrote:
Greetings,

Another module: http://www.pjb.com.au/comp/lua/MIDI.lua
doc homepage:   http://www.pjb.com.au/comp/lua/MIDI.html
test script:    http://www.pjb.com.au/comp/lua/test_mi.lua
version:        3.7

MIDI.lua - for Reading, writing and manipulating MIDI data
translates the MIDI data into Lua variables and back, e.g.

 local MIDI = require 'MIDI'
 local my_score = {
   96,  -- ticks per beat
   {    -- first track
      {'patch_change', 0, 1, 11}, -- vibraphone on channel 1
      {'set_tempo', 0, 750000},   -- microseconds per beat
      {'note', 5, 96, 1, 25, 100},
      {'note', 101, 96, 1, 29, 100},
   },  -- end of first track
 }
 local f = assert(io.open('f.mid','wb'))
 f:write(MIDI.score2midi(my_score))
 f:close()

and, aside from offering this low-level access, also offers a
number of different functions to perform common manipulations.

It's a translation into Lua of my Python module:
 http://www.pjb.com.au/midi/MIDI.html
 http://www.pjb.com.au/midi/free/MIDI.py
which is the basis of my midisox program, which already has a
Perl version, and may soon get a Lua version...

( Translating is a process which I find really instructive; plus
 I really like having compatible calling-interfaces to my most-
 -needed-stuff in different languages; also the resulting study
 of the code and the new test-scripts finds and fixes lots of
 little bugs that no-one seems to spot otherwise. )

May it be useful,  let me know of problems,
Peter Billam

http://www.pjb.com.au       [hidden email]      (03) 6278 9410
"Was der Meister nicht kann,   vermöcht es der Knabe, hätt er
 ihm immer gehorcht?"   Siegfried to Mime, from Act 1 Scene 2





--
welcom to gtalk me
http://hi.baidu.com/jyf1987
Reply | Threaded
Open this post in threaded view
|

Re: MIDI.lua

"J.Jørgen von Bargen"
In reply to this post by pj
 <pj <at> pjb.com.au> writes:

> Another module: http://www.pjb.com.au/comp/lua/MIDI.lua
> doc homepage:   http://www.pjb.com.au/comp/lua/MIDI.html
> test script:    http://www.pjb.com.au/comp/lua/test_mi.lua

Very interesting. But I miss the 'DataDumper' module to run the test_mi script.

> May it be useful,  let me know of problems,
> Peter Billam

Will give you more feedback after taking a deep-inside look.

BTW: I've written my own Midi-Module (just started, by-far not so complete as
yours, but much more "lua-ish" :-)

Regards Jørgen



pj
Reply | Threaded
Open this post in threaded view
|

Re: MIDI.lua

pj
In reply to this post by pj
J.Jørgen von Bargen writes:
> But I miss the 'DataDumper' module to run the test_mi script.

Ah, sorry..  I'm not sure where I got it from, I'd have to
google, it starts:

--[[ DataDumper.lua
Copyright (c) 2007 Olivetti-Engineering SA

it's 227 lines long, maybe I should roll it into test_mi ...

Peter

http://www.pjb.com.au       [hidden email]      (03) 6278 9410
"Was der Meister nicht kann,   vermöcht es der Knabe, hätt er
 ihm immer gehorcht?"   Siegfried to Mime, from Act 1 Scene 2


Reply | Threaded
Open this post in threaded view
|

Re: MIDI.lua

Robert G. Jakabosky
On Tuesday 14, [hidden email] wrote:
> J.Jørgen von Bargen writes:
> > But I miss the 'DataDumper' module to run the test_mi script.
>
> Ah, sorry..  I'm not sure where I got it from, I'd have to
> google, it starts:
>
> --[[ DataDumper.lua
> Copyright (c) 2007 Olivetti-Engineering SA

most likely from here:
http://lua-users.org/wiki/DataDumper

--
Robert G. Jakabosky

Reply | Threaded
Open this post in threaded view
|

Re: MIDI.lua

Zark Yoc
In reply to this post by 云帆江
没想到Lua list里也有同胞啊。呵呵



2010/9/14 江云帆 <[hidden email]>
cool, i have tried smidi , but thats for pys60


On Tue, Sep 14, 2010 at 9:10 AM, <[hidden email]> wrote:
Greetings,

Another module: http://www.pjb.com.au/comp/lua/MIDI.lua
doc homepage:   http://www.pjb.com.au/comp/lua/MIDI.html
test script:    http://www.pjb.com.au/comp/lua/test_mi.lua
version:        3.7

MIDI.lua - for Reading, writing and manipulating MIDI data
translates the MIDI data into Lua variables and back, e.g.

 local MIDI = require 'MIDI'
 local my_score = {
   96,  -- ticks per beat
   {    -- first track
      {'patch_change', 0, 1, 11}, -- vibraphone on channel 1
      {'set_tempo', 0, 750000},   -- microseconds per beat
      {'note', 5, 96, 1, 25, 100},
      {'note', 101, 96, 1, 29, 100},
   },  -- end of first track
 }
 local f = assert(io.open('f.mid','wb'))
 f:write(MIDI.score2midi(my_score))
 f:close()

and, aside from offering this low-level access, also offers a
number of different functions to perform common manipulations.

It's a translation into Lua of my Python module:
 http://www.pjb.com.au/midi/MIDI.html
 http://www.pjb.com.au/midi/free/MIDI.py
which is the basis of my midisox program, which already has a
Perl version, and may soon get a Lua version...

( Translating is a process which I find really instructive; plus
 I really like having compatible calling-interfaces to my most-
 -needed-stuff in different languages; also the resulting study
 of the code and the new test-scripts finds and fixes lots of
 little bugs that no-one seems to spot otherwise. )

May it be useful,  let me know of problems,
Peter Billam

http://www.pjb.com.au       [hidden email]      (03) 6278 9410
"Was der Meister nicht kann,   vermöcht es der Knabe, hätt er
 ihm immer gehorcht?"   Siegfried to Mime, from Act 1 Scene 2





--
welcom to gtalk me
http://hi.baidu.com/jyf1987



--
Zark Yoc

Reply | Threaded
Open this post in threaded view
|

Re: MIDI.lua

Stuart P. Bentley
In reply to this post by pj
Cool! This would go really well with that Lua libao binding  
(http://github.com/thelinx/lao/)- if only I could figure out how to  
compile lao on Windows...

On Mon, 13 Sep 2010 21:10:43 -0400, <[hidden email]> wrote:

> Greetings,
>
> Another module: http://www.pjb.com.au/comp/lua/MIDI.lua
> doc homepage:   http://www.pjb.com.au/comp/lua/MIDI.html
> test script:    http://www.pjb.com.au/comp/lua/test_mi.lua
> version:        3.7
>
> MIDI.lua - for Reading, writing and manipulating MIDI data
> translates the MIDI data into Lua variables and back, e.g.
>
>  local MIDI = require 'MIDI'
>  local my_score = {
>     96,  -- ticks per beat
>     {    -- first track
>        {'patch_change', 0, 1, 11}, -- vibraphone on channel 1
>        {'set_tempo', 0, 750000},   -- microseconds per beat
>        {'note', 5, 96, 1, 25, 100},
>        {'note', 101, 96, 1, 29, 100},
>     },  -- end of first track
>  }
>  local f = assert(io.open('f.mid','wb'))
>  f:write(MIDI.score2midi(my_score))
>  f:close()
>
> and, aside from offering this low-level access, also offers a
> number of different functions to perform common manipulations.
>
> It's a translation into Lua of my Python module:
>   http://www.pjb.com.au/midi/MIDI.html
>   http://www.pjb.com.au/midi/free/MIDI.py
> which is the basis of my midisox program, which already has a
> Perl version, and may soon get a Lua version...
>
> ( Translating is a process which I find really instructive; plus
>   I really like having compatible calling-interfaces to my most-
>   -needed-stuff in different languages; also the resulting study
>   of the code and the new test-scripts finds and fixes lots of
>   little bugs that no-one seems to spot otherwise. )
>
> May it be useful,  let me know of problems,
> Peter Billam
>
> http://www.pjb.com.au       [hidden email]      (03) 6278 9410
> "Was der Meister nicht kann,   vermöcht es der Knabe, hätt er
>  ihm immer gehorcht?"   Siegfried to Mime, from Act 1 Scene 2
>
>


Reply | Threaded
Open this post in threaded view
|

Re: MIDI.lua

Patrick Rapin
I feel doubly concerned about this thread, although indirectly, so I cannot resist to write about my experience :)
First, I am the author of the small mentioned utility called "DataDumper", written during the development of LuaDura. Feel free to use it.
And second, because I also have written a script called "midi.lua"!
But mine does not perform exactly the same thing. It opens up a MIDI file, reads it into a Lua structure in memory, and... plays it on a Olivetti printers orchestra !
LuaDura, mentioned previously, is a Lua based platform to control Olivetti printers firmware and hardware through USB.
Our printers have at least two DC motors that can produce sound when driven with a PWM in a audible frequency range. With three Olivetti printers connected, for example, the Lua script can play up to 6 notes simultaneously. This is can very impressive, when the MIDI file is well suited to this type of orchestra ;)
pj
Reply | Threaded
Open this post in threaded view
|

Re: MIDI.lua

pj
In reply to this post by pj
Patrick Rapin wrote:
> First, I am the author of the small mentioned utility called
> "DataDumper", written during the development of LuaDura.

Pleased to meet you :-)  Apart from being so useful during
debugging, the test-script uses it as a deepequals() function:
   if DataDumper(t1) == DataDumper(t2) ...
(There may also be other ways to that...)

> And second, because I also have written a script called "midi.lua"!
> But mine does not perform exactly the same thing. It opens up a MIDI
> file, reads it into a Lua structure in memory, and... plays it on a
> Olivetti printers orchestra !  LuaDura, mentioned previously, is a
> Lua based platform to control Olivetti printers firmware and hardware
> through USB.  Our printers have at least two DC motors that can produce
> sound when driven with a PWM in a audible frequency range. With three
> Olivetti printers connected, for example, the Lua script can play up
> to 6 notes simultaneously. This is can very impressive, when the MIDI
> file is well suited to this type of orchestra ;)

Wonderful!  I heard that on a radio program once :-)  Amazing.
Is it on youtube  ?

Regards,  Peter Billam

http://www.pjb.com.au       [hidden email]      (03) 6278 9410
"Was der Meister nicht kann,   vermöcht es der Knabe, hätt er
 ihm immer gehorcht?"   Siegfried to Mime, from Act 1 Scene 2