David:
> Malte Meyn <[email protected]> writes:
> 
> > Am 19.03.2018 um 14:47 schrieb [email protected]:
> >> You could try the attached rudimentary patch and recompile your
> >> lilypond source, see if that solves your problem, and report back.
> > Would it be possible to make a patch that reads this from a context
> > property so that the user could input something like
> >
> >     \set Score.midiTickResolution = 960

(The word resolution is not suitable since the resolution of the
midi tick is 1, it is a 15 bit int.)

Yes, if someone points to directions to go from \set to variable.

The second question is in what namespace or class to have the variable.
One possibility is to have it globally, another is to have it in the
Midi_header class.

> I think it belongs in the \midi block since you cannot change it in
> mid-file.  Well, you probably can, but LilyPond is even less prepared to
> do that.

The tick value can only be set once in the midi file, in the
last 16bits of the header chunk (the first so called "chunk"
of the file). See e.g. lily/midi-chunk.cc:Midi_header::Midi_header()

My current awful patch looks like in the attachment.

BTW, it is called "division" in the midi docs, and the word tick is
about the duration of one delta-time, or to cite the std:

 If bit 15 of <division> is zero, the bits 14 thru 0 represent the number
 of delta time "ticks" which make up a quarter-note. For instance, if
 division is 96, then a time interval of an eighth-note between two
 events in the file would be 48.

Perhaps we should call the value Midi_division or something similar.

Regards,
/Karl Hammar

-----------------------------------------------------------------------
Aspö Data
Lilla Aspö 148
S-742 94 Östhammar
Sweden
+46 173 140 57

diff --git a/lily/audio-item.cc b/lily/audio-item.cc
index a8a78199c7..57c1fa025c 100644
--- a/lily/audio-item.cc
+++ b/lily/audio-item.cc
@@ -129,7 +129,7 @@ moment_to_real (Moment m)
 int
 moment_to_ticks (Moment m)
 {
-  return int (moment_to_real (m) * 384 * 4);
+  return int (moment_to_real (m) * Midi_ticks * 4);
 }
 
 void Audio_span_dynamic::set_end_moment (Moment mom)
diff --git a/lily/include/midi-item.hh b/lily/include/midi-item.hh
index 57bb2d4da2..22de679cda 100644
--- a/lily/include/midi-item.hh
+++ b/lily/include/midi-item.hh
@@ -23,6 +23,8 @@
 #include "audio-item.hh"
 #include "std-vector.hh"
 
+int16_t Midi_ticks;
+
 string int2midi_varint_string (int i);
 
 /**
diff --git a/lily/midi-item.cc b/lily/midi-item.cc
index ba29ba0ba5..4af3f16d6c 100644
--- a/lily/midi-item.cc
+++ b/lily/midi-item.cc
@@ -34,6 +34,8 @@
 #define PITCH_WHEEL_CENTER 0x2000
 #define PITCH_WHEEL_SEMITONE 0X1000
 
+int16_t Midi_ticks = 960; /* negative value is SMPTE time format */
+
 Midi_item *
 Midi_item::get_midi (Audio_item *a)
 {
diff --git a/lily/midi-walker.cc b/lily/midi-walker.cc
index d9765c6814..4411206c2d 100644
--- a/lily/midi-walker.cc
+++ b/lily/midi-walker.cc
@@ -86,7 +86,7 @@ Midi_walker::do_start_note (Midi_note *note)
   assert (note->audio_ == ptr);
   int now_ticks = ptr->audio_column_->ticks ();
   int stop_ticks = int (moment_to_real (note->audio_->length_mom_) *
-                        Real (384 * 4)) + now_ticks;
+                        Real (Midi_ticks * 4)) + now_ticks;
   for (vsize i = 0; i < stop_note_queue.size (); i++)
     {
       /* if this pitch already in queue, and is not already ignored */
diff --git a/lily/performance.cc b/lily/performance.cc
index 9f840efd25..bd6a91d9cb 100644
--- a/lily/performance.cc
+++ b/lily/performance.cc
@@ -72,7 +72,7 @@ Performance::output (Midi_stream &midi_stream,
 {
   int tracks_ = audio_staffs_.size ();
 
-  midi_stream.write (Midi_header (1, tracks_, 384));
+  midi_stream.write (Midi_header (1, tracks_, Midi_ticks));
   debug_output (_ ("Track...") + " ", false);
 
   //Find the first Audio_item in the performance, so all staves start
_______________________________________________
lilypond-user mailing list
[email protected]
https://lists.gnu.org/mailman/listinfo/lilypond-user

Reply via email to