LCOV - code coverage report
Current view: top level - src - ppg_tap_dance.c (source / functions) Hit Total Coverage
Test: coverage.info.cleaned Lines: 22 22 100.0 %
Date: 2018-01-08 Functions: 1 1 100.0 %

          Line data    Source code
       1             : /* Copyright 2017 noseglasses <shinynoseglasses@gmail.com>
       2             :  *
       3             :  * This program is free software: you can redistribute it and/or modify
       4             :  * it under the terms of the GNU Lesser General Public License as published by
       5             :  * the Free Software Foundation, either version 3 of the License, or
       6             :  * (at your option) any later version.
       7             :  *
       8             :  * This program is distributed in the hope that it will be useful,
       9             :  * but WITHOUT ANY WARRANTY; without even the implied warranty of
      10             :  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
      11             :  * GNU Lesser General Public License for more details.
      12             :  *
      13             :  * You should have received a copy of the GNU Lesser General Public License
      14             :  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
      15             :  */
      16             : 
      17             : #include "ppg_tap_dance.h"
      18             : #include "ppg_debug.h"
      19             : #include "ppg_note.h"
      20             : #include "ppg_global.h"
      21             : #include "detail/ppg_token_detail.h"
      22             : #include "detail/ppg_pattern_detail.h"
      23             : 
      24             : #include <stddef.h>
      25             : 
      26           3 : PPG_Token ppg_tap_dance(   
      27             :                      PPG_Layer layer,
      28             :                      PPG_Input_Id input,
      29             :                      PPG_Count n_tap_definitions,
      30             :                      PPG_Tap_Definition tap_definitions[])
      31             : {
      32             : //    PPG_LOG("Adding tap dance\n");
      33             :    
      34           3 :    ppg_global_init();
      35             :    
      36           3 :    PPG_Count n_taps = 0;
      37           9 :    for (PPG_Count i = 0; i < n_tap_definitions; i++) { 
      38             :       
      39           6 :       if(tap_definitions[i].tap_count > n_taps) {
      40           6 :          n_taps = tap_definitions[i].tap_count;
      41             :       }
      42             :    }
      43             :    
      44           3 :    if(n_taps == 0) { return NULL; }
      45             :       
      46           3 :    PPG_Token__ *tokens[n_taps];
      47             :    
      48          18 :    for (PPG_Count i = 0; i < n_taps; i++) {
      49             :       
      50          15 :       PPG_Token__ *new_note = (PPG_Token__*)ppg_note_create_standard(input);
      51          15 :          new_note->misc.action_flags = PPG_Action_Fallback;
      52             :       
      53          15 :       tokens[i] = new_note;
      54             :    }
      55             :    
      56           9 :    for (PPG_Count i = 0; i < n_tap_definitions; i++) {
      57             :       
      58           6 :       ppg_token_store_action(
      59           6 :                tokens[tap_definitions[i].tap_count - 1], 
      60           6 :                tap_definitions[i].action);
      61             :       
      62           6 :       PPG_Token__ *token 
      63           6 :          = (PPG_Token__ *)tokens[tap_definitions[i].tap_count - 1];
      64             :       
      65             :       // Make sure that the notes that are associated
      66             :       // with the exact number of taps do not
      67             :       // allow fallback. Else all actions of all
      68             :       // notes back to the search tree root
      69             :       // would be triggered.
      70             :       //
      71           6 :       token->misc.action_flags &= ~PPG_Action_Fallback;
      72             :    }
      73             :          
      74           3 :    PPG_Token__ *leafToken 
      75           3 :       = ppg_pattern_from_list(NULL, layer, n_taps, tokens);
      76             :    
      77           3 :    return leafToken;
      78             : }

Generated by: LCOV version 1.10