// This file was generated by gir (https://github.com/gtk-rs/gir)
// from
// from gir-files (https://github.com/gtk-rs/gir-files)
// DO NOT EDIT

use crate::Addr;
use crate::EventDataConnect;
use crate::EventDataCtl;
use crate::EventDataNote;
use crate::EventDataQueue;
use crate::EventDataResult;
use crate::EventLengthMode;
use crate::EventPriorityMode;
use crate::EventTimeMode;
use crate::EventTimestampMode;
use crate::EventType;
use crate::Tstamp;
use glib::object::IsA;
use glib::translate::*;
use std::fmt;
use std::mem;
use std::ptr;

glib::wrapper! {
    #[doc(alias = "ALSASeqEventCntr")]
    pub struct EventCntr(Object<ffi::ALSASeqEventCntr, ffi::ALSASeqEventCntrClass>);

    match fn {
        type_ => || ffi::alsaseq_event_cntr_get_type(),
    }
}

impl EventCntr {
    pub const NONE: Option<&'static EventCntr> = None;

    #[doc(alias = "alsaseq_event_cntr_new")]
    pub fn new(count: u32) -> Result<EventCntr, glib::Error> {
        unsafe {
            let mut error = ptr::null_mut();
            let ret = ffi::alsaseq_event_cntr_new(count, &mut error);
            if error.is_null() {
                Ok(from_glib_full(ret))
            } else {
                Err(from_glib_full(error))
            }
        }
    }
}

