[gsharp-devel] Can I import *.midi or *.mid or a sequence from CM in gsharp

Christophe Rhodes csr21 at cam.ac.uk
Thu Mar 23 09:22:27 UTC 2006


"Thanassis Zervopoulos" <azervopoulos at gmail.com> writes:

>   I've tried to save some notes and I saw that the format wasn't
> midi or mid and I have some music recorded with CM
> (portmidi-record),I'm not sure if I can pass a seq or even a
> midi,mid file directly to gsharp

Not without doing some work.  (And automatic conversion is unlikely
ever to be fully satisfactory, for reasons detailed in Robert's
reply).

However, writing (for want of a better term) import filters into
gsharp (and export, though we have export to MIDI already) is clearly
important for all sorts of reasons, even if the results of the filter
need to be touched afterwards.  As it happens, I was discussing just
two days ago about what would need to be done to write an
"interpreter" for OPND files, which are a sequence of (Onset,
PitchName, Duration) triples.  This is one step closer than a MIDI
importer, as the "spelling" of the notes is included in the OPND
format, whereas it isn't in MIDI: a C-sharp and a D-flat have the same
MIDI pitch representation, whereas on a score they are noticeably
different.

Just to get you started, though, here is a toy example: consider a
music notation encoding which can represent one voice of crotchets
(quarter notes) the white notes between a4 and g5: the opening of
Tallis' second lamentation might be represented in this format as the
string "aabcdeea".  (I hope that everyone realises that this format is
not a particularly good one :-).  Then code to
convert/import/interpret this representation within gsharp is:

(in-package :gsharp)

(define-gsharp-command (interpret-string :name t) ((s 'string))
  ;; no error checking
  (dotimes (i (length s))
    (let ((pitch (+ 23 (digit-char-p (char s i) 36))))
      (insert-note pitch (if (upper-case-p (char s i))
                             *current-cluster*
                             (insert-cluster))))))

and indeed this code includes some extra bonus easter egg features!

Generalizing this to OPND files is relatively straightforward;
generating OPND representations from MIDI files involves a certain
amount more research, but there are some algorithms which perform
quite well, so getting pitch names is possible.  I believe that
performing acceptable voicing from arbitrary MIDI files is quite hard.

Cheers,

Christophe



More information about the gsharp-devel mailing list