Fix a memory leak.
[ardour.git] / libs / midi++2 / port.cc
index 65cba24eb0157a6e188e726a5e1ca764849bed23..539d5c49cbe840f8106036c1929285b7e93a8c49 100644 (file)
@@ -54,6 +54,7 @@ Port::Port (string const & name, Flags flags, jack_client_t* jack_client)
        , input_fifo (1024)
        , _flags (flags)
 {
+       assert (jack_client);
        init (name, flags);
 }
 
@@ -66,6 +67,8 @@ Port::Port (const XMLNode& node, jack_client_t* jack_client)
        , output_fifo (512)
        , input_fifo (1024)
 {
+       assert (jack_client);
+       
        Descriptor desc (node);
 
        init (desc.tag, desc.flags);
@@ -116,7 +119,7 @@ Port::~Port ()
 }
 
 void
-Port::parse (nframes_t timestamp)
+Port::parse (framecnt_t timestamp)
 {
        byte buf[512];
 
@@ -168,8 +171,10 @@ Port::clock (timestamp_t timestamp)
 }
 
 void
-Port::cycle_start (nframes_t nframes)
+Port::cycle_start (pframes_t nframes)
 {
+       assert (_jack_port);
+       
        _currently_in_cycle = true;
        _nframes_this_cycle = nframes;
 
@@ -185,12 +190,12 @@ Port::cycle_start (nframes_t nframes)
        
        if (receives_input()) {
                void* jack_buffer = jack_port_get_buffer(_jack_port, nframes);
-               const nframes_t event_count = jack_midi_get_event_count(jack_buffer);
+               const pframes_t event_count = jack_midi_get_event_count(jack_buffer);
 
                jack_midi_event_t ev;
                timestamp_t cycle_start_frame = jack_last_frame_time (_jack_client);
 
-               for (nframes_t i = 0; i < event_count; ++i) {
+               for (pframes_t i = 0; i < event_count; ++i) {
                        jack_midi_event_get (&ev, jack_buffer, i);
                        input_fifo.write (cycle_start_frame + ev.time, (Evoral::EventType) 0, ev.size, ev.buffer);
                }       
@@ -397,10 +402,6 @@ int
 Port::create_port ()
 {
        _jack_port = jack_port_register(_jack_client, _tagname.c_str(), JACK_DEFAULT_MIDI_TYPE, _flags, 0);
-       if (_jack_port) {
-               jack_midi_clear_buffer (jack_port_get_buffer (_jack_port, jack_get_buffer_size (_jack_client)));
-       }
-
        return _jack_port == 0 ? -1 : 0;
 }