pub trait EventCntrExt: 'static {
    #[doc(alias = "alsaseq_event_cntr_calculate_pool_consumption")]
    fn calculate_pool_consumption(&self, count: usize) -> Result<usize, glib::Error>;

    #[doc(alias = "alsaseq_event_cntr_count_events")]
    fn count_events(&self) -> usize;

    #[doc(alias = "alsaseq_event_cntr_get_event_type")]
    #[doc(alias = "get_event_type")]
    fn event_type(&self, index: usize) -> Result<EventType, glib::Error>;

    #[doc(alias = "alsaseq_event_cntr_get_length_mode")]
    #[doc(alias = "get_length_mode")]
    fn length_mode(&self, index: usize) -> Result<EventLengthMode, glib::Error>;

    #[doc(alias = "alsaseq_event_cntr_get_priority_mode")]
    #[doc(alias = "get_priority_mode")]
    fn priority_mode(&self, index: usize) -> Result<EventPriorityMode, glib::Error>;

    #[doc(alias = "alsaseq_event_cntr_get_queue_id")]
    #[doc(alias = "get_queue_id")]
    fn queue_id(&self, index: usize) -> Result<u8, glib::Error>;

    #[doc(alias = "alsaseq_event_cntr_get_tag")]
    #[doc(alias = "get_tag")]
    fn tag(&self, index: usize) -> Result<i8, glib::Error>;

    #[doc(alias = "alsaseq_event_cntr_get_time_mode")]
    #[doc(alias = "get_time_mode")]
    fn time_mode(&self, index: usize) -> Result<EventTimeMode, glib::Error>;

    #[doc(alias = "alsaseq_event_cntr_get_tstamp_mode")]
    #[doc(alias = "get_tstamp_mode")]
    fn tstamp_mode(&self, index: usize) -> Result<EventTimestampMode, glib::Error>;

    #[doc(alias = "alsaseq_event_cntr_set_addr_data")]
    fn set_addr_data(&self, index: usize, data: &Addr) -> Result<(), glib::Error>;

    #[doc(alias = "alsaseq_event_cntr_set_blob_data")]
    fn set_blob_data(&self, index: usize, data: &[u8]) -> Result<(), glib::Error>;

    #[doc(alias = "alsaseq_event_cntr_set_connect_data")]
    fn set_connect_data(&self, index: usize, data: &EventDataConnect) -> Result<(), glib::Error>;

    #[doc(alias = "alsaseq_event_cntr_set_ctl_data")]
    fn set_ctl_data(&self, index: usize, data: &EventDataCtl) -> Result<(), glib::Error>;

    #[doc(alias = "alsaseq_event_cntr_set_dst")]
    fn set_dst(&self, index: usize, dst: &Addr) -> Result<(), glib::Error>;

    #[doc(alias = "alsaseq_event_cntr_set_event_type")]
    fn set_event_type(&self, index: usize, ev_type: EventType) -> Result<(), glib::Error>;

    #[doc(alias = "alsaseq_event_cntr_set_note_data")]
    fn set_note_data(&self, index: usize, data: &EventDataNote) -> Result<(), glib::Error>;

    #[doc(alias = "alsaseq_event_cntr_set_priority_mode")]
    fn set_priority_mode(&self, index: usize, mode: EventPriorityMode) -> Result<(), glib::Error>;

    #[doc(alias = "alsaseq_event_cntr_set_queue_data")]
    fn set_queue_data(&self, index: usize, data: &EventDataQueue) -> Result<(), glib::Error>;

    #[doc(alias = "alsaseq_event_cntr_set_queue_id")]
    fn set_queue_id(&self, index: usize, queue_id: u8) -> Result<(), glib::Error>;

    #[doc(alias = "alsaseq_event_cntr_set_result_data")]
    fn set_result_data(&self, index: usize, data: &EventDataResult) -> Result<(), glib::Error>;

    #[doc(alias = "alsaseq_event_cntr_set_src")]
    fn set_src(&self, index: usize, src: &Addr) -> Result<(), glib::Error>;

    #[doc(alias = "alsaseq_event_cntr_set_tag")]
    fn set_tag(&self, index: usize, tag: i8) -> Result<(), glib::Error>;

    #[doc(alias = "alsaseq_event_cntr_set_time_mode")]
    fn set_time_mode(&self, index: usize, mode: EventTimeMode) -> Result<(), glib::Error>;

    #[doc(alias = "alsaseq_event_cntr_set_tstamp")]
    fn set_tstamp(&self, index: usize, tstamp: &Tstamp) -> Result<(), glib::Error>;

    #[doc(alias = "alsaseq_event_cntr_set_tstamp_data")]
    fn set_tstamp_data(&self, index: usize, data: &Tstamp) -> Result<(), glib::Error>;

    #[doc(alias = "alsaseq_event_cntr_set_tstamp_mode")]
    fn set_tstamp_mode(&self, index: usize, mode: EventTimestampMode) -> Result<(), glib::Error>;
}

impl<O: IsA<EventCntr>> EventCntrExt for O {
    fn calculate_pool_consumption(&self, count: usize) -> Result<usize, glib::Error> {
        unsafe {
            let mut cells = mem::MaybeUninit::uninit();
            let mut error = ptr::null_mut();
            let _ = ffi::alsaseq_event_cntr_calculate_pool_consumption(
                self.as_ref().to_glib_none().0,
                count,
                cells.as_mut_ptr(),
                &mut error,
            );
            let cells = cells.assume_init();
            if error.is_null() {
                Ok(cells)
            } else {
                Err(from_glib_full(error))
            }
        }
    }

    fn count_events(&self) -> usize {
        unsafe {
            let mut count = mem::MaybeUninit::uninit();
            ffi::alsaseq_event_cntr_count_events(
                self.as_ref().to_glib_none().0,
                count.as_mut_ptr(),
            );
            let count = count.assume_init();
            count
        }
    }

    fn event_type(&self, index: usize) -> Result<EventType, glib::Error> {
        unsafe {
            let mut ev_type = mem::MaybeUninit::uninit();
            let mut error = ptr::null_mut();
            let _ = ffi::alsaseq_event_cntr_get_event_type(
                self.as_ref().to_glib_none().0,
                index,
                ev_type.as_mut_ptr(),
                &mut error,
            );
            let ev_type = ev_type.assume_init();
            if error.is_null() {
                Ok(from_glib(ev_type))
            } else {
                Err(from_glib_full(error))
            }
        }
    }

