id: qtgui_freq_sink_x
label: QT GUI Frequency Sink
flags: [ python, cpp ]

parameters:
-   id: type
    label: Type
    dtype: enum
    default: complex
    options: [complex, float, msg_complex, msg_float]
    option_labels: [Complex, Float, Complex Message, Float Message]
    option_attributes:
        fcn: [freq_sink_c, freq_sink_f, freq_sink_c, freq_sink_f]
        t: [complex, float, message, message]
    hide: part
-   id: name
    label: Name
    dtype: string
    default: '""'
    hide: ${ ('none' if len(name) > 0 else 'part') }
-   id: fftsize
    label: FFT Size
    dtype: int
    default: '1024'
    options: ['32','64','128','256','512','1024','2048','4096','8192','16384','32768']
    hide: ${ ('all' if (type == 'msg_complex' or type == 'msg_float') else 'none') }
-   id: freqhalf
    label: Spectrum Width
    dtype: enum
    default: 'True'
    options: ['True', 'False']
    option_labels: [Full, Half]
    hide: ${ ('part' if type == "float" or type == "msg_float" else 'all') }
-   id: wintype
    label: Window Type
    dtype: enum
    default: window.WIN_BLACKMAN_hARRIS
    options: [window.WIN_BLACKMAN_hARRIS, window.WIN_HAMMING, window.WIN_HANN, window.WIN_BLACKMAN,
        window.WIN_RECTANGULAR, window.WIN_KAISER, window.WIN_FLATTOP]
    option_labels: [Blackman-harris, Hamming, Hann, Blackman, Rectangular, Kaiser,
        Flat-top]
    option_attributes:
        cpp_opts: ["fft::window::WIN_BLACKMAN_hARRIS", "fft::window::WIN_HAMMING", "fft::window::WIN_HANN", "fft::window::WIN_BLACKMAN",
        "fft::window::WIN_RECTANGULAR", "fft::window::WIN_KAISER", "fft::window::WIN_FLATTOP"]
    hide: part
-   id: norm_window
    label: Normalize Window Power
    dtype: enum
    default: 'False'
    options: ['True', 'False']
    option_labels: [Yes, No]
    hide: ${ ('none' if norm_window == 'True' else 'part') }
-   id: fc
    label: Center Frequency (Hz)
    dtype: real
    default: '0'
-   id: bw
    label: Bandwidth (Hz)
    dtype: real
    default: samp_rate
-   id: grid
    label: Grid
    dtype: enum
    default: 'False'
    options: ['True', 'False']
    option_labels: ['Yes', 'No']
    hide: part
-   id: autoscale
    label: Autoscale
    dtype: enum
    default: 'False'
    options: ['True', 'False']
    option_labels: ['Yes', 'No']
    hide: part
-   id: average
    label: Average
    dtype: enum
    default: 'False'
    options: ['1.0', '0.2', '0.1', '0.05']
    option_labels: [None, Low, Medium, High]
    hide: part
-   id: ymin
    label: Y min
    dtype: real
    default: '-140'
    hide: part
-   id: ymax
    label: Y max
    dtype: real
    default: '10'
    hide: part
-   id: label
    label: Y label
    dtype: string
    default: Relative Gain
    hide: part
-   id: units
    label: Y units
    dtype: string
    default: dB
    hide: part
-   id: nconnections
    label: Number of Inputs
    dtype: int
    default: '1'
    hide: ${ ('all' if (type == 'msg_complex' or type == 'msg_float') else 'part') }
-   id: update_time
    label: Update Period
    dtype: real
    default: '0.10'
    hide: part
-   id: showports
    label: Show Msg Ports
    dtype: bool
    default: 'False'
    options: ['True', 'False']
    option_labels: ['Yes', 'No']
    hide: part
-   id: gui_hint
    label: GUI Hint
    dtype: gui_hint
    hide: part