    fn length_mode(&self, index: usize) -> Result<EventLengthMode, glib::Error> {
        unsafe {
            let mut mode = mem::MaybeUninit::uninit();
            let mut error = ptr::null_mut();
            let _ = ffi::alsaseq_event_cntr_get_length_mode(
                self.as_ref().to_glib_none().0,
                index,
                mode.as_mut_ptr(),
                &mut error,
            );
            let mode = mode.assume_init();
            if error.is_null() {
                Ok(from_glib(mode))
            } else {
                Err(from_glib_full(error))
            }
        }
    }

    fn priority_mode(&self, index: usize) -> Result<EventPriorityMode, glib::Error> {
        unsafe {
            let mut mode = mem::MaybeUninit::uninit();
            let mut error = ptr::null_mut();
            let _ = ffi::alsaseq_event_cntr_get_priority_mode(
                self.as_ref().to_glib_none().0,
                index,
                mode.as_mut_ptr(),
                &mut error,
            );
            let mode = mode.assume_init();
            if error.is_null() {
                Ok(from_glib(mode))
            } else {
                Err(from_glib_full(error))
            }
        }
    }

    fn queue_id(&self, index: usize) -> Result<u8, glib::Error> {
        unsafe {
            let mut queue_id = mem::MaybeUninit::uninit();
            let mut error = ptr::null_mut();
            let _ = ffi::alsaseq_event_cntr_get_queue_id(
                self.as_ref().to_glib_none().0,
                index,
                queue_id.as_mut_ptr(),
                &mut error,
            );
            let queue_id = queue_id.assume_init();
            if error.is_null() {
                Ok(queue_id)
            } else {
                Err(from_glib_full(error))
            }
        }
    }

    fn tag(&self, index: usize) -> Result<i8, glib::Error> {
        unsafe {
            let mut tag = mem::MaybeUninit::uninit();
            let mut error = ptr::null_mut();
            let _ = ffi::alsaseq_event_cntr_get_tag(
                self.as_ref().to_glib_none().0,
                index,
                tag.as_mut_ptr(),
                &mut error,
            );
            let tag = tag.assume_init();
            if error.is_null() {
                Ok(tag)
            } else {
                Err(from_glib_full(error))
            }
        }
    }

    fn time_mode(&self, index: usize) -> Result<EventTimeMode, glib::Error> {
        unsafe {
            let mut mode = mem::MaybeUninit::uninit();
            let mut error = ptr::null_mut();
            let _ = ffi::alsaseq_event_cntr_get_time_mode(
                self.as_ref().to_glib_none().0,
                index,
                mode.as_mut_ptr(),
                &mut error,
            );
            let mode = mode.assume_init();
            if error.is_null() {
                Ok(from_glib(mode))
            } else {
                Err(from_glib_full(error))
            }
        }
    }

    fn tstamp_mode(&self, index: usize) -> Result<EventTimestampMode, glib::Error> {
        unsafe {
            let mut mode = mem::MaybeUninit::uninit();
            let mut error = ptr::null_mut();
            let _ = ffi::alsaseq_event_cntr_get_tstamp_mode(
                self.as_ref().to_glib_none().0,
                index,
                mode.as_mut_ptr(),
                &mut error,
            );
            let mode = mode.assume_init();
            if error.is_null() {
                Ok(from_glib(mode))
            } else {
                Err(from_glib_full(error))
            }
        }
    }

    fn set_addr_data(&self, index: usize, data: &Addr) -> Result<(), glib::Error> {
        unsafe {
            let mut error = ptr::null_mut();
            let _ = ffi::alsaseq_event_cntr_set_addr_data(
                self.as_ref().to_glib_none().0,
                index,
                data.to_glib_none().0,
                &mut error,
            );
            if error.is_null() {
                Ok(())
            } else {
                Err(from_glib_full(error))
            }
        }
    }

    fn set_blob_data(&self, index: usize, data: &[u8]) -> Result<(), glib::Error> {
        let size = data.len() as usize;
        unsafe {
            let mut error = ptr::null_mut();
            let _ = ffi::alsaseq_event_cntr_set_blob_data(
                self.as_ref().to_glib_none().0,
                index,
                data.to_glib_none().0,
                size,
                &mut error,
            );
            if error.is_null() {
                Ok(())
            } else {
                Err(from_glib_full(error))
            }
        }
    }

    fn set_connect_data(&self, index: usize, data: &EventDataConnect) -> Result<(), glib::Error> {
        unsafe {
            let mut error = ptr::null_mut();
            let _ = ffi::alsaseq_event_cntr_set_connect_data(
                self.as_ref().to_glib_none().0,
                index,
                data.to_glib_none().0,
                &mut error,
            );
            if error.is_null() {
                Ok(())
            } else {
                Err(from_glib_full(error))
            }
        }
    }

    fn set_ctl_data(&self, index: usize, data: &EventDataCtl) -> Result<(), glib::Error> {
        unsafe {
            let mut error = ptr::null_mut();
            let _ = ffi::alsaseq_event_cntr_set_ctl_data(
                self.as_ref().to_glib_none().0,
                index,
                data.to_glib_none().0,
                &mut error,
            );
            if error.is_null() {
                Ok(())
            } else {
                Err(from_glib_full(error))
            }
        }
    }

    fn set_dst(&self, index: usize, dst: &Addr) -> Result<(), glib::Error> {
        unsafe {
            let mut error = ptr::null_mut();
            let _ = ffi::alsaseq_event_cntr_set_dst(
                self.as_ref().to_glib_none().0,
                index,
                dst.to_glib_none().0,
                &mut error,
            );
            if error.is_null() {
                Ok(())
            } else {
                Err(from_glib_full(error))
            }
        }
    }

    fn set_event_type(&self, index: usize, ev_type: EventType) -> Result<(), glib::Error> {
        unsafe {
            let mut error = ptr::null_mut();
            let _ = ffi::alsaseq_event_cntr_set_event_type(
                self.as_ref().to_glib_none().0,
                index,
                ev_type.into_glib(),
                &mut error,
            );
            if error.is_null() {
                Ok(())
            } else {
                Err(from_glib_full(error))
            }
        }
    }

    fn set_note_data(&self, index: usize, data: &EventDataNote) -> Result<(), glib::Error> {
        unsafe {
            let mut error = ptr::null_mut();
            let _ = ffi::alsaseq_event_cntr_set_note_data(
                self.as_ref().to_glib_none().0,
                index,
                data.to_glib_none().0,
                &mut error,
            );
            if error.is_null() {
                Ok(())
            } else {
                Err(from_glib_full(error))
            }
        }
    }

    fn set_priority_mode(&self, index: usize, mode: EventPriorityMode) -> Result<(), glib::Error> {
        unsafe {
            let mut error = ptr::null_mut();
            let _ = ffi::alsaseq_event_cntr_set_priority_mode(
                self.as_ref().to_glib_none().0,
                index,
                mode.into_glib(),
                &mut error,
            );
            if error.is_null() {
                Ok(())
            } else {
                Err(from_glib_full(error))
            }
        }
    }

    fn set_queue_data(&self, index: usize, data: &EventDataQueue) -> Result<(), glib::Error> {
        unsafe {
            let mut error = ptr::null_mut();
            let _ = ffi::alsaseq_event_cntr_set_queue_data(
                self.as_ref().to_glib_none().0,
                index,
                data.to_glib_none().0,
                &mut error,
            );
            if error.is_null() {
                Ok(())
            } else {
                Err(from_glib_full(error))
            }
        }
    }