-   id: tr_mode
    label: Trigger Mode
    category: Trigger
    dtype: enum
    default: qtgui.TRIG_MODE_FREE
    options: [qtgui.TRIG_MODE_FREE, qtgui.TRIG_MODE_AUTO, qtgui.TRIG_MODE_NORM, qtgui.TRIG_MODE_TAG]
    option_labels: [Free, Auto, Normal, Tag]
    option_attributes:
        cpp_opts: ["qtgui::TRIG_MODE_FREE", "qtgui::TRIG_MODE_AUTO", "qtgui::TRIG_MODE_NORM", "qtgui::TRIG_MODE_TAG"]
    hide: part
-   id: tr_level
    label: Trigger Level
    category: Trigger
    dtype: float
    default: '0.0'
    hide: part
-   id: tr_chan
    label: Trigger Channel
    category: Trigger
    dtype: int
    default: '0'
    hide: part
-   id: tr_tag
    label: Trigger Tag Key
    category: Trigger
    dtype: string
    default: '""'
    hide: part
-   id: ctrlpanel
    label: Control Panel
    category: Config
    dtype: enum
    default: 'False'
    options: ['True', 'False']
    option_labels: ['Yes', 'No']
    hide: part
-   id: legend
    label: Legend
    category: Config
    dtype: enum
    default: 'True'
    options: ['True', 'False']
    option_labels: ['Yes', 'No']
    hide: part
-   id: axislabels
    label: Axis Labels
    category: Config
    dtype: enum
    default: 'True'
    options: ['True', 'False']
    option_labels: ['Yes', 'No']
    hide: part
-   id: label1
    label: Line 1 Label
    category: Config
    dtype: string
    hide: ${ ('part' if int(nconnections) >= 1 else 'all') }
-   id: width1
    label: Line 1 Width
    category: Config
    dtype: int
    default: '1'
    hide: ${ ('part' if int(nconnections) >= 1 else 'all') }
-   id: color1
    label: Line 1 Color
    category: Config
    dtype: enum
    options: ['"blue"', '"red"', '"green"', '"black"', '"cyan"', '"magenta"', '"yellow"',
        '"dark red"', '"dark green"', '"dark blue"']
    option_labels: [Blue, Red, Green, Black, Cyan, Magenta, Yellow, Dark Red, Dark
            Green, Dark Blue]
    hide: ${ ('part' if int(nconnections) >= 1 else 'all') }
-   id: alpha1
    label: Line 1 Alpha
    category: Config
    dtype: float
    default: '1.0'
    hide: ${ ('part' if int(nconnections) >= 1 else 'all') }
-   id: label2
    label: Line 2 Label
    base_key: label1
    default: "''"
    hide: ${ ('part' if int(nconnections) >= 2 else 'all') }
-   id: width2
    label: Line 2 Width
    base_key: width1
    default: '1'
    hide: ${ ('part' if int(nconnections) >= 2 else 'all') }
-   id: color2
    label: Line 2 Color
    base_key: color1
    default: '"red"'
    hide: ${ ('part' if int(nconnections) >= 2 else 'all') }
-   id: alpha2
    label: Line 2 Alpha
    base_key: alpha1
    default: '1.0'
    hide: ${ ('part' if int(nconnections) >= 2 else 'all') }
-   id: label3
    label: Line 3 Label
    base_key: label1
    default: "''"
    hide: ${ ('part' if int(nconnections) >= 3 else 'all') }
-   id: width3
    label: Line 3 Width
    base_key: width1
    default: '1'
    hide: ${ ('part' if int(nconnections) >= 3 else 'all') }
-   id: color3
    label: Line 3 Color
    base_key: color1
    default: '"green"'
    hide: ${ ('part' if int(nconnections) >= 3 else 'all') }
-   id: alpha3
    label: Line 3 Alpha
    base_key: alpha1
    default: '1.0'
    hide: ${ ('part' if int(nconnections) >= 3 else 'all') }
-   id: label4
    label: Line 4 Label
    base_key: label1
    default: "''"
    hide: ${ ('part' if int(nconnections) >= 4 else 'all') }
-   id: width4
    label: Line 4 Width
    base_key: width1
    default: '1'
    hide: ${ ('part' if int(nconnections) >= 4 else 'all') }
-   id: color4
    label: Line 4 Color
    base_key: color1
    default: '"black"'
    hide: ${ ('part' if int(nconnections) >= 4 else 'all') }
-   id: alpha4
    label: Line 4 Alpha
    base_key: alpha1
    default: '1.0'
    hide: ${ ('part' if int(nconnections) >= 4 else 'all') }
-   id: label5
    label: Line 5 Label
    base_key: label1
    default: "''"
    hide: ${ ('part' if int(nconnections) >= 5 else 'all') }
-   id: width5
    label: Line 5 Width
    base_key: width1
    default: '1'
    hide: ${ ('part' if int(nconnections) >= 5 else 'all') }
-   id: color5
    label: Line 5 Color
    base_key: color1
    default: '"cyan"'
    hide: ${ ('part' if int(nconnections) >= 5 else 'all') }
-   id: alpha5
    label: Line 5 Alpha
    base_key: alpha1
    default: '1.0'
    hide: ${ ('part' if int(nconnections) >= 5 else 'all') }
-   id: label6
    label: Line 6 Label
    base_key: label1
    default: "''"
    hide: ${ ('part' if int(nconnections) >= 6 else 'all') }
-   id: width6
    label: Line 6 Width
    base_key: width1
    default: '1'
    hide: ${ ('part' if int(nconnections) >= 6 else 'all') }
-   id: color6
    label: Line 6 Color
    base_key: color1
    default: '"magenta"'
    hide: ${ ('part' if int(nconnections) >= 6 else 'all') }
-   id: alpha6
    label: Line 6 Alpha
    base_key: alpha1
    default: '1.0'
    hide: ${ ('part' if int(nconnections) >= 6 else 'all') }
-   id: label7
    label: Line 7 Label
    base_key: label1
    default: "''"
    hide: ${ ('part' if int(nconnections) >= 7 else 'all') }
-   id: width7
    label: Line 7 Width
    base_key: width1
    default: '1'
    hide: ${ ('part' if int(nconnections) >= 7 else 'all') }
-   id: color7
    label: Line 7 Color
    base_key: color1
    default: '"yellow"'
    hide: ${ ('part' if int(nconnections) >= 7 else 'all') }
-   id: alpha7
    label: Line 7 Alpha
    base_key: alpha1
    default: '1.0'
    hide: ${ ('part' if int(nconnections) >= 7 else 'all') }
-   id: label8
    label: Line 8 Label
    base_key: label1
    default: "''"
    hide: ${ ('part' if int(nconnections) >= 8 else 'all') }
-   id: width8
    label: Line 8 Width
    base_key: width1
    default: '1'
    hide: ${ ('part' if int(nconnections) >= 8 else 'all') }
-   id: color8
    label: Line 8 Color
    base_key: color1
    default: '"dark red"'
    hide: ${ ('part' if int(nconnections) >= 8 else 'all') }
-   id: alpha8
    label: Line 8 Alpha
    base_key: alpha1
    default: '1.0'
    hide: ${ ('part' if int(nconnections) >= 8 else 'all') }
-   id: label9
    label: Line 9 Label
    base_key: label1
    default: "''"
    hide: ${ ('part' if int(nconnections) >= 9 else 'all') }
-   id: width9
    label: Line 9 Width
    base_key: width1
    default: '1'
    hide: ${ ('part' if int(nconnections) >= 9 else 'all') }
-   id: color9
    label: Line 9 Color
    base_key: color1
    default: '"dark green"'
    hide: ${ ('part' if int(nconnections) >= 9 else 'all') }