    fn set_queue_id(&self, index: usize, queue_id: u8) -> Result<(), glib::Error> {
        unsafe {
            let mut error = ptr::null_mut();
            let _ = ffi::alsaseq_event_cntr_set_queue_id(
                self.as_ref().to_glib_none().0,
                index,
                queue_id,
                &mut error,
            );
            if error.is_null() {
                Ok(())
            } else {
                Err(from_glib_full(error))
            }
        }
    }

    fn set_result_data(&self, index: usize, data: &EventDataResult) -> Result<(), glib::Error> {
        unsafe {
            let mut error = ptr::null_mut();
            let _ = ffi::alsaseq_event_cntr_set_result_data(
                self.as_ref().to_glib_none().0,
                index,
                data.to_glib_none().0,
                &mut error,
            );
            if error.is_null() {
                Ok(())
            } else {
                Err(from_glib_full(error))
            }
        }
    }

    fn set_src(&self, index: usize, src: &Addr) -> Result<(), glib::Error> {
        unsafe {
            let mut error = ptr::null_mut();
            let _ = ffi::alsaseq_event_cntr_set_src(
                self.as_ref().to_glib_none().0,
                index,
                src.to_glib_none().0,
                &mut error,
            );
            if error.is_null() {
                Ok(())
            } else {
                Err(from_glib_full(error))
            }
        }
    }

    fn set_tag(&self, index: usize, tag: i8) -> Result<(), glib::Error> {
        unsafe {
            let mut error = ptr::null_mut();
            let _ = ffi::alsaseq_event_cntr_set_tag(
                self.as_ref().to_glib_none().0,
                index,
                tag,
                &mut error,
            );
            if error.is_null() {
                Ok(())
            } else {
                Err(from_glib_full(error))
            }
        }
    }

    fn set_time_mode(&self, index: usize, mode: EventTimeMode) -> Result<(), glib::Error> {
        unsafe {
            let mut error = ptr::null_mut();
            let _ = ffi::alsaseq_event_cntr_set_time_mode(
                self.as_ref().to_glib_none().0,
                index,
                mode.into_glib(),
                &mut error,
            );
            if error.is_null() {
                Ok(())
            } else {
                Err(from_glib_full(error))
            }
        }
    }

    fn set_tstamp(&self, index: usize, tstamp: &Tstamp) -> Result<(), glib::Error> {
        unsafe {
            let mut error = ptr::null_mut();
            let _ = ffi::alsaseq_event_cntr_set_tstamp(
                self.as_ref().to_glib_none().0,
                index,
                tstamp.to_glib_none().0,
                &mut error,
            );
            if error.is_null() {
                Ok(())
            } else {
                Err(from_glib_full(error))
            }
        }
    }

    fn set_tstamp_data(&self, index: usize, data: &Tstamp) -> Result<(), glib::Error> {
        unsafe {
            let mut error = ptr::null_mut();
            let _ = ffi::alsaseq_event_cntr_set_tstamp_data(
                self.as_ref().to_glib_none().0,
                index,
                data.to_glib_none().0,
                &mut error,
            );
            if error.is_null() {
                Ok(())
            } else {
                Err(from_glib_full(error))
            }
        }
    }

    fn set_tstamp_mode(&self, index: usize, mode: EventTimestampMode) -> Result<(), glib::Error> {
        unsafe {
            let mut error = ptr::null_mut();
            let _ = ffi::alsaseq_event_cntr_set_tstamp_mode(
                self.as_ref().to_glib_none().0,
                index,
                mode.into_glib(),
                &mut error,
            );
            if error.is_null() {
                Ok(())
            } else {
                Err(from_glib_full(error))
            }
        }
    }
}

impl fmt::Display for EventCntr {
    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
        f.write_str("EventCntr")
    }
}