-   id: alpha9
    label: Line 9 Alpha
    base_key: alpha1
    default: '1.0'
    hide: ${ ('part' if int(nconnections) >= 9 else 'all') }
-   id: label10
    label: Line 10 Label
    base_key: label1
    default: "''"
    hide: ${ ('part' if int(nconnections) >= 10 else 'all') }
-   id: width10
    label: Line 10 Width
    base_key: width1
    default: '1'
    hide: ${ ('part' if int(nconnections) >= 10 else 'all') }
-   id: color10
    label: Line 10 Color
    base_key: color1
    default: '"dark blue"'
    hide: ${ ('part' if int(nconnections) >= 10 else 'all') }
-   id: alpha10
    label: Line 10 Alpha
    base_key: alpha1
    default: '1.0'
    hide: ${ ('part' if int(nconnections) >= 10 else 'all') }

inputs:
-   domain: stream
    dtype: ${ type.t }
    multiplicity: ${ (0 if (type == 'msg_complex' or type == 'msg_float') else nconnections) }
    optional: ${ (True if type.startswith('msg') else False) }
-   domain: message
    id: freq
    optional: true
    hide: ${ not showports }
-   domain: message
    id: bw
    optional: true
    hide: ${ not showports }

outputs:
-   domain: message
    id: freq
    optional: true
    hide: ${ not showports }

asserts:
- ${fftsize >= 32 and fftsize <= 32768#'The FFT Size is out of range 32 - 32768'}
- ${not (fftsize & (fftsize -1))#The FFT Size should be a power of 2}

templates:
    imports: |-
        import sip

    callbacks:
    - set_frequency_range(${fc}, ${bw})
    - set_update_time(${update_time})
    - set_y_axis(${ymin}, ${ymax})
    - self.${id}.set_trigger_mode(${tr_mode}, ${tr_level}, ${tr_chan}, ${tr_tag})
    make:  |-
        <%
            win = 'self._%s_win'%id
        %>\
        qtgui.${type.fcn}(
            ${fftsize}, #size
            ${wintype}, #wintype
            ${fc}, #fc
            ${bw}, #bw
            ${name}, #name
            ${ 0 if (type == 'msg_complex' or type == 'msg_float') else nconnections },
            None # parent
        )
        self.${id}.set_update_time(${update_time})
        self.${id}.set_y_axis(${ymin}, ${ymax})
        self.${id}.set_y_label(${label}, ${units})
        self.${id}.set_trigger_mode(${tr_mode}, ${tr_level}, ${tr_chan}, ${tr_tag})
        self.${id}.enable_autoscale(${autoscale})
        self.${id}.enable_grid(${grid})
        self.${id}.set_fft_average(${average})
        self.${id}.enable_axis_labels(${axislabels})
        self.${id}.enable_control_panel(${ctrlpanel})
        self.${id}.set_fft_window_normalized(${norm_window})

        % if legend == "False":
        self.${id}.disable_legend()
        % endif

        % if type == "float" or type == "msg_float":
        self.${id}.set_plot_pos_half(not ${freqhalf})
        % endif

        labels = [${label1}, ${label2}, ${label3}, ${label4}, ${label5},
            ${label6}, ${label7}, ${label8}, ${label9}, ${label10}]
        widths = [${width1}, ${width2}, ${width3}, ${width4}, ${width5},
            ${width6}, ${width7}, ${width8}, ${width9}, ${width10}]
        colors = [${color1}, ${color2}, ${color3}, ${color4}, ${color5},
            ${color6}, ${color7}, ${color8}, ${color9}, ${color10}]
        alphas = [${alpha1}, ${alpha2}, ${alpha3}, ${alpha4}, ${alpha5},
            ${alpha6}, ${alpha7}, ${alpha8}, ${alpha9}, ${alpha10}]

        for i in range(${1 if (type == 'msg_complex' or type == 'msg_float') else nconnections}):
            if len(labels[i]) == 0:
                self.${id}.set_line_label(i, "Data {0}".format(i))
            else:
                self.${id}.set_line_label(i, labels[i])
            self.${id}.set_line_width(i, widths[i])
            self.${id}.set_line_color(i, colors[i])
            self.${id}.set_line_alpha(i, alphas[i])

        ${win} = sip.wrapinstance(self.${id}.qwidget(), Qt.QWidget)
        ${ gui_hint() % win}

cpp_templates:
    includes: ['#include <gnuradio/qtgui/${type.fcn}.h>']
    declarations: 'qtgui::${type.fcn}::sptr ${id};'
    callbacks:
    - set_frequency_range(${fc}, ${bw})
    - set_update_time(${update_time})
    - set_y_axis(${ymin}, ${ymax})
    - this->${id}.set_trigger_mode(${tr_mode.cpp_opts}, ${tr_level}, ${tr_chan}, ${tr_tag})
    link: ['gnuradio::gnuradio-qtgui']
    make:  |-
        <%
            win = '_%s_win'%id
        %>\
        ${id} = qtgui::${type.fcn}::make(
            ${fftsize}, // size
            ${wintype.cpp_opts}, // wintype
            ${fc}, // fc
            ${bw}, // bw
            ${name}, // name
            ${ 0 if (type == 'msg_complex' or type == 'msg_float') else nconnections } // nconnections
        );

        QWidget* _${id}_win;

        ${id}->set_update_time(${update_time});
        ${id}->set_y_axis(${ymin}, ${ymax});
        ${id}->set_y_label("${label.strip("'")}", "${units.strip("'")}");
        ${id}->set_trigger_mode(${tr_mode.replace('qtgui.','gr::qtgui::')}, ${tr_level}, ${tr_chan}, ${tr_tag});
        ${id}->enable_autoscale(${autoscale});
        ${id}->enable_grid(${grid});
        ${id}->set_fft_average(${average});
        ${id}->enable_axis_labels(${axislabels});
        ${id}->enable_control_panel(${ctrlpanel});

        % if legend == "False":
        ${id}->disable_legend();
        % endif
        % if type.endswith('float'):
        ${id}->set_plot_pos_half(not ${freqhalf});
        % endif

        {
            std::string labels[10] = {"${label1.strip("'")}", "${label2.strip("'")}", "${label3.strip("'")}", "${label4.strip("'")}", "${label5.strip("'")}",
                "${label6.strip("'")}", "${label7.strip("'")}", "${label8.strip("'")}", "${label9.strip("'")}", "${label10.strip("'")}"};
            int widths[10] = {${width1}, ${width2}, ${width3}, ${width4}, ${width5},
                ${width6}, ${width7}, ${width8}, ${width9}, ${width10}};
            std::string colors[10] = {${color1}, ${color2}, ${color3}, ${color4}, ${color5},
                ${color6}, ${color7}, ${color8}, ${color9}, ${color10}};
            double alphas[10] = {${alpha1}, ${alpha2}, ${alpha3}, ${alpha4}, ${alpha5},
                ${alpha6}, ${alpha7}, ${alpha8}, ${alpha9}, ${alpha10}};
            for (int i = 0; i < ${ 1 if (type == 'msg_complex' or type == 'msg_float') else nconnections }; i++) {
                if (sizeof(labels[i]) == 0) {
                    ${id}->set_line_label(i, "Data " + std::to_string(i));
                } else {
                    ${id}->set_line_label(i, labels[i]);
                }
                ${id}->set_line_width(i, widths[i]);
                ${id}->set_line_color(i, colors[i]);
                ${id}->set_line_alpha(i, alphas[i]);
            }
        }
        _${id}_win = this->${id}->qwidget();

        ${gui_hint() % win}

documentation: |-
    The GUI hint can be used to position the widget within the application. The hint is of the form [tab_id@tab_index]: [row, col, row_span, col_span]. Both the tab specification and the grid position are optional.

file_format: 1
